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

add expired flag to MilestoneAnswerSession #219

Closed
lkeegan opened this issue Jan 9, 2025 · 0 comments · Fixed by #229
Closed

add expired flag to MilestoneAnswerSession #219

lkeegan opened this issue Jan 9, 2025 · 0 comments · Fixed by #229
Labels
backend enhancement New feature or request

Comments

@lkeegan
Copy link
Member

lkeegan commented Jan 9, 2025

See #204

Currently:

  • get_current_milestone_answer_session checks if the current session is expired, if so creates a new one
  • update_milestone_answer always accepts an answer, i.e. doesn't check if answer session has expired
  • when the stats are updated they identify if a session is expired based on how long since it was created

This may lead to inconsistent/wrong stats, e.g. if an answer is changed after it was included in the stats.

Todo:

Add an expired flag to MilestoneAnswerSession

  • get_current_milestone_answer_session now sets this expired flag if the current one is expired
  • update_milestone_answer still always accepts answers (would be a poor user experience to reject an answer from a session that was valid when they started their current session if it expired while they were filling in the answers)
  • stats only include answers from expired answer sessions, no longer need to filter based on age of answer session
@lkeegan lkeegan added enhancement New feature or request backend labels Jan 9, 2025
lkeegan added a commit that referenced this issue Feb 24, 2025
- refactor statistics calculation
  - add `update_stats` function which updates milestones and milestone group statistics
    - optional `update_existing_statistics` argument
      - if `True`, then statistics updated using new answers 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)
  - reduce duplication
- `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
- add `/update-milestone-age-scores` admin endpoint to recalculate the statistics
  - TODO: add tests, add button(s) to admin interface?
  - TODO: add scheduled calling of this function
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 `update_existing_statistics` argument
      - if `True`, then statistics updated using new answers 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)
  - reduce duplication
- `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
- add `/update-milestone-age-scores` admin endpoint to recalculate the statistics
  - TODO: add tests, add button(s) to admin interface?
  - TODO: add scheduled calling of this function
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
backend enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant