From 1ce18ffb88104088983a63b243cd8aba5cd5b11a Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 7 Oct 2024 16:31:34 +0100 Subject: [PATCH] add download all first mark data to stats page --- crowdsourcer/management/commands/export_marks.py | 4 +++- crowdsourcer/scoring.py | 8 ++++++-- crowdsourcer/templates/crowdsourcer/stats.html | 6 +++++- crowdsourcer/views/stats.py | 9 ++++++++- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/crowdsourcer/management/commands/export_marks.py b/crowdsourcer/management/commands/export_marks.py index caa549ac..264b2c30 100644 --- a/crowdsourcer/management/commands/export_marks.py +++ b/crowdsourcer/management/commands/export_marks.py @@ -141,7 +141,9 @@ def handle( answer_data = None if output_answers or questions_only: if not questions_only: - answer_data = get_all_question_data(scoring) + answer_data = get_all_question_data( + scoring, marking_session=session.label + ) questions = ( Question.objects.filter(section__marking_session=session) diff --git a/crowdsourcer/scoring.py b/crowdsourcer/scoring.py index 2cea35a7..89443875 100644 --- a/crowdsourcer/scoring.py +++ b/crowdsourcer/scoring.py @@ -4,6 +4,7 @@ from django.db.models import Count, Max, OuterRef, Q, Subquery, Sum from crowdsourcer.models import ( + MarkingSession, Option, PublicAuthority, Question, @@ -707,10 +708,13 @@ def get_response_data( return data -def get_all_question_data(scoring, response_type="Audit"): +def get_all_question_data(scoring, marking_session=None, response_type="Audit"): rt = ResponseType.objects.get(type=response_type) + session = MarkingSession.objects.get(label=marking_session) responses = ( - Response.objects.filter(response_type=rt) + Response.objects.filter( + response_type=rt, question__section__marking_session=session + ) .annotate(multi_count=Count("multi_option__pk")) .order_by( "authority__name", diff --git a/crowdsourcer/templates/crowdsourcer/stats.html b/crowdsourcer/templates/crowdsourcer/stats.html index 0508e2c9..f70ebe0e 100644 --- a/crowdsourcer/templates/crowdsourcer/stats.html +++ b/crowdsourcer/templates/crowdsourcer/stats.html @@ -46,8 +46,12 @@

{{ page_title }}

Question scores and answers {% include 'crowdsourcer/includes/csv-badge.html' %} + + All First Mark answer data + {% include 'crowdsourcer/includes/csv-badge.html' %} + - All answer data + All Audit answer data {% include 'crowdsourcer/includes/csv-badge.html' %} diff --git a/crowdsourcer/views/stats.py b/crowdsourcer/views/stats.py index cff21d60..7372c14c 100644 --- a/crowdsourcer/views/stats.py +++ b/crowdsourcer/views/stats.py @@ -380,8 +380,15 @@ class AllAnswerDataView(BaseScoresView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) + args = {} + if self.request.GET.get("stage"): + args["response_type"] = self.request.GET["stage"] + self.file_name = f"all_answer_data_{slugify(args['response_type'])}.csv" + self.get_scores() - context["rows"] = get_all_question_data(self.scoring) + context["rows"] = get_all_question_data( + self.scoring, marking_session=self.request.current_session.label, **args + ) return context