Skip to content

fix(health-data): apply default units for HealthConnect sync (fixes #567) - #621

Merged
CodeWithCJ merged 5 commits into
CodeWithCJ:mainfrom
JosephDoUrden:fix/health-data
Feb 8, 2026
Merged

CodeWithCJ merged 5 commits into
CodeWithCJ:mainfrom
JosephDoUrden:fix/health-data

Conversation

@JosephDoUrden

Copy link
Copy Markdown
Contributor

Summary

Fixes #567: HealthConnect (and other client) sync was creating custom measurement categories with measurement_type = 'N/A' because the backend did not use the unit field from the payload and had no defaults. The web UI then showed "N/A" for those metrics and graphs were wrong.

Changes

  • Backend: In processHealthData, when handling scalar health data as custom measurements, the category's measurement_type is now taken from dataEntry.unit (or dataEntry.measurementType) when present; otherwise a default is applied from a new DEFAULT_UNITS_BY_HEALTH_TYPE map (e.g. heart_rate → bpm, TotalCaloriesBurned → kcal, distance → m), aligned with the mobile HealthMetrics.
  • Tests: Added measurementService.healthDataUnits.test.js to assert default units when unit is missing and that payload unit is used when provided.

Testing

  • npx jest tests/measurementService.healthDataUnits.test.js (with SPARKY_FITNESS_API_ENCRYPTION_KEY set) — 4 tests pass.
  • Manual: sync HealthConnect data for heart rate / calories / distance and confirm the web UI shows correct units instead of N/A.

Notes

  • Existing categories that were already created with measurement_type = 'N/A' are unchanged; users can edit the category in Settings to set the unit, or re-sync after deleting those entries if desired. New syncs will get the correct default.

…es not show N/A (CodeWithCJ#567)

- Use payload unit when present, else resolve from DEFAULT_UNITS_BY_HEALTH_TYPE
- Ensures custom measurement categories get a proper measurement_type for heart rate, calories, distance, sleep, etc.
- Add tests for default and payload unit behavior
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @JosephDoUrden, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue where health data synced from clients, particularly HealthConnect, would display 'N/A' for units in the web UI and generate incorrect graphs due to the backend not properly handling or defaulting measurement units. The changes introduce a robust system to intelligently assign units, either by utilizing those provided in the incoming data or by applying predefined defaults for common health metrics, thereby ensuring data integrity and accurate visualization.

Highlights

  • Default Unit Application: Implemented a 'DEFAULT_UNITS_BY_HEALTH_TYPE' map to automatically assign appropriate units (e.g., 'bpm' for heart rate, 'kcal' for calories) to health data entries when the client (like HealthConnect) does not provide them.
  • Improved Unit Resolution: The 'processHealthData' function now prioritizes units provided in the incoming data payload ('dataEntry.unit' or 'dataEntry.measurementType') and falls back to the new default map if no unit is specified, preventing 'N/A' values in the UI.
  • Comprehensive Unit Testing: A new test file, 'measurementService.healthDataUnits.test.js', has been added to ensure the correct application of both provided and default units for various health metrics, confirming the fix for issue [Bug]: HealthConnect Default Units #567.
Changelog
  • SparkyFitnessServer/package-lock.json
    • Updated package version from '0.16.3.7' to '0.16.4.1'.
    • Added several new development dependencies related to ESLint (e.g., '@eslint/js', 'eslint', 'eslint-plugin-n', 'eslint-plugin-security', 'globals') and other build/tooling utilities.
    • Adjusted 'peer' and 'optional' flags for various dependencies, and removed some nested 'ansi-styles' and 'chalk' entries, likely due to dependency resolution optimizations.
  • SparkyFitnessServer/services/measurementService.js
    • Introduced 'DEFAULT_UNITS_BY_HEALTH_TYPE', a new constant map defining default units for a wide range of health metric types.
    • Modified the 'processHealthData' function to first check for 'dataEntry.unit' or 'dataEntry.measurementType' for custom measurements. If neither is present or valid, it now uses the 'DEFAULT_UNITS_BY_HEALTH_TYPE' map to determine the 'measurement_type' for new custom categories.
  • SparkyFitnessServer/tests/measurementService.healthDataUnits.test.js
    • Added a new test file dedicated to verifying the unit handling logic in 'measurementService.processHealthData'.
    • Includes test cases to confirm that default units are correctly applied when the payload lacks unit information (e.g., heart rate, total calories burned, distance).
    • Also includes a test case to ensure that explicitly provided units in the payload are correctly used, overriding any defaults.
Activity
  • The pull request introduces a critical bug fix for health data unit handling, complete with a detailed problem summary, proposed changes, and thorough testing instructions.
  • The author has also provided important notes regarding the impact on existing data, demonstrating a comprehensive approach to the change.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses the issue of missing units for health data from clients like HealthConnect by introducing a default unit mapping. This is a solid improvement that will enhance the user experience by preventing "N/A" units in the UI. The changes are well-contained, and the addition of new tests is commendable. I have a few suggestions to improve consistency in the new unit map and enhance code readability.

JosephDoUrden and others added 4 commits February 8, 2026 15:25
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@CodeWithCJ
CodeWithCJ merged commit 69e1fbf into CodeWithCJ:main Feb 8, 2026
1 check passed
@JosephDoUrden
JosephDoUrden deleted the fix/health-data branch February 8, 2026 13:20
@JosephDoUrden

Copy link
Copy Markdown
Contributor Author

Thanks, happy to take another issue @CodeWithCJ

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.

[Bug]: HealthConnect Default Units

2 participants