Skip to content

Commit

Permalink
add download all first mark data to stats page
Browse files Browse the repository at this point in the history
  • Loading branch information
struan committed Oct 7, 2024
1 parent e074608 commit 1ce18ff
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
4 changes: 3 additions & 1 deletion crowdsourcer/management/commands/export_marks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions crowdsourcer/scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.db.models import Count, Max, OuterRef, Q, Subquery, Sum

from crowdsourcer.models import (
MarkingSession,
Option,
PublicAuthority,
Question,
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion crowdsourcer/templates/crowdsourcer/stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ <h1 class="mb-4">{{ page_title }}</h1>
<span class="me-3">Question scores and answers</span>
{% include 'crowdsourcer/includes/csv-badge.html' %}
</a>
<a class="list-group-item list-group-item-action d-flex align-items-center justify-content-between" href="{% session_url 'all_answers_csv' %}?stage=First Mark">
<span class="me-3">All First Mark answer data</span>
{% include 'crowdsourcer/includes/csv-badge.html' %}
</a>
<a class="list-group-item list-group-item-action d-flex align-items-center justify-content-between" href="{% session_url 'all_answers_csv' %}">
<span class="me-3">All answer data</span>
<span class="me-3">All Audit answer data</span>
{% include 'crowdsourcer/includes/csv-badge.html' %}
</a>
<a class="list-group-item list-group-item-action d-flex align-items-center justify-content-between" href="{% session_url 'select_council_for_history' %}">
Expand Down
9 changes: 8 additions & 1 deletion crowdsourcer/views/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 1ce18ff

Please sign in to comment.