.
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
# Generated by Django 3.1.3 on 2021-02-17 14:23
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('longs', '0023_auto_20210216_1315'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='ciduseranswer',
|
||||||
|
options={'ordering': ['cid']},
|
||||||
|
),
|
||||||
|
]
|
||||||
+5
-5
@@ -406,15 +406,15 @@ class CidUserAnswer(models.Model):
|
|||||||
|
|
||||||
class ScoreOptions(models.TextChoices):
|
class ScoreOptions(models.TextChoices):
|
||||||
UNMARKED = "", _("Unmarked")
|
UNMARKED = "", _("Unmarked")
|
||||||
FOUR = "4", _("4")
|
FOUR = 4, _("4")
|
||||||
FOUR_HALF = "4.5", _("4.5")
|
FOUR_HALF = "4.5", _("4.5")
|
||||||
FIVE = "5", _("5")
|
FIVE = 5, _("5")
|
||||||
FIVE_HALF = "5.5", _("5.5")
|
FIVE_HALF = "5.5", _("5.5")
|
||||||
SIX = "6", _("6")
|
SIX = 6, _("6")
|
||||||
SIX_HALF = "6.5", _("6.5")
|
SIX_HALF = "6.5", _("6.5")
|
||||||
SEVEN = "7", _("7")
|
SEVEN = 7, _("7")
|
||||||
SEVEN_HALF = "7.5", _("7.5")
|
SEVEN_HALF = "7.5", _("7.5")
|
||||||
EIGHT = "8", _("8")
|
EIGHT = 8, _("8")
|
||||||
|
|
||||||
score = models.CharField(
|
score = models.CharField(
|
||||||
max_length=3, choices=ScoreOptions.choices, default=ScoreOptions.UNMARKED, blank=True
|
max_length=3, choices=ScoreOptions.choices, default=ScoreOptions.UNMARKED, blank=True
|
||||||
|
|||||||
@@ -49,7 +49,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>Question {{forloop.counter}}</td>
|
<td>Question {{forloop.counter}}</td>
|
||||||
{% for ans, score in by_question|get_item:question %}
|
{% for ans, score in by_question|get_item:question %}
|
||||||
<td class="user-answer-score-{{score}}" title="answer score: {{score}}">{{ans}}</td>
|
<td class="user-answer-score-{{score}}" title="answer score: {{score}}">{{score}}</td>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
<h2>Exam: {{ exam.name }}</h2>
|
<h2>Exam: {{ exam.name }}</h2>
|
||||||
<h3>Candidate: {{ cid }}</h3>
|
<h3>Candidate: {{ cid }}</h3>
|
||||||
Answers:
|
Answers:
|
||||||
<ul>{% for ans, score, correct_answer in answers_and_marks %}
|
<ul>{% for score in answers_marks %}
|
||||||
<li class="user-answer-li">Question {{forloop.counter}} - Correct answer: <span class="correct-answer">{{ correct_answer }}</span></li>
|
<li class="user-answer-li">Question {{forloop.counter}}</li>
|
||||||
<span class="user-answer-score user-answer-score-{{score}}"><pre>{{ans}}</pre> ({{score}})</span>
|
<span class="user-answer-score user-answer-score-{{score}}"><pre>{{ans}}</pre> ({{score}})</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
+22
-29
@@ -787,27 +787,27 @@ def exam_scores_cid(request, pk):
|
|||||||
s = q.cid_user_answers.filter(cid=cid).first()
|
s = q.cid_user_answers.filter(cid=cid).first()
|
||||||
|
|
||||||
if not s:
|
if not s:
|
||||||
# skip if no answer
|
# skip if no answer, (score 4)
|
||||||
user_answers_marks[cid].append(0)
|
user_answers_marks[cid].append(4)
|
||||||
user_answers[cid].append("")
|
#user_answers[cid].append("")
|
||||||
by_question[q].append(("", 0))
|
by_question[q].append(("", 4))
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
ans = s.answer
|
ans = ""
|
||||||
answer_score = s.get_answer_score()
|
answer_score = s.get_answer_score()
|
||||||
if answer_score == "unmarked":
|
if answer_score == "":
|
||||||
index = exam.get_question_index(q)
|
index = exam.get_question_index(q)
|
||||||
unmarked.add(index)
|
unmarked.add(index)
|
||||||
user_answers[cid].append(ans)
|
#user_answers[cid].append(ans)
|
||||||
user_answers_marks[cid].append(answer_score)
|
user_answers_marks[cid].append(answer_score)
|
||||||
user_answers_and_marks[cid].append((ans, answer_score))
|
#user_answers_and_marks[cid].append((ans, answer_score))
|
||||||
|
|
||||||
by_question[q].append((ans, answer_score))
|
by_question[q].append((ans, answer_score))
|
||||||
|
|
||||||
user_scores = {}
|
user_scores = {}
|
||||||
for user in user_answers_marks:
|
for user in user_answers_marks:
|
||||||
user_scores[user] = sum(
|
user_scores[user] = sum(
|
||||||
[i for i in user_answers_marks[user] if i != "unmarked"]
|
[float(i) for i in user_answers_marks[user] if i != ""]
|
||||||
)
|
)
|
||||||
|
|
||||||
user_scores_list = list(user_scores.values())
|
user_scores_list = list(user_scores.values())
|
||||||
@@ -847,12 +847,12 @@ def exam_scores_cid(request, pk):
|
|||||||
"unmarked": unmarked,
|
"unmarked": unmarked,
|
||||||
"questions": questions,
|
"questions": questions,
|
||||||
"by_question": by_question,
|
"by_question": by_question,
|
||||||
"user_answers": dict(user_answers),
|
#"user_answers": dict(user_answers),
|
||||||
"user_answers_marks": dict(user_answers_marks),
|
"user_answers_marks": dict(user_answers_marks),
|
||||||
"user_scores": user_scores,
|
"user_scores": user_scores,
|
||||||
"user_scores_list": user_scores_list,
|
"user_scores_list": user_scores_list,
|
||||||
"user_names": user_names,
|
"user_names": user_names,
|
||||||
"user_answers_and_marks": user_answers_and_marks,
|
#"user_answers_and_marks": user_answers_and_marks,
|
||||||
"max_score": max_score,
|
"max_score": max_score,
|
||||||
"mean": mean,
|
"mean": mean,
|
||||||
"median": median,
|
"median": median,
|
||||||
@@ -870,9 +870,9 @@ def exam_scores_cid_user(request, pk, sk):
|
|||||||
|
|
||||||
questions = exam.exam_questions.all()
|
questions = exam.exam_questions.all()
|
||||||
|
|
||||||
answers_and_marks = []
|
#answers_and_marks = []
|
||||||
answers_marks = []
|
answers_marks = []
|
||||||
answers = []
|
#answers = []
|
||||||
|
|
||||||
for q in questions:
|
for q in questions:
|
||||||
# Get user answer
|
# Get user answer
|
||||||
@@ -881,28 +881,21 @@ def exam_scores_cid_user(request, pk, sk):
|
|||||||
|
|
||||||
if not user_answer or user_answer is None:
|
if not user_answer or user_answer is None:
|
||||||
# skip if no answer
|
# skip if no answer
|
||||||
answers_marks.append(0)
|
#answers_marks.append("")
|
||||||
#answers.append("")
|
#answers.append("")
|
||||||
answer_score = 0
|
answer_score = 4
|
||||||
ans = "Not answered"
|
#ans = "Not answered"
|
||||||
else:
|
else:
|
||||||
if user_answer.normal:
|
|
||||||
ans = "Normal"
|
|
||||||
else:
|
|
||||||
ans = user_answer.answer
|
|
||||||
answer_score = user_answer.get_answer_score()
|
answer_score = user_answer.get_answer_score()
|
||||||
|
|
||||||
correct_answer = q.GetPrimaryAnswer()
|
|
||||||
|
|
||||||
if not exam.publish_results:
|
if not exam.publish_results:
|
||||||
correct_answer = "*****"
|
|
||||||
answer_score = 0
|
answer_score = 0
|
||||||
answers.append(ans)
|
#answers.append(ans)
|
||||||
answers_marks.append(answer_score)
|
answers_marks.append(answer_score)
|
||||||
answers_and_marks.append((ans, answer_score, correct_answer))
|
#answers_and_marks.append((ans, answer_score, correct_answer))
|
||||||
|
|
||||||
if "unmarked" in answers_marks:
|
if "" in answers_marks:
|
||||||
answered = [i for i in answers_marks if type(i) == int]
|
answered = [int(i) for i in answers_marks if i != ""]
|
||||||
total_score = sum(answered)
|
total_score = sum(answered)
|
||||||
unmarked_number = len(answers_marks) - len(answered)
|
unmarked_number = len(answers_marks) - len(answered)
|
||||||
total_score = "{} ({} unmarked)".format(total_score, unmarked_number)
|
total_score = "{} ({} unmarked)".format(total_score, unmarked_number)
|
||||||
@@ -918,11 +911,11 @@ def exam_scores_cid_user(request, pk, sk):
|
|||||||
"exam": exam,
|
"exam": exam,
|
||||||
"cid": cid,
|
"cid": cid,
|
||||||
"questions": questions,
|
"questions": questions,
|
||||||
"answers": answers,
|
#"answers": answers,
|
||||||
"answers_marks": answers_marks,
|
"answers_marks": answers_marks,
|
||||||
"total_score": total_score,
|
"total_score": total_score,
|
||||||
"max_score": max_score,
|
"max_score": max_score,
|
||||||
"answers_and_marks": answers_and_marks,
|
#"answers_and_marks": answers_and_marks,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+19
-12
@@ -30,12 +30,14 @@ from anatomy.models import Exam as AnatomyExam
|
|||||||
from rapids.models import CidUserAnswer as RapidsCidUserAnswer
|
from rapids.models import CidUserAnswer as RapidsCidUserAnswer
|
||||||
from rapids.models import Exam as RapidsExam
|
from rapids.models import Exam as RapidsExam
|
||||||
|
|
||||||
|
from longs.models import CidUserAnswer as LongsCidUserAnswer
|
||||||
|
from longs.models import Exam as LongsExam
|
||||||
|
|
||||||
from anatomy.views import AnatomyExamViews
|
from anatomy.views import AnatomyExamViews
|
||||||
from rapids.views import RapidExamViews
|
from rapids.views import RapidExamViews
|
||||||
from longs.views import LongExamViews
|
from longs.views import LongExamViews
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def profile(request):
|
def profile(request):
|
||||||
user = request.user
|
user = request.user
|
||||||
@@ -50,21 +52,23 @@ def cid_selector(request):
|
|||||||
|
|
||||||
|
|
||||||
def cid_scores(request, pk):
|
def cid_scores(request, pk):
|
||||||
#exam = get_object_or_404(Exam, pk=pk)
|
# exam = get_object_or_404(Exam, pk=pk)
|
||||||
|
|
||||||
# TODO:Need some kind of test for cid
|
# TODO:Need some kind of test for cid
|
||||||
cid = pk
|
cid = pk
|
||||||
|
|
||||||
#questions = exam.exam_questions.all()
|
# questions = exam.exam_questions.all()
|
||||||
physics_answers = PhysicsCidUserAnswer.objects.filter(
|
physics_answers = PhysicsCidUserAnswer.objects.filter(cid=cid)
|
||||||
cid=cid)
|
anatomy_answers = AnatomyCidUserAnswer.objects.filter(cid=cid)
|
||||||
anatomy_answers = AnatomyCidUserAnswer.objects.filter(
|
rapids_answers = RapidsCidUserAnswer.objects.filter(cid=cid)
|
||||||
cid=cid)
|
longs_answers = LongsCidUserAnswer.objects.filter(cid=cid)
|
||||||
rapids_answers = RapidsCidUserAnswer.objects.filter(
|
|
||||||
cid=cid)
|
|
||||||
|
|
||||||
|
if (
|
||||||
if not physics_answers and not anatomy_answers and not rapids_answers:
|
not physics_answers
|
||||||
|
and not anatomy_answers
|
||||||
|
and not rapids_answers
|
||||||
|
and not longs_answers
|
||||||
|
):
|
||||||
raise Http404("cid not found")
|
raise Http404("cid not found")
|
||||||
|
|
||||||
physics_exam_ids = physics_answers.values_list("exam").distinct()
|
physics_exam_ids = physics_answers.values_list("exam").distinct()
|
||||||
@@ -76,6 +80,8 @@ def cid_scores(request, pk):
|
|||||||
rapids_exam_ids = rapids_answers.values_list("exam").distinct()
|
rapids_exam_ids = rapids_answers.values_list("exam").distinct()
|
||||||
rapids_exams = RapidsExam.objects.filter(id__in=rapids_exam_ids)
|
rapids_exams = RapidsExam.objects.filter(id__in=rapids_exam_ids)
|
||||||
|
|
||||||
|
longs_exam_ids = longs_answers.values_list("exam").distinct()
|
||||||
|
longs_exams = LongsExam.objects.filter(id__in=longs_exam_ids)
|
||||||
|
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
@@ -84,10 +90,12 @@ def cid_scores(request, pk):
|
|||||||
"physics_exams": physics_exams,
|
"physics_exams": physics_exams,
|
||||||
"anatomy_exams": anatomy_exams,
|
"anatomy_exams": anatomy_exams,
|
||||||
"rapids_exams": rapids_exams,
|
"rapids_exams": rapids_exams,
|
||||||
|
"longs_exams": longs_exams,
|
||||||
"cid": cid,
|
"cid": cid,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def active_exams(request):
|
def active_exams(request):
|
||||||
anatomy_exams = AnatomyExamViews.active_exams(request, False)
|
anatomy_exams = AnatomyExamViews.active_exams(request, False)
|
||||||
rapid_exams = RapidExamViews.active_exams(request, False)
|
rapid_exams = RapidExamViews.active_exams(request, False)
|
||||||
@@ -100,7 +108,6 @@ def active_exams(request):
|
|||||||
|
|
||||||
active_exams = {"exams": exams}
|
active_exams = {"exams": exams}
|
||||||
|
|
||||||
|
|
||||||
return JsonResponse(active_exams)
|
return JsonResponse(active_exams)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,5 +22,11 @@
|
|||||||
<li><a href="{% url 'rapids:exam_scores_cid_user' pk=exam.pk sk=cid %}">{{exam.name}}</a></li>
|
<li><a href="{% url 'rapids:exam_scores_cid_user' pk=exam.pk sk=cid %}">{{exam.name}}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
<h3>Longs</h3>
|
||||||
|
<ul>
|
||||||
|
{% for exam in longs_exams %}
|
||||||
|
<li><a href="{% url 'longs:exam_scores_cid_user' pk=exam.pk sk=cid %}">{{exam.name}}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user