diff --git a/crowdsourcer/management/commands/export_marks.py b/crowdsourcer/management/commands/export_marks.py index caa549a..264b2c3 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 2cea35a..8944387 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 0508e2c..f70ebe0 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 cff21d6..7372c14 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