This commit is contained in:
Ross
2021-02-16 12:45:19 +00:00
parent 1e8697e6bb
commit a0b9e92aba
4 changed files with 47 additions and 60 deletions
+21 -42
View File
@@ -143,6 +143,14 @@ class Long(models.Model):
["http://penracourses.org.uk{}".format(i.url) for i in self.GetImages()]
)
def GetUnmarkedAnswerCount(self):
answers = self.cid_user_answers.all()
return len([ans for ans in answers if not ans.is_marked()])
def GetUnmarkedAnswers(self):
answers = self.cid_user_answers.all()
return [ans for ans in answers if not ans.is_marked()]
# def GetNonFeedbackQuestionImages(self):
# return self.GetImages()
@@ -408,7 +416,7 @@ class CidUserAnswer(models.Model):
EIGHT = "8", _("8")
score = models.CharField(
max_length=3, choices=ScoreOptions.choices, default=ScoreOptions.UNMARKED
max_length=3, choices=ScoreOptions.choices, default=ScoreOptions.UNMARKED, blank=True
)
created = models.DateTimeField(auto_now_add=True)
@@ -419,8 +427,8 @@ class CidUserAnswer(models.Model):
exam = self.exam
except (Exam.DoesNotExist, KeyError) as e:
exam = "None"
return "{}/{}/{}: {}".format(
exam, self.cid, self.question.GetPrimaryAnswer(), self.answer
return "{}/{}/{} ({})".format(
exam, self.cid, self.created, self.updated
)
def save(self, *args, **kwargs):
@@ -428,13 +436,10 @@ class CidUserAnswer(models.Model):
return super(CidUserAnswer, self).save(*args, **kwargs)
def clean(self):
if self.answer:
self.answer = self.answer.strip()
for ans in (self.answer_observations, self.answer_interpretation, self.answer_principle_diagnosis, self.answer_differential_diagnosis, self.answer_management):
if ans:
ans = ans.strip()
s = self.answer.lower()
s = s.translate(str.maketrans("", "", string.punctuation))
self.answer_compare = s
# def get_compare_string(self):
# # strip here should be unneccasry (providing clean is now working)
@@ -442,37 +447,11 @@ class CidUserAnswer(models.Model):
# s = s.translate(str.maketrans('', '', string.punctuation))
# return s
def get_answer_score(self):
q = self.question
# First step we check that the normal/abnormal states match
if q.normal != self.normal:
# If they don't match the answer is wrong (score is 0)
return 0
# If both are normal full marks
elif q.normal and self.normal:
return 2
# Then compare answer strings (as per anatomy questions)
ans = self.answer_compare
if (
q.answers.filter(
answer_compare__iexact=ans, status=Answer.MarkOptions.CORRECT
).first()
is not None
):
mark = 2
elif (
q.answers.filter(
answer_compare__iexact=ans, status=Answer.MarkOptions.HALF_MARK
).first()
is not None
):
mark = 1
elif q.answers.filter(
answer_compare__iexact=ans, status=Answer.MarkOptions.INCORRECT
).first():
mark = 0
def is_marked(self):
if self.score == "":
return False
else:
mark = "unmarked"
return mark
return True
def get_answer_score(self):
return self.score