more fixes

This commit is contained in:
Ross
2020-11-26 21:35:06 +00:00
parent 2e555b0b06
commit 79d8143c7e
4 changed files with 41 additions and 18 deletions
+9
View File
@@ -109,6 +109,15 @@ class AnatomyQuestion(models.Model):
return "{} ({}) [{}, {}]".format(a.answer, exams, self.modality,
self.structure)
def GetPrimaryAnswer(self):
return self.answers.all().first().answer
def GetExams(self):
e = self.exams.all().values_list("name", flat=True)
exams = ", ".join(e)
return exams
def GetUnmarkedAnswersString(self):
unmarked_answers = self.GetUnmarkedAnswers()
+4 -1
View File
@@ -12,7 +12,10 @@
<ol>
{% for question in questions.all %}
<li>{{ question }}<img src="{{ question.image|thumbnail_url:'exam-list' }}" alt="thumbail" /></li>
<li>{{ question.description }}: {{ question.GetPrimaryAnswer }}<img src="{{ question.image|thumbnail_url:'exam-list' }}" alt="thumbail" />
<br />
Exams: {{ question.GetExams }} / Modality: {{ question.modality }}
</li>
{% endfor %}
</ol>
<a href="{% url 'anatomy:exam_json' pk=exam.pk %}">JSON</a>
@@ -2,12 +2,14 @@
{% block content %}
<div class="anatomy">
<h2>{{ exam.name }}</h2>
<h3>Candidate: {{ user_names|get_item:user }}</h3>
<!-- Answers: {{ user_answers_and_marks|get_item:user }}-->
Answers: {% for ans, score in answers_and_marks %}
<h2>Exam: {{ exam.name }}</h2>
<h3>Candidate: {{ cid }}</h3>
Answers:
<ul>{% for ans, score, correct_answer in answers_and_marks %}
<li>Question {{forloop.counter}}: {{ correct_answer }}</li>
{{ans}} ({{score}}),
{% endfor %}
<br /> Total mark: {{ score }}
</ul>
<br /> Total mark: {{ total_score }}
</div>
{% endblock %}
+21 -12
View File
@@ -549,16 +549,23 @@ def exam_scores_cid(request, pk):
user_scores[user] = sum(user_answers_marks[user])
user_scores_list = list(user_scores.values())
mean = statistics.mean(user_scores_list)
median = statistics.median(user_scores_list)
try:
mode = statistics.mode(user_scores_list)
except statistics.StatisticsError:
mode = "No unique mode"
df = user_scores_list
fig = px.histogram(df, x=0)
fig_html = fig.to_html()
if len(user_scores_list) < 1:
mean = 0
median = 0
mode = 0
fig_html = ""
else:
mean = statistics.mean(user_scores_list)
median = statistics.median(user_scores_list)
try:
mode = statistics.mode(user_scores_list)
except statistics.StatisticsError:
mode = "No unique mode"
df = user_scores_list
fig = px.histogram(df, x=0)
fig_html = fig.to_html()
total = len(questions)
@@ -592,6 +599,7 @@ def exam_scores_cid_user(request, pk, sk):
answers_marks = []
answers = []
for q in questions:
# Get user answer
s = q.cid_user_answers.filter(cid=cid)
@@ -608,11 +616,12 @@ def exam_scores_cid_user(request, pk, sk):
a = 1
else:
a = 0
correct_answer = q.GetPrimaryAnswer()
answers.append(ans)
answers_marks.append(a)
answers_and_marks.append((ans, a))
answers_and_marks.append((ans, a, correct_answer))
score = sum(answers_marks)
total_score = sum(answers_marks)
total = len(questions)
@@ -625,7 +634,7 @@ def exam_scores_cid_user(request, pk, sk):
"questions": questions,
"answers": answers,
"answers_marks": answers_marks,
"score": score,
"total_score": total_score,
"answers_and_marks": answers_and_marks,
},
)