From 6d281dfe3ace0b140676d862b274bf07e690bd5b Mon Sep 17 00:00:00 2001 From: Mo8it Date: Tue, 12 Apr 2022 13:29:08 +0200 Subject: [PATCH] Add number, mean and all --- advlabdb/adminModelViews.py | 39 ++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/advlabdb/adminModelViews.py b/advlabdb/adminModelViews.py index 6475150..3824805 100644 --- a/advlabdb/adminModelViews.py +++ b/advlabdb/adminModelViews.py @@ -1041,8 +1041,8 @@ def groupExperimentQueryFactory(): def assistantFilterOptions(): - assistants = Assistant.query.filter(Assistant.user.has(User.active == True)) - return tuple((assistant.id, assistant.repr()) for assistant in assistants) + activeAssistants = assistantQueryFactory() + return tuple((assistant.id, assistant.repr()) for assistant in activeAssistants) class AppointmentView(SecureAdminModelView): @@ -1444,20 +1444,25 @@ class AnalysisView(SecureAdminBaseView): def markHist(data, title): fig = Figure() ax = fig.subplots() - ax.set_title(title) ax.set_xlim(MIN_MARK - 0.5, MAX_MARK + 0.5) ax.set_xticks(np.arange(MAX_MARK + 1)) ax.set_xlabel("Mark") - if data: + N = data.size + title += f"\nN = {N}" + + if N > 0: hist = ax.hist( data, bins=np.arange(MAX_MARK) - 0.5, ) - ax.set_yticks(np.arange(len(data) + 1)) + ax.set_yticks(np.arange(N + 1)) + title += f" | mean = {round(np.mean(data), 1)}" else: ax.set_yticks(np.arange(2)) + ax.set_title(title) + buf = BytesIO() fig.savefig(buf, format="png") @@ -1465,21 +1470,37 @@ class AnalysisView(SecureAdminBaseView): def markHists(markType, activeAssistants): attr = markType.lower() + "_mark" - return [ + markTypeTitleAddition = f" | {markType} marks" + + hists = [ AnalysisView.markHist( - data=[getattr(experimentMark, attr) for experimentMark in assistant.experiment_marks], - title=f"{assistant.repr()} - {markType} Marks", + data=np.array([getattr(experimentMark, attr) for experimentMark in assistant.experiment_marks]), + title=assistant.repr() + markTypeTitleAddition, ) for assistant in activeAssistants ] + hists.append( + AnalysisView.markHist( + data=np.hstack( + [ + [getattr(experimentMark, attr) for experimentMark in assistant.experiment_marks] + for assistant in activeAssistants + ] + ), + title="All" + markTypeTitleAddition, + ) + ) + + return hists + @expose(methods=("GET", "POST")) def index(self): form = AnalysisView.AnalysisForm() if form.validate_on_submit(): if form.assistantMarksSubmit.data: - activeAssistants = Assistant.query.filter(Assistant.user.has(User.active == True)) + activeAssistants = assistantQueryFactory() oralMarkHists = AnalysisView.markHists("Oral", activeAssistants) protocolMarkHists = AnalysisView.markHists("Protocol", activeAssistants)