feat: add user quiz statistics endpoint with per-question breakdown#173
feat: add user quiz statistics endpoint with per-question breakdown#173
Conversation
There was a problem hiding this comment.
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}/statsaction toQuizViewSetwithinclude=per_questionsupport. - 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. |
There was a problem hiding this comment.
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}/statsaction onQuizViewSet, includinginclude=per_questionsupport. - 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. |
There was a problem hiding this comment.
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_questionsupport. - Introduced
quizzes/services/stats.pyto 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. |
There was a problem hiding this comment.
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
statsaction onQuizViewSetreturning aggregated user statistics for a quiz, with?include=per_questionsupport. - Introduced a small stats service (
get_quiz_stats) plus serializers to structure the response. - Centralized
includeparsing intoparse_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. |
Antoni-Czaplicki
left a comment
There was a problem hiding this comment.
zerknij na issue na pm i upewnij sie ze wszystko jest jak w zamysle
| 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"} |
There was a problem hiding this comment.
komentarze po angielsku pls
| from quizzes.models import AnswerRecord, QuizSession | ||
|
|
||
|
|
||
| def get_quiz_stats(quiz, user, *, include_per_question: bool = False) -> dict: |
There was a problem hiding this comment.
potrzebujemy rozdzielić i zwracać i ogólne i per user, spójrz tutaj co powinno być zwracane
No description provided.