Fix: store reading and exercise session durations in seconds (not ms)#512
Open
mircealungu wants to merge 1 commit intomasterfrom
Open
Fix: store reading and exercise session durations in seconds (not ms)#512mircealungu wants to merge 1 commit intomasterfrom
mircealungu wants to merge 1 commit intomasterfrom
Conversation
…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.
|
ArchLens - No architecturally relevant changes to the existing views |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: updatedurationcolumn comment from "milliseconds" → "seconds"; fixUserExerciseSession.__init__to usetotal_seconds()without* 1000user_stats.py: update all/ 60000→/ 60for reading and exercise sessions; renameduration_ms→duration_secin those functions; fix variable namesexercise_ms/reading_ms→exercise_sec/reading_secsession_history.py:format_durationand_calculate_focus_levelnow 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 typesmacro_reading_session.py: remove/ 1000when accumulating session durationsactivity.py: remove/ 1000from SQL query since durations are now secondsNote: 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
durationcolumn type staysINTEGER. 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