many Longs fixes
This commit is contained in:
+117
-112
@@ -409,13 +409,18 @@ class LongCreateBase(RevisionMixin, LoginRequiredMixin, CreateView):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(LongCreateBase, self).get_context_data(**kwargs)
|
||||
|
||||
queryset = LongSeries.objects.select_related("modality", "examination", "plane").prefetch_related("long").filter(pk=62)#.values()
|
||||
print("TEST")
|
||||
print(queryset)
|
||||
#queryset = LongSeries.objects.all()
|
||||
if self.request.POST:
|
||||
context["series_formset"] = SeriesFormSet(
|
||||
self.request.POST, self.request.FILES
|
||||
self.request.POST, self.request.FILES, queryset=queryset
|
||||
)
|
||||
context["series_formset"].full_clean()
|
||||
else:
|
||||
context["series_formset"] = SeriesFormSet()
|
||||
context["series_formset"] = SeriesFormSet(queryset=queryset)
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
@@ -713,7 +718,7 @@ def mark_answer(request, exam_id, question_number, answer_id, override=False):
|
||||
answer_id=answer_id,
|
||||
)
|
||||
# elif "previous" in request.POST:
|
||||
# return redirect("longs:mark_question_overview", pk=exam_id, sk=n - 1)
|
||||
# return redirect("longs:mark", pk=exam_id, sk=n - 1)
|
||||
|
||||
else:
|
||||
form = MarkLongQuestionSingleForm(initial={"score": answer.score})
|
||||
@@ -763,7 +768,7 @@ def mark_answer(request, exam_id, question_number, answer_id, override=False):
|
||||
answer_id=answer_id,
|
||||
)
|
||||
# elif "previous" in request.POST:
|
||||
# return redirect("longs:mark_question_overview", pk=exam_id, sk=n - 1)
|
||||
# return redirect("longs:mark", pk=exam_id, sk=n - 1)
|
||||
|
||||
else:
|
||||
try:
|
||||
@@ -811,7 +816,7 @@ def mark_answer(request, exam_id, question_number, answer_id, override=False):
|
||||
# @user_passes_test(user_is_admin, login_url="/accounts/login")
|
||||
@login_required
|
||||
@user_is_long_marker
|
||||
def mark_question_overview(request, exam_id, sk):
|
||||
def mark(request, exam_id, sk):
|
||||
exam = get_object_or_404(Exam, pk=exam_id)
|
||||
|
||||
questions = exam.exam_questions.all()
|
||||
@@ -864,113 +869,113 @@ def mark_question_overview(request, exam_id, sk):
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@user_is_long_marker
|
||||
def exam_scores_all(request, pk):
|
||||
exam = get_object_or_404(Exam, pk=pk)
|
||||
|
||||
questions = exam.exam_questions.all()
|
||||
|
||||
cids = (
|
||||
UserAnswer.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, (score 4)
|
||||
user_answers_marks[cid].append(4)
|
||||
# user_answers[cid].append("")
|
||||
by_question[q].append(("", 4))
|
||||
continue
|
||||
else:
|
||||
ans = ""
|
||||
answer_score = s.get_answer_score()
|
||||
if answer_score == "":
|
||||
index = exam.get_question_index(q)
|
||||
unmarked.add(index)
|
||||
# user_answers[cid].append(ans)
|
||||
user_answers_marks[cid].append(answer_score)
|
||||
# user_answers_and_marks[cid].append((ans, answer_score))
|
||||
|
||||
by_question[q].append((ans, answer_score))
|
||||
|
||||
user_scores = {}
|
||||
user_scores_normalised = {}
|
||||
for user in user_answers_marks:
|
||||
user_scores[user] = sum([i for i in user_answers_marks[user] if i != ""])
|
||||
user_scores_normalised[user] = normaliseScore(
|
||||
sum([i for i in user_answers_marks[user] if i != ""])
|
||||
)
|
||||
|
||||
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) * 2
|
||||
|
||||
return render(
|
||||
request,
|
||||
"longs/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_normalised": user_scores_normalised,
|
||||
"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,
|
||||
},
|
||||
)
|
||||
#@login_required
|
||||
#@user_is_long_marker
|
||||
#def exam_scores_all(request, pk):
|
||||
# exam = get_object_or_404(Exam, pk=pk)
|
||||
#
|
||||
# questions = exam.exam_questions.all()
|
||||
#
|
||||
# cids = (
|
||||
# UserAnswer.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, (score 4)
|
||||
# user_answers_marks[cid].append(4)
|
||||
# # user_answers[cid].append("")
|
||||
# by_question[q].append(("", 4))
|
||||
# continue
|
||||
# else:
|
||||
# ans = ""
|
||||
# answer_score = s.get_answer_score()
|
||||
# if answer_score == "":
|
||||
# index = exam.get_question_index(q)
|
||||
# unmarked.add(index)
|
||||
# # user_answers[cid].append(ans)
|
||||
# user_answers_marks[cid].append(answer_score)
|
||||
# # user_answers_and_marks[cid].append((ans, answer_score))
|
||||
#
|
||||
# by_question[q].append((ans, answer_score))
|
||||
#
|
||||
# user_scores = {}
|
||||
# user_scores_normalised = {}
|
||||
# for user in user_answers_marks:
|
||||
# user_scores[user] = sum([i for i in user_answers_marks[user] if i != ""])
|
||||
# user_scores_normalised[user] = normaliseScore(
|
||||
# sum([i for i in user_answers_marks[user] if i != ""])
|
||||
# )
|
||||
#
|
||||
# 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) * 2
|
||||
#
|
||||
# return render(
|
||||
# request,
|
||||
# "longs/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_normalised": user_scores_normalised,
|
||||
# "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, cid, passcode):
|
||||
|
||||
Reference in New Issue
Block a user