Read students per-row Average Grade from HPPS - #8205
Conversation
934a787 to
5dda72a
Compare
cfb4e51 to
0947142
Compare
5dda72a to
4ed73c2
Compare
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Rides the existing grade join with GROUP BY user_id so per-row average grade can be primed once per page, instead of one query per user. Implemented in both the tables-based and comments-based services, with tests pinning parity between them (auto-passed lessons without a real quiz attempt are excluded in both). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Extend prime_row_aggregates() in the students overview list table to also fetch per-user grade totals via Grading_Stats_Service_Interface, and have get_row_data() read from that primed cache instead of running per-row Sensei_Utils::sensei_check_for_activity / Sensei_Grading::get_user_graded_lessons_sum calls. Deprecate the now-unused sensei_analysis_user_lesson_grades filter. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
0947142 to
7de7213
Compare
|
@merkushin Here's an HPPS one if you'd like a break from WPML. 😂 Note that I'll probably have to merge and not necessarily wait for reviews so I can maintain some momentum, but I'll circle back to any feedback you might leave. |
There was a problem hiding this comment.
🟡 Changes recommended
CSV export fetches all students at once, so the new per-user averages query path should be hardened (e.g., chunking) to avoid excessively large IN (...) queries on large sites.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Updates Reports → Overview → Students so the per-row Average Grade value is fetched in bulk via the grading stats service (HPPS-aware), avoiding per-row grade queries and improving correctness for fractional grades.
Changes:
- Add
get_average_grades_by_user()to the grading stats service interface and both comments-based and tables-based implementations. - Prime a per-page per-user average-grade cache in the Students list table (also reused for CSV export rows).
- Add unit tests covering per-user averages (including fractional grades and no-grade users) and add changelog entries, including deprecation notice for
sensei_analysis_user_lesson_grades.
File summaries
| File | Description |
|---|---|
| tests/unit-tests/reports/overview/services/test-class-sensei-reports-overview-service-students.php | Adds unit coverage for per-user average grade rounding and defaulting to 0. |
| tests/unit-tests/internal/services/test-class-tables-based-grading-stats-service.php | Updates test helpers for float grades and adds tests for HPPS per-user averages and edge cases. |
| tests/unit-tests/internal/services/test-class-comments-based-grading-stats-service.php | Updates test helpers for float grades and adds tests for legacy per-user averages and edge cases. |
| includes/reports/overview/services/class-sensei-reports-overview-service-students.php | Adds a service-layer API to fetch per-user averages and normalize output for the list table/CSV. |
| includes/reports/overview/list-table/class-sensei-reports-overview-list-table-students.php | Primes per-page per-user average grades and removes per-row grade total/count queries + filter usage. |
| includes/internal/services/class-tables-based-grading-stats-service.php | Implements per-user average grade query against HPPS progress + submissions tables. |
| includes/internal/services/class-grading-stats-service-interface.php | Extends the interface with get_average_grades_by_user(). |
| includes/internal/services/class-comments-based-grading-stats-service.php | Implements per-user average grade query using the legacy comments/meta model and refactors shared SQL. |
| changelog/fix-reports-overview-students-average-grade-hpps | Documents the HPPS-aware per-row Average Grade behavior change. |
| changelog/deprecate-analysis-user-lesson-grades-filter | Documents the deprecation of sensei_analysis_user_lesson_grades. |
Review details
- Files reviewed: 10/10 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
@donnapep haha, blazing fast 😅 |
SEN-83: HPPS: Reports Overview aggregates → table-aware
Part of the Reports → Overview HPPS effort.
Proposed Changes
Notes
Per-student average grades with fractional values can differ slightly from
trunk. This is expected:trunktruncates the decimal portion of the total grade before calculating the average, while this PR preserves it. The values produced by this PR are therefore more accurate.Testing Instructions
Use an existing site with progress synchronized between comments and the HPPS tables. The data should include at least one student with fractional grades and one student without any grades.
trunk, open Reports → Overview → Students with HPPS off. Record each student's Average Grade, then export the CSV and record the corresponding values. This is the baseline;trunkdoes not need to be checked with HPPS on because this per-row value always reads comment-based data there.trunkbaseline, accounting for the expected precision differences described above. Confirm that students without grades still show0%.Deprecated Code
This per-row filter no longer runs. No replacement:
sensei_analysis_user_lesson_grades