Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor statistics calculation #203

Closed
lkeegan opened this issue Dec 11, 2024 · 0 comments · Fixed by #229
Closed

Refactor statistics calculation #203

lkeegan opened this issue Dec 11, 2024 · 0 comments · Fixed by #229

Comments

@lkeegan
Copy link
Member

lkeegan commented Dec 11, 2024

Currently it is done as part of the request if the statistics are out of date, which may result in an occasional very slow request.

It would be nicer to have this functionality as a separate function with an endpoint, that can run automatically e.g. once a week, and also be ran by an admin on demand from the admin interface.

see 271c75e for partial implementation

@lkeegan lkeegan added this to the Initial production version milestone Dec 12, 2024
lkeegan added a commit that referenced this issue Feb 28, 2025
- refactor statistics calculation
  - add `update_stats` function which updates milestones and milestone group statistics
    - optional `incremental` argument
      - if `True`, then statistics updated with any new answers since last calculation (as before)
      - if `False`, then recalculates all statistics using all answers (may be needed if e.g. some junk answers are deleted by an admin)
  - add apscheduler to schedule regular calls of this function (based on 271c75e)
    - add `STATS_CRONTAB` to app settings to allow the schedule to be set, with a default crontab of 3am every monday
  - add fastapi_injectable to allow use of fastapi dependencies outside of fastapi routes
  - reduce duplication
  - resolves #203
- `AnswerSession`
  - add `expired` flag: initially False
    - set to True by `get_or_create_current_milestone_answer_session` if it was created 7 or more days ago
    - set to True when stats are updated if it was created 9 days or more ago
      - includes a grace period to avoid setting a currently in use answer session to expired
    - once an answer session is expired, then answers can no longer be modified / submitted by the user
      - this should ensure that answers cannot be modified after they have been included in the statistics
    - resolves #219
  - add `included_in_statistics` flag: initially False
    - set to True once the answers from this session are included in the statistics
- `MilestoneAnswer`
  - remove `included_in_milestone_statistics` and `included_in_milestonegroup_statistics` flags
    - this is now done at the level of an answer session rather than for each individual answer
- milestone feedback functions
  - insert a `TrafficLight.invalid.value` instead of raising an exception if there are no statistics for a milestone id or group
  - no longer recalculate stats when constructing feedback to avoid slowing down a user request in this case
@MaHaWo MaHaWo closed this as completed in 8b8d07e Mar 4, 2025
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 a pull request may close this issue.

1 participant