1.8 KiB
1.8 KiB
Investigation Plan: Bedtime Graph Issue
Objective
Investigate why the "Bedtime" graph shows unexpected times when a specific bedtime_ref is set.
Current Understanding
- The
BedtimePlot.tsxcomponent displays a graph where the Y-axis (or values) are formatted usingformatMinutesAfter(value, bedtime_ref). - The data comes from the
/api/stats/wake-sleep-timesendpoint. - The backend calculates
bedtime_minutesbased on sessions that started on or before thebedtime_ref.
Investigation Steps
Step 1: Analyze Backend Logic
- Examine
get_wake_sleep_timesinbackend/app/routers/stats.pyto understand howbedtime_minutesis calculated. - Verify if the logic correctly identifies "bedtime" for various sleep session scenarios (e.g., sessions crossing midnight).
- Identify potential edge cases where the
s.start_time.time() <= b_ref_timecondition might be problematic.
Step 2: Analyze Frontend Logic
- Examine
BedtimePlot.tsxanduseStats.tsto see how the data is consumed and formatted. - Understand how
formatMinutesAfterinteracts with the values returned by the backend.
Step 3: Data Simulation & Verification
- Create a set of test cases (mocked data) representing different sleep scenarios.
- Manually calculate the expected
bedtime_minutesfor these scenarios using the current logic. - Compare with what the user reported to confirm the bug's nature.
Step 4: Propose and Implement Fixes
- Refine the backend logic to better represent "bedtime" if current logic is insufficient.
- Ensure the frontend correctly displays the intended time.
- Verify that changes do not break other parts of the stats page (e.g., Wakeup times).
Future Tasks
- Run tests to ensure correctness after implementation.
- Finalize documentation/explanation of the fix.