Skip to content

Conversation

Copy link

Copilot AI commented Dec 13, 2025

The counts tables track usage metrics (submissions, runs, errors, edit times) but weren't being populated. Performance requires instant statistics computation without aggregating historical logs.

Changes

Model Relationships

  • Added one-to-one relationships: Submission.submission_counts, Assignment.counts, Course.counts, User.user_counts

Tracking Helpers (models/counters/helpers.py)

  • Welford's algorithm for running averages: new_avg = old_avg + (new_value - old_avg) / count
  • Update functions: update_run_count(), update_error_counts(), increment_submission_count(), update_user_activity()
  • Backfill function: recalculate_submission_counts_from_logs() for existing data

Integration Points

  • Submission.from_assignment() - increment submission counts across assignment/course/user
  • save_student_file() - update user edit timestamp
  • log_event() - track runs and error types (syntax/runtime/instructor test)
  • Assignment.new() - increment course assignment count
  • User.add_role(), User.update_roles() - track course enrollment by role
  • handle_login_change() - update last login timestamp

Usage

from models.counters.helpers import ensure_submission_counts

counts = ensure_submission_counts(submission_id)
# Instant access: counts.runs, counts.average_edit_time, counts.syntax_errors

Metrics are updated incrementally in O(1) time. The recalculation function uses ILIKE queries suitable for one-time backfilling but not real-time use.

Original prompt

The counts tables of the models are for keeping track of usage data on submissions, assignments, etc. With these, we'll be able to track statistics and compute them instantly, with running sums, averages, standard deviations, etc. the math on these is a little tricky, but will be critical for performance issues. For example, whenever a student makes an edit, we need to update the average edit time. All of these metrics need to be tracked across the relevant endpoints.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 5 commits December 13, 2025 16:52
…istics

Co-authored-by: acbart <897227+acbart@users.noreply.github.com>
Co-authored-by: acbart <897227+acbart@users.noreply.github.com>
Co-authored-by: acbart <897227+acbart@users.noreply.github.com>
Co-authored-by: acbart <897227+acbart@users.noreply.github.com>
Co-authored-by: acbart <897227+acbart@users.noreply.github.com>
Copilot AI changed the title [WIP] Add counts tables for usage data tracking Implement real-time counts tracking with running statistics Dec 13, 2025
Copilot AI requested a review from acbart December 13, 2025 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants