Skip to content

Fix: store reading and exercise session durations in seconds (not ms)#512

Open
mircealungu wants to merge 1 commit intomasterfrom
auto-fix/issue-107
Open

Fix: store reading and exercise session durations in seconds (not ms)#512
mircealungu wants to merge 1 commit intomasterfrom
auto-fix/issue-107

Conversation

@mircealungu
Copy link
Copy Markdown
Member

Summary

Closes #107

The frontend timer counts in seconds but was multiplying by 1000 before sending to the API, which stored and returned milliseconds. This required the frontend to divide by 1000 again on display — needless complexity.

This PR (together with zeeguu/web#auto-fix/issue-107) removes that round-trip conversion.

Changes (this commit: the core fix)

  • user_reading_session.py / user_exercise_session.py: update duration column comment from "milliseconds" → "seconds"; fix UserExerciseSession.__init__ to use total_seconds() without * 1000
  • user_stats.py: update all / 60000/ 60 for reading and exercise sessions; rename duration_msduration_sec in those functions; fix variable names exercise_ms / reading_msexercise_sec / reading_sec
  • session_history.py: format_duration and _calculate_focus_level now expect seconds; browsing and listening sessions (still stored in ms) are normalized to seconds before inclusion in the response, so the API returns a consistent unit across all session types
  • macro_reading_session.py: remove / 1000 when accumulating session durations
  • activity.py: remove / 1000 from SQL query since durations are now seconds

Note: Browsing and listening sessions still store milliseconds; only reading and exercise sessions are changed as specified in the issue.

Database migration

No schema change needed — the duration column type stays INTEGER. The stored values will simply represent seconds instead of milliseconds going forward. Historical data (stored in ms) will show inflated times until manually migrated, but new sessions will be correct.


To discuss this fix, find this session at https://claude.ai/code

…of ms

Closes #107

The frontend timer counts in seconds but was converting to milliseconds
before sending to the API, which then stored and returned milliseconds.
This required the frontend to convert back on display.

Changes:
- Update duration column comments in UserReadingSession and UserExerciseSession
- Fix UserExerciseSession.__init__ to store seconds (remove * 1000)
- Update all / 60000 calculations to / 60 for reading/exercise sessions
- Rename duration_ms → duration_sec in stats functions for reading/exercise
- Update session_history endpoint: format_duration and _calculate_focus_level
  now expect seconds; browsing/listening durations (still stored in ms) are
  normalized to seconds before being included in the response
- Update macro_reading_session.py to treat duration as seconds
- Update activity.py SQL query: remove / 1000 since durations are now seconds

Note: browsing and listening sessions still store milliseconds; only
reading and exercise sessions are changed as specified in the issue.
@github-actions
Copy link
Copy Markdown

ArchLens - No architecturally relevant changes to the existing views

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.

change the reading session and exercise session so they store only seconds

2 participants