1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +00:00

Add final part mark analysis

This commit is contained in:
Mo 2022-04-12 15:02:05 +02:00
parent d71070008d
commit 05de612e23
3 changed files with 75 additions and 4 deletions

View file

@ -63,6 +63,7 @@ from advlabdb.utils import (
initActiveSemesterMenuLinks,
randomPassword,
setUserActiveSemester,
sortedSemestersStartingWithNewest,
userActiveSemester,
)
@ -1440,6 +1441,15 @@ class AnalysisView(SecureAdminBaseView):
assistantMarksSubmit = SubmitField(
label="Assistant's marks",
)
finalPartMarksSubmit = SubmitField(
label="Final part marks",
)
def htmlFig(fig):
buf = BytesIO()
fig.savefig(buf, format="png")
return b64encode(buf.getbuffer()).decode("ascii")
def markHist(data, title):
fig = Figure()
@ -1463,10 +1473,7 @@ class AnalysisView(SecureAdminBaseView):
ax.set_title(title)
buf = BytesIO()
fig.savefig(buf, format="png")
return b64encode(buf.getbuffer()).decode("ascii")
return AnalysisView.htmlFig(fig)
def markHists(markType, activeAssistants):
attr = markType.lower() + "_mark"
@ -1512,6 +1519,53 @@ class AnalysisView(SecureAdminBaseView):
protocolMarkHists=protocolMarkHists,
)
if form.finalPartMarksSubmit.data:
parts = userActiveSemester().parts
activeSemesterFinalPartMarksHists = [
AnalysisView.markHist(
data=np.array([partStudent.final_part_mark for partStudent in part.part_students]),
title=part.repr(),
)
for part in parts
]
semesters = sortedSemestersStartingWithNewest()
semesterLabels = [semester.repr() for semester in semesters]
meanFinalPartMarks = np.flip(
[
np.mean(
np.hstack(
[
[partStudent.final_part_mark for partStudent in part.part_students]
for part in semester.parts
]
)
)
for semester in semesters
]
)
fig = Figure()
ax = fig.subplots()
x = range(1, len(meanFinalPartMarks) + 1)
ax.plot(
x,
meanFinalPartMarks,
marker="d",
)
# TODO: Change ticks to semester labels
# TODO: Check linestyle
ax.set_xticks(x)
ax.set_xlim(0.5, x[-1] + 0.5)
meanFinalPartMarksPlot = AnalysisView.htmlFig(fig)
return self.render(
"analysis/final_part_marks.html",
activeSemesterFinalPartMarksHists=activeSemesterFinalPartMarksHists,
meanFinalPartMarksPlot=meanFinalPartMarksPlot,
)
return self.render("analysis/analysis.html", form=form)

View file

@ -9,5 +9,7 @@
<form method="POST">
{{ form.csrf_token }}
{{ form.assistantMarksSubmit }}
<hr>
{{ form.finalPartMarksSubmit }}
</form>
{% endblock body %}

View file

@ -0,0 +1,15 @@
{% from "macros.html" import information %}
{% extends "admin/master.html" %}
{% block body %}
{{information(current_user, userActiveSemester, role="admin")}}
<hr>
{% for activeSemesterFinalPartMarksHist in activeSemesterFinalPartMarksHists %}
<img src="data:image/png;base64,{{activeSemesterFinalPartMarksHist}}">
<hr>
{% endfor %}
<img src="data:image/png;base64,{{meanFinalPartMarksPlot}}">
{% endblock body %}