Commit b546ab5e authored by NARRA SURAJ's avatar NARRA SURAJ

improved evaluation

parent 808a20df
......@@ -9,6 +9,7 @@ from .models import Question
from .models import Options
from .models import Student
from .models import Evaluation
from .models import Takes
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
......@@ -16,6 +17,7 @@ from django.views.decorators.cache import cache_control
import json
from django.db import connection
from django.db import IntegrityError
import datetime
def evaluate(responses, otherData):
#create evaluation object
......@@ -27,14 +29,17 @@ def evaluate(responses, otherData):
# attempt.student = Student.objects.get(username=request.session['username'])
# attemptObj.test = responses[0].test_ID
# attemptObj.save()
evalObj.student_id = otherData['username']
evalObj.test_ID_id = int(otherData['testID'])
# evalObj.attempt = attemptObj
evalObj.q_ID = None
totalMarks = 0
correctAnswer = None
for response in responses:
evalObj = Evaluation()
evalObj.student_id = otherData['username']
evalObj.test_ID_id = int(otherData['testID'])
evalObj.q_ID = None
(question, options), = response.items()
question = int(question)
# options = responses[question]
......@@ -57,6 +62,7 @@ def evaluate(responses, otherData):
print correctAnswer
if len(responseList) == len(correctAnswer) and sorted(responseList) == sorted(correctAnswer):
evalObj.marks = 1
totalMarks = totalMarks + evalObj.marks
# print "responses"
# print responseList
# print correctAnswer
......@@ -67,6 +73,17 @@ def evaluate(responses, otherData):
print "Integrity error - evaluation not recorded"
pass
takesObj = Takes()
takesObj.student_id = otherData['username']
takesObj.test_ID_id = otherData['testID']
takesObj.time_stamp = datetime.datetime.now()
takesObj.total_marks = totalMarks
try:
takesObj.save()
except IntegrityError as e:
print "Integrity error in Takes - not recorded"
pass
def getOptions(question): #returns queryset
return models.Options.objects.get(q_ID = question)
......
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