Skip to content

feat: add user quiz statistics endpoint with per-question breakdown#173

Open
Batirro wants to merge 7 commits intodevfrom
feat/163-feature-quiz-stats
Open

feat: add user quiz statistics endpoint with per-question breakdown#173
Batirro wants to merge 7 commits intodevfrom
feat/163-feature-quiz-stats

Conversation

@Batirro
Copy link
Copy Markdown
Member

@Batirro Batirro commented Mar 14, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 14, 2026 15:45
@Batirro Batirro requested a review from MoonPrincess06 as a code owner March 14, 2026 15:45
@Batirro Batirro linked an issue Mar 14, 2026 that may be closed by this pull request
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new DRF endpoint to return per-user quiz statistics (optionally with a per-question breakdown), implemented via a dedicated service function and covered by a new test module.

Changes:

  • Added GET /quizzes/{id}/stats action to QuizViewSet with include=per_question support.
  • Implemented aggregation logic in quizzes/services/stats.py (get_quiz_stats + per-question aggregation).
  • Added an extensive test suite for the new stats endpoint.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
quizzes/views.py Adds the stats viewset action, schema docs, and include parsing logic.
quizzes/services/stats.py Introduces aggregation queries for totals, accuracy, study time, and optional per-question breakdown.
quizzes/serializers.py Adds serializers for the stats response payload (QuizStatsSerializer, QuestionStatsSerializer).
quizzes/tests/test_quiz_stats.py Adds endpoint tests for empty stats, aggregation, per-question output, isolation, and permissions.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new authenticated quiz “stats” endpoint to expose per-user aggregated quiz performance metrics, with an optional per-question breakdown, fitting into the quizzes app’s DRF viewset + services structure.

Changes:

  • Added GET /quizzes/{id}/stats action on QuizViewSet, including include=per_question support.
  • Implemented stats aggregation in a dedicated service (quizzes/services/stats.py).
  • Added serializers and a comprehensive test suite for totals, study time, per-question breakdown, and permissions.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
quizzes/views.py Adds the stats viewset action, schema docs, and include parsing.
quizzes/services/stats.py Implements query-based aggregation for overall and per-question statistics.
quizzes/serializers.py Introduces QuizStatsSerializer and QuestionStatsSerializer for the endpoint response.
quizzes/tests/test_quiz_stats.py Adds endpoint tests covering aggregation logic, optional expansions, and access control.

Copilot AI review requested due to automatic review settings March 14, 2026 19:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new DRF action endpoint to return per-user quiz statistics (including optional per-question breakdown), implemented via a dedicated service and exposed with OpenAPI documentation, with a comprehensive test suite validating aggregation and permissions.

Changes:

  • Added GET /quizzes/{id}/stats/ action returning aggregated stats for the authenticated user, with ?include=per_question support.
  • Introduced quizzes/services/stats.py to compute aggregate + per-question statistics.
  • Added serializers and a full test module covering aggregation, include parsing, and permission behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
quizzes/views.py Adds stats action + shared include parsing helper and wires in service/serializer.
quizzes/services/stats.py Implements query-based aggregation for totals and per-question breakdown.
quizzes/serializers.py Adds QuizStatsSerializer and nested QuestionStatsSerializer for response shape.
quizzes/tests/test_quiz_stats.py Adds coverage for empty stats, aggregation, study time, include behavior, isolation, and permissions.

Copilot AI review requested due to automatic review settings March 17, 2026 10:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new /quizzes/{id}/stats endpoint to expose per-user quiz performance statistics (optionally with a per-question breakdown), aligning with existing include query-param patterns used across the quizzes API.

Changes:

  • Added stats action on QuizViewSet returning aggregated user statistics for a quiz, with ?include=per_question support.
  • Introduced a small stats service (get_quiz_stats) plus serializers to structure the response.
  • Centralized include parsing into parse_include_values() and added comprehensive endpoint tests.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
quizzes/views.py Adds GET /quizzes/{id}/stats action and refactors metadata include parsing to shared helper.
quizzes/utils.py New parse_include_values() helper supporting repeated and CSV include params.
quizzes/services/stats.py New service computing aggregated stats and optional per-question breakdown.
quizzes/serializers.py Adds QuizStatsSerializer and QuestionStatsSerializer for the endpoint response shape.
quizzes/tests/test_quiz_stats.py Adds test coverage for aggregation, permissions, study time rules, and include parsing variants.

Copy link
Copy Markdown
Collaborator

@MoonPrincess06 MoonPrincess06 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Copy Markdown
Member

@Antoni-Czaplicki Antoni-Czaplicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zerknij na issue na pm i upewnij sie ze wszystko jest jak w zamysle

Comment on lines +6 to +12
Zwraca zbiór wartości parametru query (domyślnie `include`), wspierając:
- powtarzane parametry: ?include=a&include=b
- wartości CSV: ?include=a,b

Przykład:
?include=questions,stats&include=owner
-> {"questions", "stats", "owner"}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

komentarze po angielsku pls

from quizzes.models import AnswerRecord, QuizSession


def get_quiz_stats(quiz, user, *, include_per_question: bool = False) -> dict:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

potrzebujemy rozdzielić i zwracać i ogólne i per user, spójrz tutaj co powinno być zwracane

Solvro/pm-testownik#28 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Statystyki quizu

4 participants