Skip to content

Conversation

vactomas
Copy link

@vactomas vactomas commented Jul 11, 2025

Hi, matin,
I've added a couple of additional metrics, which can be obtained from the Garmin API. I believe they could be of use to people, who process the data themselves.

Let me know, what you think!

Summary by CodeRabbit

  • New Features

    • Added support for retrieving Garmin fitness scores and morning training readiness data, including detailed metrics and feedback for specific dates or date ranges.
  • Documentation

    • Expanded documentation with examples and detailed descriptions for accessing Garmin Scores and Morning Training Readiness data.
  • Tests

    • Introduced tests to verify correct retrieval and handling of Garmin Scores and Morning Training Readiness data.

Copy link
Contributor

coderabbitai bot commented Jul 11, 2025

Walkthrough

The changes introduce two new data classes, GarminScoresData and MorningTrainingReadinessData, for retrieving and representing extended Garmin fitness and readiness metrics. Documentation is updated with usage examples. Public exports and imports are adjusted to include these classes, and new tests are added to validate their API methods.

Changes

File(s) Change Summary
README.md Expanded documentation with sections and examples for Garmin Scores and Morning Training Readiness data retrieval.
src/garth/init.py, src/garth/data/init.py Added imports and public exports for GarminScoresData and MorningTrainingReadinessData.
src/garth/data/garmin_scores.py Introduced GarminScoresData class with methods to fetch and list Garmin fitness scores.
src/garth/data/morning_training_readiness.py Introduced MorningTrainingReadinessData class with methods to fetch and list morning readiness metrics.
tests/data/test_garmin_scores.py Added tests for GarminScoresData's get and list methods.
tests/data/test_morning_training_readiness.py Added tests for MorningTrainingReadinessData's get and list methods.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Client
    participant GarminAPI

    User->>Client: Call GarminScoresData.get(date)
    Client->>GarminAPI: Fetch hill score for date
    GarminAPI-->>Client: Hill score data
    Client->>GarminAPI: Fetch endurance score for date
    GarminAPI-->>Client: Endurance score data
    Client->>User: Return GarminScoresData instance

    User->>Client: Call MorningTrainingReadinessData.get(date)
    Client->>GarminAPI: Fetch readiness data for date
    GarminAPI-->>Client: Readiness data (multiple entries)
    Client->>Client: Filter for 'AFTER_WAKEUP_RESET'
    Client->>User: Return MorningTrainingReadinessData instance
Loading

Suggested reviewers

  • matin

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 840a25b and 5d23551.

⛔ Files ignored due to path filters (2)
  • tests/data/cassettes/test_morning_training_readiness_data_get.yaml is excluded by !tests/**/cassettes/**
  • tests/data/cassettes/test_morning_training_readiness_data_list.yaml is excluded by !tests/**/cassettes/**
📒 Files selected for processing (5)
  • README.md (1 hunks)
  • src/garth/__init__.py (2 hunks)
  • src/garth/data/__init__.py (2 hunks)
  • src/garth/data/morning_training_readiness.py (1 hunks)
  • tests/data/test_morning_training_readiness.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • README.md
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/garth/init.py
  • src/garth/data/init.py
  • tests/data/test_morning_training_readiness.py
  • src/garth/data/morning_training_readiness.py
✨ 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.

❤️ Share
🪧 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.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
src/garth/data/garmin_scores.py (2)

38-46: Consider API call efficiency and error handling

The method makes two separate API calls which could be inefficient, but this may be necessary due to the API design. The error handling returns None if either endpoint fails, which is reasonable but could be more granular.

Consider if both endpoints are always required or if partial data could be useful in some cases.


60-65: Complex field renaming logic - consider adding comments

The dictionary comprehension for renaming endurance classification fields is complex but appears correct. Consider adding a comment to explain the logic for better maintainability.

+        # Rename classification fields to include 'endurance_classification' prefix
         data_endurance_score = {
             ("endurance_classification" + key[len("classification") :])
             if key.startswith("classification")
             else key: value
             for key, value in data_endurance_score.items()
         }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b027e1 and 840a25b.

⛔ Files ignored due to path filters (4)
  • tests/data/cassettes/test_garmin_scores_data_get.yaml is excluded by !tests/**/cassettes/**
  • tests/data/cassettes/test_garmin_scores_data_list.yaml is excluded by !tests/**/cassettes/**
  • tests/data/cassettes/test_morning_training_readiness_data_get.yaml is excluded by !tests/**/cassettes/**
  • tests/data/cassettes/test_morning_training_readiness_data_list.yaml is excluded by !tests/**/cassettes/**
📒 Files selected for processing (7)
  • README.md (1 hunks)
  • src/garth/__init__.py (2 hunks)
  • src/garth/data/__init__.py (2 hunks)
  • src/garth/data/garmin_scores.py (1 hunks)
  • src/garth/data/morning_training_readiness.py (1 hunks)
  • tests/data/test_garmin_scores.py (1 hunks)
  • tests/data/test_morning_training_readiness.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`tests/**`: - test functions shouldn't have a return type hint - it's ok to use `assert` instead of `pytest.assume()`

tests/**: - test functions shouldn't have a return type hint

  • it's ok to use assert instead of pytest.assume()

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • tests/data/test_garmin_scores.py
  • tests/data/test_morning_training_readiness.py
🧠 Learnings (2)
tests/data/test_garmin_scores.py (1)
Learnt from: matin
PR: matin/garth#76
File: tests/test_http.py:109-109
Timestamp: 2024-12-07T14:07:11.531Z
Learning: In Python test files (e.g., `tests/test_http.py`), top-level test functions should be separated by two blank lines, as per PEP 8 style guidelines.
tests/data/test_morning_training_readiness.py (1)
Learnt from: matin
PR: matin/garth#76
File: tests/test_http.py:109-109
Timestamp: 2024-12-07T14:07:11.531Z
Learning: In Python test files (e.g., `tests/test_http.py`), top-level test functions should be separated by two blank lines, as per PEP 8 style guidelines.
🧬 Code Graph Analysis (2)
src/garth/__init__.py (3)
src/garth/data/garmin_scores.py (1)
  • GarminScoresData (14-74)
src/garth/data/hrv.py (1)
  • HRVData (39-68)
src/garth/data/morning_training_readiness.py (1)
  • MorningTrainingReadinessData (15-69)
src/garth/data/morning_training_readiness.py (3)
src/garth/utils.py (1)
  • camel_to_snake_dict (17-33)
src/garth/data/_base.py (1)
  • Data (15-47)
src/garth/http.py (2)
  • Client (19-244)
  • connectapi (186-192)
🔇 Additional comments (13)
src/garth/__init__.py (2)

4-6: LGTM - Imports follow existing patterns

The new imports are correctly placed and follow the established alphabetical ordering within the import block.


36-38: LGTM - Exports properly added to all

The new classes are correctly added to the __all__ export list in alphabetical order, maintaining consistency with existing patterns.

README.md (1)

908-1068: LGTM - Comprehensive documentation for new features

The new documentation sections are well-structured and follow the existing style patterns. The examples demonstrate both single-date and multi-date usage scenarios with detailed sample outputs, which will be helpful for users implementing these features.

src/garth/data/__init__.py (1)

6-8: LGTM - Consistent with existing module patterns

The new exports and imports are correctly added following the established alphabetical ordering and import structure patterns.

Also applies to: 21-23

src/garth/data/garmin_scores.py (2)

14-29: LGTM - Well-structured dataclass definition

The dataclass fields are comprehensive and well-named, covering all the metrics from both hill and endurance score endpoints. The field names are descriptive and follow Python naming conventions.


71-74: LGTM - Consistent list method implementation

The list method correctly delegates to the parent class and sorts by calendar_date, which is consistent with other data classes in the codebase.

tests/data/test_garmin_scores.py (2)

9-24: LGTM - Comprehensive test coverage for get() method

The test correctly verifies both positive and negative cases:

  • Tests successful data retrieval with assertions on key fields
  • Tests the case where no data is available (returns None)
  • Follows the established testing patterns with pytest.mark.vcr and authed_client fixture

26-34: LGTM - Appropriate test for list() method

The test verifies the list functionality correctly:

  • Tests with appropriate parameters (days=2, max_workers=1)
  • Verifies the returned data length matches expected days
  • Checks that the last entry matches the expected end date
  • Uses single worker to ensure deterministic test execution
tests/data/test_morning_training_readiness.py (1)

26-34: Test implementation looks good.

The test properly validates the list method functionality, checking both the returned length and the last entry's date.

src/garth/data/morning_training_readiness.py (4)

1-12: Imports and setup look good.

The imports are appropriately scoped and the module structure follows the established pattern in the codebase.


14-35: Well-structured dataclass with comprehensive field definitions.

The dataclass appropriately captures all the morning training readiness metrics with correct type annotations. The field names follow Python naming conventions.


37-64: Robust implementation of the get method.

The method properly:

  • Handles the case when no data is returned from the API
  • Filters for the specific "AFTER_WAKEUP_RESET" context to isolate morning readiness data
  • Uses the established camel_to_snake_dict utility for field conversion
  • Follows the pattern established in other data classes

66-69: Good override of the list method.

The method appropriately sorts the results by calendar_date, which provides a consistent and logical ordering for time-series data.

@vactomas vactomas force-pushed the feature/add-additional-garmin-scores branch from 840a25b to 5d23551 Compare July 11, 2025 14:56
@matin matin closed this Aug 19, 2025
@matin matin reopened this Aug 19, 2025
Copy link

codecov bot commented Aug 19, 2025

Codecov Report

❌ Patch coverage is 99.25926% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 99.95%. Comparing base (4b027e1) to head (5d23551).

Files with missing lines Patch % Lines
src/garth/data/morning_training_readiness.py 97.82% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main     #135      +/-   ##
===========================================
- Coverage   100.00%   99.95%   -0.05%     
===========================================
  Files           45       49       +4     
  Lines         1898     2028     +130     
===========================================
+ Hits          1898     2027     +129     
- Misses           0        1       +1     
Flag Coverage Δ
unittests 99.95% <99.25%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@matin
Copy link
Owner

matin commented Aug 19, 2025

@vactomas both of your PRs have the same issue. let's put pragma: no cover.

you could also mock the response, but don't worry about it. let's get these PRs merged

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.

2 participants