Commit 4e3b5104 authored by NARRA SURAJ's avatar NARRA SURAJ

improved evaluation

parent b546ab5e
......@@ -17,22 +17,36 @@ from django.views.decorators.cache import cache_control
import json
from django.db import connection
from django.db import IntegrityError
from pprint import pprint
import datetime
def evaluate(responses, otherData):
"""responses contains a list of dicts of the form {q_ID: [option1, option2 ..]}
other data contains any other data necessary for evaluation such as testID and studentID"""
#create evaluation object
evalObj = Evaluation()
if len(responses) == 0:
return
# attemptObj = Attempt()
# attempt.student = Student.objects.get(username=request.session['username'])
# attemptObj.test = responses[0].test_ID
# attemptObj.save()
#debugging:
print "responses:"
print responses
#marks for each question:
#list of question ids
print "QList"
QList = [int(question) for [(question, _)] in [response.items() for response in responses]]
print QList
#select contains objects for which test_ID=tetsID, q_ID belongs to list QList
contains = models.Contains.objects.filter(test_ID=otherData['testID'], q_ID__in=QList)
#put these in a dictionary {q_ID:[marks_pos, marks_neg]}
marksDict = {}
for c in contains:
marksDict[c.q_ID_id] = [c.marks_pos, c.marks_neg]
# evalObj.attempt = attemptObj
totalMarks = 0
correctAnswer = None
for response in responses:
......@@ -60,13 +74,16 @@ def evaluate(responses, otherData):
# correctAnswer = list(correctAnswer.values('pk'))
# correctAnswer = list(map(lambda x: x['pk'], correctAnswer))
print correctAnswer
#correct answer
if len(responseList) == len(correctAnswer) and sorted(responseList) == sorted(correctAnswer):
evalObj.marks = 1
evalObj.marks = marksDict[question][0] #0 - first in the list, marks_pos
totalMarks = totalMarks + evalObj.marks
# print "responses"
# print responseList
# print correctAnswer
# print evalObj
#else, it is a wrong answer since no attempt results in no response
else:
evalObj.marks = marksDict[question][1] #1 - second in the list, marks_neg
totalMarks = totalMarks + evalObj.marks
try:
evalObj.save()
except IntegrityError as e:
......
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