Commit 39812351 authored by CHINTHAREDDY SAI CHARITH REDDY's avatar CHINTHAREDDY SAI CHARITH REDDY

Test Performance

parents f59e050e cb3dfd3e
*.pyc
\ No newline at end of file
*.pyc
logfile
\ No newline at end of file
......@@ -40,6 +40,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'background_task',
# 'datetimepicker',
]
......@@ -115,13 +116,13 @@ AUTH_PASSWORD_VALIDATORS = [
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
TIME_ZONE = 'Asia/Kolkata'
USE_I18N = True
USE_L10N = True
USE_TZ = True
USE_TZ = False
# Static files (CSS, JavaScript, Images)
......
......@@ -4,6 +4,8 @@ from django.contrib.auth.models import User
from .models import *
from django.forms.widgets import Select, Widget,DateTimeInput,TimeInput
import datetime
from .models import QuestionImage
from django.forms import Textarea
# from datetimepicker.widgets import DateTimePicker
# class QuestionForm(forms.ModelForm):
......@@ -17,7 +19,7 @@ import datetime
# model = Options
# fields = ('option_value',)
VISIBILITY_CHOICES= ('1980', '1981', '1982')
#VISIBILITY_CHOICES= ('1980', '1981', '1982')
# class TestForm(forms.ModelForm):
# # start_time = forms.DateTimeField(widget=DateTimePicker(), initial=datetime.datetime.now())
......@@ -28,12 +30,25 @@ VISIBILITY_CHOICES= ('1980', '1981', '1982')
# model = Test
# exclude = ['test_ID', 'ownership']
class ImageFileUploadForm(forms.ModelForm):
q_id = forms.IntegerField(label='')
class Meta:
model = QuestionImage
fields = ['image' , 'imageDesc' ]
class TestForm(forms.ModelForm):
# start_time = forms.DateTimeField(input_formats=['%Y-%m-%dT%H:%M'])
# expected_time_for_completion = forms.DurationField(input_formats=['%HH:%M'])
class Meta:
model = Test
widgets = {
'expected_time_for_completion': forms.TimeInput(attrs={'type':'time'}),
'start_time': forms.DateInput(attrs={'type':'datetime-local'}),
# 'expected_time_for_completion': forms.TimeInput(attrs={'type':'time'}),
# 'start_time': forms.DateInput(attrs={'type':'datetime-local'}),
}
exclude = ['test_ID', 'ownership']
\ No newline at end of file
exclude = ['test_ID', 'ownership']
# def clean_start_time(self):
# dt = self.cleaned_data['start_time']
# print dt
# return dt['start_time'][0].replace('T', ' ') #remove the 'T' in HTML returned string
\ No newline at end of file
......@@ -4,6 +4,7 @@ from __future__ import unicode_literals
from django.db import models
from django.core.validators import MinLengthValidator
# Create your models here.
class arfa_user(models.Model):
......@@ -85,18 +86,17 @@ class Question(models.Model):
difficulty_set = models.CharField(max_length=20)
difficulty_observed = models.CharField(max_length=20)
question_text = models.CharField(max_length=1000)
image_link = models.CharField(max_length=200)
num_appeared = models.IntegerField(default=0)
num_correct = models.IntegerField(default=0)
visibility = models.CharField(max_length=20)
ownership = models.CharField(max_length=20)
class QuestionImage(models.Model):
image = models.FileField(upload_to='QuestionImages/' )
question = models.ForeignKey('Question' , on_delete=models.CASCADE)
image_id=models.AutoField(primary_key=True)
image = models.FileField(upload_to='ARFA_app/static/ARFA_app/QuestionImages/' )
imageDesc = models.CharField(max_length=100)
orderNum = models.IntegerField(default=1)
q_ID=models.ForeignKey('Question',null=True)
class Takes(models.Model):
student = models.ForeignKey('Student',models.SET_NULL,blank=True,null=True)
......
......@@ -18,7 +18,7 @@
height: 2px;
background: #e0e0e0;
position: absolute;
width: 80%;
width: 60%;
margin: 0 auto;
left: 0;
right: 0;
......@@ -44,6 +44,7 @@ span.round-tab {
z-index: 2;
position: absolute;
left: 0;
padding-top: 15px;
text-align: center;
font-size: 25px;
}
......@@ -65,7 +66,7 @@ span.round-tab:hover {
}
.wizard .nav-tabs > li {
width: 25%;
width: 33%;
}
.wizard li:after {
......
from background_task import background
from django.contrib.auth.models import User
from . import models
from django.db.models import F
#https://django-background-tasks.readthedocs.io/en/latest/#creating-and-registering-tasks
@background(schedule=60)
def testRanks(test_ID):
#get all Takes objects with this test_ID
print "testRanks called ! \n\n\n\n\n\n"
takesObjects = models.Takes.objects.filter(test_ID=test_ID).order_by(F('total_marks').desc())
num = len(takesObjects)
i=0
oldMarks = -10000
for t in takesObjects:
if t.total_marks != oldMarks:
i = i+1
oldMarks = t.total_marks
t.rank = i
print t.student_id
print t.rank
try:
print "saving"
t.save()
except:
print "some error"
# try:
# takesObjects.update()
# except:
# print "some error"
@background(schedule=60)
def testTask():
print "test task"
\ No newline at end of file
......@@ -12,6 +12,8 @@
<script type="text/javascript">
$(document).ready(function () {
$('#images').hide();
$('#id_q_id').hide() ;
//Initialize tooltips
$('.nav-tabs > li a[title]').tooltip();
......@@ -51,6 +53,8 @@ function prevTab(elem) {
<script type="text/javascript">
var question_data = {} ;
var options_details = {};
var id = -1 ;
var hasimage=0;
function addOption()
{
var n = document.getElementById("optno");
......@@ -65,11 +69,8 @@ function prevTab(elem) {
var label = document.createElement("label");
label.innerHTML = "Option "+x+":";
que.appendChild(label);
// que.className = "row" ;
var r = document.createElement("div") ;
r.className = "row" ;
// r.innerHTML = "<tr><input class = \"form-control\" size=\"30\" type=\"text\"><input class = \"form-control\" size=\"30\" type=\"text\"></tr>" ;
var input = document.createElement("input");
var check = document.createElement("input");
var check_ans = document.createElement("label");
......@@ -91,12 +92,6 @@ function prevTab(elem) {
r.appendChild(check) ;
r.appendChild(check_ans) ;
que.appendChild(r);
// var text = que.value ;
// text = text + "<input className='form-control' type='text' size='20' placeholder='Enter an option'>" ;
// document.getElementById('options').innerHTML = text ;
container.appendChild(que);
}
function deleteLastOption()
......@@ -110,7 +105,7 @@ function prevTab(elem) {
}
function step1()
{
{
var subject = document.getElementById('subject') ;
var qtext = document.getElementById('qtext').value ;
question_data['subject_ID'] = subject.value ;
......@@ -121,7 +116,7 @@ function prevTab(elem) {
}
function step2()
{
{
var O = document.getElementById("options") ;
var children = O.children;
for (var i = 0; i < children.length; i++) {
......@@ -135,53 +130,27 @@ function prevTab(elem) {
}
console.log(options_details) ;
document.getElementById('l3').click() ;
}
function step3()
{
$('#images').hide();
document.getElementById('l4').click() ;
}
function post()
{
// var xhttp = new XMLHttpRequest();
Data = { 'question_data': question_data , 'options_details' : options_details } ;
console.log(Data) ;
// D = {
// client_response : Data,
// csrfmiddlewaretoken: '{{ csrf_token }}'
// } ;
// console.log(D) ;
// var csrftoken = Cookies.get('csrftoken');
// xhttp.onreadystatechange = function() {
// if (this.readyState == 4 && this.status == 200) {
// alert(this.responseText);
// }
// };
// xhttp.open("POST", "add_question", true);
// xhttp.send();
// $.post({
// url: "add_question",
// data: Data,
// "success": function(result) {
// console.log(result);
// }
// }) ;
// console.log( document.getElementById("upload").value ) ;
// document.getElementById("imageForm").submit();
// console.log("still") ;
$.ajax({
url : "add_question",
type : "POST",
type : "POST",
data : {
client_response : JSON.stringify(Data),
csrfmiddlewaretoken: '{{ csrf_token }}'
},
// data : Data ,
// headers: {
// csrfmiddlewaretoken: '{{ csrf_token }}'
// },
success : function(p) {
q = JSON.parse(p);
console.log(q) ;
......@@ -190,7 +159,9 @@ function prevTab(elem) {
alert('Reason'+' : '+q.reason)
}
else{
alert("Successfully added to database") ;
alert("Successfully added question to database") ;
console.log("Return from post" + q['q_ID']) ;
id = q['q_ID'] ;
}
},
error : function(xhr,errmsg,err) {
......@@ -199,9 +170,50 @@ function prevTab(elem) {
});
}
function intend_to_add_img(){
$('#images').show();
hasimage=1;
}
function uploadImage()
{
var data = new FormData($('form').get(0));
console.log("Need to add to question " + id) ;
document.getElementById('id_q_id').value = id ;
$('#imageForm').submit(function(e){
e.preventDefault();
$form = $(this)
var formData = new FormData(this);
i = 0 ;
console.log("adding here...") ;
$.ajax({
url: "addimage",
type: 'POST',
data: formData ,
success: function (response) {
$('.error').remove();
console.log(response)
if(response.error){
$.each(response.errors, function(name, error){
error = '<small class="text-muted error">' + error + '</small>'
$form.find('[name=' + name + ']').after(error);
})
}
else{
alert(response.message)
i = 1 ;
window.location = "" ;
console.log("Added image also") ;
}
},
cache: false,
contentType: false,
processData: false
});
});
document.getElementById('imageForm').submit() ;
console.log("Image ADDED.. hopefully") ;
}
......@@ -248,13 +260,6 @@ Create Question
</a>
</li>
<li role="presentation" class="disabled">
<a href="#complete" data-toggle="tab" aria-controls="complete" role="tab" title="Complete" id = "l4">
<span class="round-tab">
<i class="glyphicon glyphicon-ok"></i>
</span>
</a>
</li>
</ul>
</div>
......@@ -277,7 +282,7 @@ Create Question
</div>
<ul class="list-inline pull-right">
<li><a href="#step2"><button type="button" class="btn btn-primary next-step" onclick="step1()">Save and continue</button></a></li>
</ul>
</ul>
<div class="clearfix"></div>
<div class="form-group col-lg-12">
<label>Question Text</label>
......@@ -302,34 +307,26 @@ Create Question
<h3>Step 3 - Add some pictures</h3>
<p> Drop images in the order you want to display</p>
<ul class="list-inline pull-right">
<li><button type="button" class="btn btn-default prev-step" onclick="document.getElementById('l2').click() ;">Previous</button></li>
<li><button type="button" class="btn btn-default prev-step" onclick="document.getElementById('l2').click() ; ">Previous</button></li>
<li><button type="button" class="btn btn-default next-step" onclick="document.getElementById('l4').click() ;">Skip</button></li>
<li><button align="left" type="button" class="btn btn-primary" id="addsubjectiveque" onclick="intend_to_add_img() ; post()" >Add an image</button></li>
<li><button type="button" class="btn btn-primary btn-info-full next-step" onclick="step3()">Save and continue</button></li>
</ul>
<!-- <form method="post" action="addimage" enctype="multipart/form-data" id="imageForm">
{% csrf_token %}
<label for="upload">
<span class="glyphicon glyphicon-folder-open" aria-hidden="true"></span>
<input type="file" id="upload" style="display:none">
</label><br>
<button onclick="post()" class="btn btn-primary btn-info-full" >Post the Question</button>
</form> -->
</ul>
</div>
<div class="tab-pane" role="tabpanel" id="complete">
<h3>Complete</h3>
<p>You have successfully completed all steps. Here's the preview</p>
<ul class="list-inline pull-right">
<li><button type="button" class="btn btn-default prev-step">Previous</button></li>
<li><button type="button" class="btn btn-primary btn-info-full next-step" onclick="post()">Post </button></li>
</ul>
</div>
<div class="clearfix"></div>
</div>
</form>
<div id = "images" >
<form method="POST" enctype="multipart/form-data" id="imageForm" novalidate="">
{% csrf_token %}
{{ form.as_p }}
<button onclick="uploadImage()" class="btn btn-primary btn-info-full" >Post the Question</button>
</form>
</div>
</div>
</section>
</div>
......
......@@ -19,7 +19,9 @@ Total Time :<b > {{total_time.hours}} {{total_time.minutes}} </b>
// Set the date we're counting down to
var countDownDate = new Date( {{ end_time }} );
countDownDate.setMonth(countDownDate.getMonth() - 1) ;
countDownDate.setMonth(countDownDate.getMonth() - 1) ;
countDownDate.setMonth(countDownDate.getMonth() - 1) ;
countDownDate.setMonth(countDownDate.getMonth() - 1) ;
console.log(countDownDate) ;
// Update the count down every 1 second
var x = setInterval(function() {
......@@ -52,7 +54,6 @@ var x = setInterval(function() {
<form class="exam-form" method="POST" action="/arfa/result">
<p style="margin-right: 5%"> <b> Questions </b></p>
{% csrf_token %}
<!-- {{ data }} -->
<input name="testID" value="{{testID}}" type="hidden" >
{% for question, options in questions.items %}
<div class="row" style="margin-top: 10px; margin-bottom: 10px">
......@@ -62,7 +63,6 @@ var x = setInterval(function() {
{% endfor %}
</div>
{% endfor %}
<button type="submit" class="btn btn-login" style="float: right;">Submit</button>
</form>
</font>
......
......@@ -28,7 +28,7 @@ chart.draw(data, {width: 500, height: 300, title: "Scores Distribution"});
{%endblock%}
{%block body%}
<h1 style="text-align:center"> You CAN VIEW student test performance prof {{username}}</h1>
<h1 style="text-align:center"> Test Performance</h1>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css">
<div class="container">
<div class="panel-default">
......@@ -102,29 +102,34 @@ chart.draw(data, {width: 500, height: 300, title: "Scores Distribution"});
<!-- <li> -->
<div class="row toggle">
<div class="col-xs-10">
<p> Question: {{q.question_text}} </p>
<p> Difficulty set: {{q.difficulty_set}}</p>
<p> Difficulty observed: {{q.difficulty_observed}}</p>
<p> Question: {{q.question_text}} </p>
</div>
</div>
<!-- <div class="container"> -->
<!-- <div class="fluid-row"> -->
<!-- <ul>
{%for option in question.option_details%}
{%if option.is_answer %}
<li>
<p style="color: green"> {{option.option_text}} </p>
</li>
{%else%}
<li>
{{option.option_text}}
</li>
{%endif%}
{%endfor%}
</ul> -->
<div>
<div>
<hr></hr>
<!-- <div class="container"> -->
<!-- <div class="fluid-row"> -->
<ul>
{%for option in q.option_details%}
{%if option.is_answer %}
<li>
<p style="color: green"> {{option.option_text}} </p>
</li>
{%else%}
<li>
{{option.option_text}}
</li>
{%endif%}
{%endfor%}
</ul>
<!-- </div> -->
<!-- </div> -->
<!-- </div> -->
</div>
</div>
</li>
{%endfor%}
......@@ -135,8 +140,3 @@ chart.draw(data, {width: 500, height: 300, title: "Scores Distribution"});
</div>
{%endblock%}
<!--
{%for p in student_performance%}
{{p}}
{%endfor%}
-->
\ No newline at end of file
......@@ -24,7 +24,7 @@ My Tests
<form method="POST" action="loadStudentTest">
{% csrf_token %}
<input name="testID" value="{{t.test_ID}}" type="hidden">
<button >Load Test</button>
<button type="submit" class="btn btn-login float-right" style="margin-top: 10px ;margin-right: 40px">Load Test</button>
</form>
</div>
{% endfor %}
......@@ -52,6 +52,11 @@ My Tests
<input name="testID" value="{{t.test_ID}}" type="hidden">
<button type="submit" class="btn btn-login float-right" style="margin-top: 10px ;margin-right: 40px">Load Test</button>
</form>
<form method="POST" action="viewTestPerformance">
{% csrf_token %}
<input name="test_ID" value="{{t.test_ID}}" type="hidden">
<button type="submit" class="btn btn-login float-right" style="margin-top: 10px ;margin-right: 40px">View Results</button>
</form>
</div>
</div>
{% endfor %}
......
......@@ -21,7 +21,7 @@ View personal Question
<p> <h4> {{test.test_name}} </h4> </p>
<p> Start Time : {{test.start_time}} </p>
<p> Duration : {{test.duration}} </p>
<p> {{test.max_marks}} </p>
<p> Maximum marks : {{test.max_marks}} </p>
</div>
<form method="POST" action="viewTestPerformance">
......
......@@ -4,7 +4,7 @@
<head>
<!-- Latest compiled and minified CSS -->
{% load static %}
<link rel="icon" href="{% static 'ARFA_app/favicon.ico' %}">
<link rel="stylesheet" href="{% static 'ARFA_app/lib/bootstrap-3.3.7-dist/css/bootstrap.min.css' %}" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> -->
<script src="{% static 'ARFA_app/lib/jquery/jquery-3.3.1.min.js' %}"></script>
......
......@@ -20,8 +20,7 @@ from django.db import IntegrityError
from django.db.models import F
from pprint import pprint
import datetime
import matplotlib.pyplot as plt
import numpy as np
def evaluate(responses, otherData):
"""responses contains a list of dicts of the form {q_ID: [option1, option2 ..]}
......@@ -117,7 +116,7 @@ def get_all_questions(request):
# args = {'username':'mathura'}
cursor = connection.cursor()
cursor.execute(''' SELECT s.subject,q."q_ID" as q_ID,q.question_text,q.topic,q.subtopic,q.source,
q.difficulty_set,q.image_link,q.visibility,q.ownership,o."option_Value" as option_details,
q.difficulty_set,q.visibility,q.ownership,o."option_Value" as option_details,
o."is_Answer"
FROM "ARFA_app_question" as q,
"ARFA_app_options" as o,"ARFA_app_subject" as s
......@@ -165,80 +164,45 @@ def result_analysis(request,test_ID):
hist = cursor.fetchall()
y = int(list(hist[-1])[0])
print y
hist = [ [str(str(int(x[0]))+"-"+str(int(x[0])+10)),int(x[1])] for x in hist]
print hist
# hist = []
# label = []
# x=0
# for val in rows:
# hist.append(val[1])
# label.append(str(int(val[0]))+"-"+str(int(val[0])+10))
# x=int(val[0])
y = y+10
for i in range(15):
hist.append([str(str(y)+"-"+str(y+10)),0])
y=y+10
# cleanup()
# imgpath = get_histogram(hist,label)
cursor = connection.cursor()
cursor.execute(''' SELECT q."q_ID" as q_ID,q.question_text,q.difficulty_set,
q.difficulty_observed,s.subject
FROM "ARFA_app_evaluation" as e,"ARFA_app_question" as q,
q.difficulty_observed,s.subject,o."option_Value" as option_details,
o."is_Answer"
FROM "ARFA_app_contains" as c,"ARFA_app_question" as q,
"ARFA_app_options" as o, "ARFA_app_subject" as s
GROUP BY s.subject,q."q_ID",q.question_text,q.difficulty_set,q.difficulty_observed
ORDER BY s.subject,q.difficulty_observed desc''',[test_ID])
WHERE o."q_ID_id" = q."q_ID" and c."q_ID_id" = q."q_ID" and q."subject_ID_id" = s."subject_ID"
and c."test_ID_id" = %s
ORDER BY s.subject,q.difficulty_observed desc,o."q_ID_id" ''',[test_ID])
rows = cursor.fetchall()
print rows
columns = [col[0] for col in cursor.description]
q_stats = []
for val in rows:
q_stats.append(dict(zip(columns,val)))
# rows = cursor.fetchall()
# print rows
# columns = [col[0] for col in cursor.description]
# q_stats = []
# for val in rows:
# q_stats.append(dict(zip(columns,val)))
q_stats = get_questions_dict(cursor)
# print "q_stats",q_stats
print hist
print q_stats
args = {"student_performance":res_stud,"test_aggregates":res_agg,"question_stats":q_stats,"distribution":hist}
return args
def get_histogram(hist,label):
N = len(hist)
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
rects = ax.bar(ind, hist, width, color='b')
# add some text for labels, title and axes ticks
ax.set_ylabel('Scores')
ax.set_title('Distribution of scores')
ax.set_xticks(ind )
ax.set_xticklabels(label)
autolabel(rects,ax)
imgpath ="TestAnalysis/"+ str(datetime.datetime.now())+".png"
plt.savefig(imgpath)
def autolabel(rects,ax):
"""
Attach a text label above each bar displaying its height
"""
for rect in rects:
height = rect.get_height()
ax.text(rect.get_x() + rect.get_width()/2., 1.00*height,
'%d' % int(height),
ha='center', va='bottom')
def cleanup():
return
def get_questions_dict(cursor):
rows = cursor.fetchall()
print rows
columns = [col[0] for col in cursor.description]
res=[]
options_so_far = []
......@@ -263,4 +227,5 @@ def get_questions_dict(cursor):
if not(first):
preval[-1] = options_so_far
t = dict(zip(columns[:-1], preval))
res.append(t)
\ No newline at end of file
res.append(t)
return res
\ No newline at end of file
This diff is collapsed.
Todo:
☐ Item
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment