Skip to content

Read students per-row Average Grade from HPPS - #8205

Merged
donnapep merged 15 commits into
trunkfrom
hpps-reports-students-avg-grade
Sep 10, 2026
Merged

donnapep merged 15 commits into
trunkfrom
hpps-reports-students-avg-grade

Conversation

@donnapep

@donnapep donnapep commented Aug 25, 2026 •

Copy link
Copy Markdown
Member

SEN-83: HPPS: Reports Overview aggregates → table-aware

Part of the Reports → Overview HPPS effort.

Proposed Changes

  • Students tab, per-row Average Grade column: primed from the grading stats service (one batched query per page) instead of per-row activity/sum queries.

Notes

Per-student average grades with fractional values can differ slightly from trunk. This is expected: trunk truncates 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.

  • On 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; trunk does not need to be checked with HPPS on because this per-row value always reads comment-based data there.
  • Check out this PR with HPPS off. Compare the on-screen and exported Average Grade values with the trunk baseline, accounting for the expected precision differences described above. Confirm that students without grades still show 0%.
  • Keep this PR checked out and turn HPPS on, selecting the HPPS tables as the progress repository. Confirm the on-screen and exported Average Grade values match this PR with HPPS off.

Deprecated Code

This per-row filter no longer runs. No replacement:

  • sensei_analysis_user_lesson_grades

@donnapep donnapep added this to the 4.26.4 milestone Aug 25, 2026
@donnapep donnapep added the Deprecation This change introduces a deprecation. label Aug 25, 2026
@github-actions

github-actions Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

WordPress Playground Preview

The changes in this pull request can previewed and tested using a WordPress Playground instance.

Open WordPress Playground Preview

@donnapep
donnapep force-pushed the hpps-reports-students-course-counts branch from 934a787 to 5dda72a Compare August 25, 2026 15:26
@donnapep
donnapep force-pushed the hpps-reports-students-avg-grade branch from cfb4e51 to 0947142 Compare August 25, 2026 15:26
@donnapep
donnapep force-pushed the hpps-reports-students-course-counts branch from 5dda72a to 4ed73c2 Compare August 25, 2026 19:09
Base automatically changed from hpps-reports-students-course-counts to trunk August 26, 2026 18:29
@donnapep donnapep self-assigned this Aug 26, 2026
donnapep and others added 3 commits September 9, 2026 11:08
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>
@donnapep
donnapep force-pushed the hpps-reports-students-avg-grade branch from 0947142 to 7de7213 Compare September 9, 2026 15:13
@donnapep
donnapep marked this pull request as ready for review September 10, 2026 13:02
Copilot AI lite review requested due to automatic review settings September 10, 2026 13:02
@donnapep

Copy link
Copy Markdown
Member Author

@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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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
donnapep merged commit cc7fa3d into trunk Sep 10, 2026
21 checks passed
@donnapep
donnapep deleted the hpps-reports-students-avg-grade branch September 10, 2026 15:12
@merkushin

Copy link
Copy Markdown
Contributor

@donnapep haha, blazing fast 😅

@donnapep donnapep added the HPPS label Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Deprecation This change introduces a deprecation. HPPS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants