Commit b902766
authored
Implement Server-Side Calorie Estimation and Display (#1531)
* feat: Implement server-side calorie estimation and display
This commit introduces a new feature to calculate and display real-time calorie expenditure based on user heart rate and age.
Key changes include:
- **Server-Side Calculation:** Added stateful calorie accumulation logic to `utils/socketManager.ts`. The calculation runs on the server to ensure consistency and uses a standard metabolic formula with default weight and age values.
- **Updated Data Structures:** Added a `calories` field to the `HrmData` interface in `types/websocket.ts` and `types/index.ts`.
- **UI Integration:** Modified the `HrTile.tsx` component to display the new calorie data (KCAL) alongside the BPM. The parent `HrmTiles.tsx` component now passes the `calories` prop.
- **Bug Fix:** Corrected a bug in the `WebSocketContext.tsx` reducer where a calorie value of `0` was being improperly handled, preventing the UI from resetting correctly. Also added a default `calories` prop to the `HrTile` component to prevent `NaN` from being displayed.
* feat: implement server-side calorie estimation
Implements server-side calorie estimation based on heart rate and age.
- Adds a `calories` field to the `HrmData` interface.
- Defines metabolic constants for calorie calculation.
- Implements `calculateCalories` logic in `utils/socketManager.ts`.
- Updates the `HrTile` component to display the accumulated calories.
- Fixes a bug in the WebSocket context reducer that was dropping the calories field.
- Addresses all PR feedback, including linting, styling, and type safety improvements.
* fix: resolve build failure by making calories prop optional
The previous commit introduced a build failure because the `HrTile` component was used in `app/client/connect/ConnectView.tsx` without the newly required `calories` prop.
This commit resolves the issue by making the `calories` prop optional in the `HrTileProps` interface. The component already provides a default value of 0, so this change is safe and prevents build failures in places where the calorie data is not relevant.
* chore: update visual regression snapshots
Updates the visual regression snapshots to match the UI changes introduced by the new calorie estimation feature. The `HrTile` component now displays the calorie count, which required updating the corresponding snapshot.
* chore: finalize calorie estimation feature
This marks the completion of the server-side calorie estimation feature.
- Implemented calorie calculation logic on the server.
- Updated frontend components to display calories.
- Fixed build errors and client-side state management bugs.
- Updated visual regression snapshots to reflect UI changes.
- All pull request feedback has been addressed.
---------
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>1 parent de84a93 commit b902766
8 files changed
Lines changed: 132 additions & 110 deletions
File tree
- components
- context
- tests/playwright/visual-regression.spec.ts-snapshots
- types
- utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | | - | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
113 | 114 | | |
114 | 115 | | |
115 | 116 | | |
116 | | - | |
117 | | - | |
118 | | - | |
| 117 | + | |
119 | 118 | | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
124 | 123 | | |
125 | 124 | | |
126 | | - | |
127 | | - | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
128 | 149 | | |
129 | 150 | | |
130 | 151 | | |
| |||
154 | 175 | | |
155 | 176 | | |
156 | 177 | | |
| 178 | + | |
157 | 179 | | |
158 | 180 | | |
159 | 181 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
114 | 113 | | |
115 | 114 | | |
116 | 115 | | |
117 | 116 | | |
118 | | - | |
119 | | - | |
120 | 117 | | |
121 | | - | |
122 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
123 | 124 | | |
124 | | - | |
125 | | - | |
126 | 125 | | |
127 | 126 | | |
128 | 127 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
0 commit comments