.
This commit is contained in:
+1
-1
@@ -148,7 +148,7 @@ class ExamBase(models.Model):
|
||||
return authors
|
||||
|
||||
def check_cid_user(self, cid, passcode, request=None):
|
||||
if request is not None and request.user.is_superuser():
|
||||
if request is not None and request.user.is_superuser:
|
||||
return True
|
||||
|
||||
if self.valid_users.exists():
|
||||
|
||||
+2
-1
@@ -51,7 +51,8 @@ class QuestionTable(tables.Table):
|
||||
# "c_answer",
|
||||
# "d_answer",
|
||||
# "e_answer",
|
||||
"best_answer",
|
||||
# "best_answer",
|
||||
"feedback",
|
||||
"created_date",
|
||||
"category",
|
||||
"author",
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
<tr>
|
||||
<th>Candidate</th>
|
||||
{% for cid in cids %}
|
||||
{% comment %} <th><a href="{% url 'physics:exam_scores_cid_user' exam.pk cid %}">{{cid}}</a></th> {% endcomment %}
|
||||
<th><a href="">{{cid}}</a></th>
|
||||
<th><a href="{% url 'physics:exam_scores_cid_user' exam.pk cid None %}">{{cid}}</a></th>
|
||||
{% comment %} <th><a href="">{{cid}}</a></th> {% endcomment %}
|
||||
{% endfor %}
|
||||
|
||||
</tr>
|
||||
|
||||
+2
-116
@@ -88,124 +88,10 @@ def active_exams(request):
|
||||
return render(request, "physics/available_exam_list.html", {"exams": active_exams})
|
||||
|
||||
|
||||
@login_required
|
||||
def exam_scores_cid(request, pk):
|
||||
def exam_scores_cid_user(request, pk, cid, passcode):
|
||||
exam = get_object_or_404(Exam, pk=pk)
|
||||
|
||||
if not exam.exam_mode:
|
||||
raise Http404("Packet not in exam mode")
|
||||
|
||||
questions = exam.exam_questions.all()
|
||||
|
||||
cids = (
|
||||
CidUserAnswer.objects.filter(question__in=questions, exam__id=pk)
|
||||
.order_by("cid")
|
||||
.values_list("cid", flat=True)
|
||||
.distinct()
|
||||
)
|
||||
|
||||
user_answers_and_marks = defaultdict(list)
|
||||
user_answers_marks = defaultdict(list)
|
||||
user_answers = defaultdict(list)
|
||||
user_names = {}
|
||||
|
||||
by_question = defaultdict(list)
|
||||
unmarked = set()
|
||||
|
||||
# Loop through all candidates
|
||||
for cid in cids:
|
||||
# Convoluted (probably...)
|
||||
user_names[cid] = cid
|
||||
for q in questions:
|
||||
# Get user answer
|
||||
s = q.cid_user_answers.filter(cid=cid, exam__id=pk).first()
|
||||
if not s:
|
||||
# skip if no answer
|
||||
user_answers_marks[cid].append((0, 0, 0, 0, 0))
|
||||
user_answers[cid].append(("", "", "", "", ""))
|
||||
by_question[q].append(
|
||||
(
|
||||
("", 0),
|
||||
("", 0),
|
||||
("", 0),
|
||||
("", 0),
|
||||
("", 0),
|
||||
)
|
||||
)
|
||||
continue
|
||||
|
||||
ans = s.get_answers()
|
||||
answer_scores = s.get_answer_score()
|
||||
|
||||
user_answers[cid].append(ans)
|
||||
user_answers_marks[cid].append(answer_scores)
|
||||
user_answers_and_marks[cid].append((ans, answer_scores))
|
||||
|
||||
zipped_ans_scores = zip(ans, answer_scores)
|
||||
|
||||
by_question[q].append(zipped_ans_scores)
|
||||
|
||||
user_scores = {}
|
||||
for user in user_answers_marks:
|
||||
user_scores[user] = sum([sum(i) for i in user_answers_marks[user]])
|
||||
|
||||
user_scores_list = list(user_scores.values())
|
||||
|
||||
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,
|
||||
title="{}: distribution of scores".format(exam),
|
||||
labels={"0": "Score"},
|
||||
height=400,
|
||||
width=600,
|
||||
)
|
||||
fig_html = fig.to_html()
|
||||
|
||||
max_score = len(questions)
|
||||
|
||||
return render(
|
||||
request,
|
||||
"physics/exam_scores.html",
|
||||
{
|
||||
"cids": cids,
|
||||
"exam": exam,
|
||||
"unmarked": unmarked,
|
||||
"questions": questions,
|
||||
"by_question": by_question,
|
||||
"user_answers": dict(user_answers),
|
||||
"user_answers_marks": dict(user_answers_marks),
|
||||
"user_scores": user_scores,
|
||||
"user_scores_list": user_scores_list,
|
||||
"user_names": user_names,
|
||||
"user_answers_and_marks": user_answers_and_marks,
|
||||
"max_score": max_score,
|
||||
"mean": mean,
|
||||
"median": median,
|
||||
"mode": mode,
|
||||
"plot": fig_html,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def exam_scores_cid_user(request, pk, sk, passcode):
|
||||
exam = get_object_or_404(Exam, pk=pk)
|
||||
|
||||
cid = sk
|
||||
if not exam.check_cid_user(cid, passcode):
|
||||
if not exam.check_cid_user(cid, passcode, request):
|
||||
raise Http404("Error accessing exam")
|
||||
|
||||
questions = exam.exam_questions.all()
|
||||
|
||||
+1
-1
@@ -105,7 +105,7 @@ def exam_scores_cid_user(request, pk, cid, passcode):
|
||||
answer_score = 0
|
||||
ans = ""
|
||||
else:
|
||||
answer_score = user_answer.get_score()
|
||||
answer_score = user_answer.get_answer_score()
|
||||
ans = user_answer.get_answer()
|
||||
|
||||
correct_answer = q.get_correct_answer()
|
||||
|
||||
Reference in New Issue
Block a user