Add an option to list daily summary
Hi, matin, I have added an option to pull daily summary for a user as I believe it is nice to have simple overview available directly.
I wasn't sure if it belongs in data or stats, but given the format of the request, I have chosen the data directory as the best possible place.
Please, let me know if there is anything else that needs to be done.
Summary by CodeRabbit
-
New Features
- Added a daily health summary feature delivering comprehensive daily metrics (calories, steps, heart rate, stress, activity, sleep, SpO2, respiration, etc.).
-
Tests
- Added tests to validate fetching and listing daily summaries for specific dates and ranges.
-
Documentation
- Added README section with usage examples and sample outputs for retrieving daily summaries.
Walkthrough
Adds a new Pydantic dataclass DailySummary representing daily health metrics with a classmethod to fetch data from the API, exposes it via package exports, adds tests for fetching/listing daily summaries, and documents usage in the README.
Changes
| Cohort / File(s) | Change Summary |
|---|---|
New data modelsrc/garth/data/daily_summary.py |
Added DailySummary dataclass with many optional health metric fields and a `get(day, *, client=None) -> Self |
Data package exportssrc/garth/data/__init__.py |
Imported DailySummary from .daily_summary and added it to __all__. |
Top-level package exportssrc/garth/__init__.py |
Imported DailySummary and added it to the package __all__. |
Teststests/data/test_daily_summary.py |
Added tests test_daily_summary_get and test_daily_summary_list using VCR'd HTTP interactions and an authed_client fixture. |
DocsREADME.md |
Added "Daily Summary" documentation with usage examples and sample output showing the DailySummary fields. |
Sequence Diagram(s)
sequenceDiagram
participant User
participant DailySummary
participant httpClient as http.Client
participant API
User->>DailySummary: DailySummary.get(day, client?)
alt no client provided
DailySummary->>httpClient: http.Client() (default)
end
DailySummary->>httpClient: connectapi("/wellness/dailySummary?calendarDate=day")
httpClient->>API: GET /wellness/dailySummary?calendarDate=day
API-->>httpClient: JSON response (camelCase keys)
httpClient-->>DailySummary: response dict
DailySummary->>DailySummary: camel_to_snake_dict -> validate -> instantiate
DailySummary-->>User: DailySummary instance or None
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested reviewers
- matin
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
🧪 Generate unit tests
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
-
I pushed a fix in commit <commit_id>, please review it. -
Open a follow-up GitHub issue for this discussion.
-
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. - PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:-
@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase. -
@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
-
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
CodeRabbit Commands (Invoked using PR/Issue comments)
Type @coderabbitai help to get the list of available commands.
Other keywords and placeholders
- Add
@coderabbitai ignoreor@coderabbit ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
Status, Documentation and Community
- Visit our Status Page to check the current availability of CodeRabbit.
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
@vactomas this is a good feature to add. ci is failing. could you check the tests?
I see the problem, I have not generated VCR cassettes. I have a question, do I just run the tests against my account or is there some other way?
I have locally temporarily set vcr record_mode to once, but it fails with 401 not authorized error on the tests I ran. I presume this is due to the sanitized tokens in conftest.py.
you have to log in, save your tokens and set the GARTH_HOME env bar.
to generate the cassettes, this'll let you generate the tests against your account. all sensitive info should be masked, but i recommend double checking to cassettes before committing them
I see, thanks. I have some trouble getting it to work, but I'll again later. Hopefully, I can get it to cooperate and get the cassettes ready
I have managed to get these cassettes to work locally. Hopefully, it will work even in CI
Codecov Report
:x: Patch coverage is 98.50746% with 1 line in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 99.94%. Comparing base (4b027e1) to head (4cb66bf).
| Files with missing lines | Patch % | Lines |
|---|---|---|
| src/garth/data/daily_summary.py | 97.95% | 1 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #132 +/- ##
===========================================
- Coverage 100.00% 99.94% -0.06%
===========================================
Files 45 47 +2
Lines 1898 1965 +67
===========================================
+ Hits 1898 1964 +66
- Misses 0 1 +1
| Flag | Coverage Δ | |
|---|---|---|
| unittests | 99.94% <98.50%> (-0.06%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
I looked at the test coverage issue. There is a problem with the part:
if not daily_summary:
return None
That said, if we try to pull a summary from time when the account wasn't used or has no data, it will still return non-empty return, but every single key is marked as None essentially.
I believe the best way to solve this is to drop the if condition completely. What are your thoughts @matin? Also, is there anything else that needs to be solved?