further improvements to questions
This commit is contained in:
@@ -1005,6 +1005,10 @@ class CaseDetail(models.Model):
|
||||
def get_question_schema(self):
|
||||
return json.dumps(self.question_schema)
|
||||
|
||||
def get_question_answers(self):
|
||||
"""Returns the correct question answers as a json string"""
|
||||
return json.dumps(self.question_answers)
|
||||
|
||||
|
||||
class BaseReportAnswer(models.Model):
|
||||
question = models.ForeignKey(CaseDetail, on_delete=models.CASCADE)
|
||||
@@ -1043,6 +1047,38 @@ class BaseReportAnswer(models.Model):
|
||||
else:
|
||||
raise ValueError("No cid or user specified")
|
||||
|
||||
def get_correct_json_answers(self):
|
||||
if self.question.question_schema is None or not "properties" in self.question.question_schema:
|
||||
return []
|
||||
answers = []
|
||||
print("1", self.json_answer)
|
||||
print("2", self.question.question_answers)
|
||||
for name, value in self.question.question_schema["properties"].items():
|
||||
print(name, value)
|
||||
|
||||
user_answer = self.json_answer[name]
|
||||
correct_answer = self.question.question_answers[name]
|
||||
print(correct_answer)
|
||||
|
||||
match value:
|
||||
case {"type": "string", "enum": _}:
|
||||
print("YES", value)
|
||||
automark = True
|
||||
answer_is_correct = user_answer == correct_answer
|
||||
case {"type": "string"}:
|
||||
if user_answer == correct_answer:
|
||||
automark = True
|
||||
answer_is_correct = True
|
||||
else:
|
||||
automark = False
|
||||
answer_is_correct = False
|
||||
case _:
|
||||
automark = False
|
||||
answer_is_correct = user_answer == correct_answer
|
||||
answers.append((value, user_answer, correct_answer, answer_is_correct, automark))
|
||||
|
||||
return answers
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user