2.1 KiB
2.1 KiB
Plan: Add Median Statistic to Wakeup and Bedtime Plots
Overview
The goal is to add a fourth statistic, "Median", to the summary section below the Wakeup and Bedtime trend graphs in WakeupPlot.tsx and BedtimePlot.tsx. Currently, these components display "Earliest", "Latest", and "Average".
Detailed Tasks
1. Update frontend/src/components/stats/WakeupPlot.tsx
- Sub-task 1.1: Update Statistics Calculation
- Locate the
statsuseMemoblock. - Calculate the median of
validMinutes.- Note: To calculate the median, sort the array and pick the middle element (or average of two middle elements if even).
- Include
medianin the returned object:{ min, max, avg, median }.
- Locate the
- Sub-task 1.2: Update UI Layout
- Find the statistics container div (currently
grid grid-cols-3). - Change the Tailwind class from
grid-cols-3togrid-cols-4.
- Find the statistics container div (currently
- Sub-task 1.3: Add Median Display
- Add a new
divfor the "Median" statistic. - Use identical styling to the existing three blocks.
- Display the value using
formatMinutesAfter(Math.round(stats.median), wakeup_ref).
- Add a new
2. Update frontend/src/components/stats/BedtimePlot.tsx
- Sub-task 2.1: Update Statistics Calculation
- Locate the
statsuseMemoblock. - Calculate the median of
validMinutes. - Include
medianin the returned object:{ min, max, avg, median }.
- Locate the
- Sub-task 2.2: Update UI Layout
- Find the statistics container div (currently
grid grid-cols-3). - Change the Tailwind class from
grid-cols-3togrid-cols-4.
- Find the statistics container div (currently
- Sub-task 2.3: Add Median Display
- Add a new
divfor the "Median" statistic. - Use identical styling to the existing three blocks.
- Display the value using
formatMinutesAfter(Math.round(stats.median), bedtime_ref).
- Add a new
Verification Plan
- Visual Inspection: Ensure the four statistics are evenly spaced and aligned in a single row below each graph.
- Logic Check: Manually verify with a small set of known numbers (e.g., [10, 20, 30] -> median 20; [10, 20, 30, 40] -> median 25) that the calculation is correct.