Skip to content

feat: auto-chunk breathing rate and HRV date ranges > 30 days - #49

Merged
veerendra2 merged 2 commits into
mainfrom
feat/auto-chunk-date-range
Jul 29, 2026
Merged

feat: auto-chunk breathing rate and HRV date ranges > 30 days#49
veerendra2 merged 2 commits into
mainfrom
feat/auto-chunk-date-range

Conversation

@veerendra2

Copy link
Copy Markdown
Owner

Overview

Fixes #35 by implementing automatic chunking for date ranges > 30 days for Breathing Rate and HRV endpoints using Claude Code CLI (gemini/gemini-3.6-flash model via gateway).

Changes

  • fitbit_cli/fitbit_api.py: Added private helper _fetch_chunked_data(self, url_template, key, start_date, end_date=None) to automatically split ranges > 30 days into <= 30-day windows, fetch each chunk, and aggregate response lists (br and hrv).
  • fitbit_cli/__init__.py: Bumped version to 1.9.0.
  • tests/date_range_test.py: Added unit tests for single date, <= 30 day range, and multi-chunk > 30 day range.

How to Test

  1. Unit tests:
    pytest tests/date_range_test.py
  2. Local execution with relative dates > 30 days:
    git fetch origin
    git checkout feat/auto-chunk-date-range
    pip3 install -e .
    fitbit-cli -b last-2-months
    fitbit-cli -H last-3-months

@veerendra2
veerendra2 marked this pull request as ready for review July 29, 2026 07:53
@veerendra2
veerendra2 requested a review from Copilot July 29, 2026 07:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds automatic date-range chunking for Breathing Rate and HRV API calls so requests spanning more than 30 days are split into multiple <=30-day requests and then aggregated, preventing Fitbit API errors for long ranges.

Changes:

  • Added a private helper in FitbitAPI to fetch and aggregate multi-chunk responses for long date ranges.
  • Updated Breathing Rate (summary + intraday) and HRV (summary) endpoints to use the chunking helper.
  • Bumped package version and added unit tests covering single-date, <=30-day, and multi-chunk scenarios.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
fitbit_cli/fitbit_api.py Introduces _fetch_chunked_data() and routes br/hrv endpoints through it to support ranges > 30 days.
fitbit_cli/__init__.py Version bump to 1.9.0.
tests/date_range_test.py Adds unit tests validating request chunking behavior and aggregation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread fitbit_cli/fitbit_api.py Outdated
Comment thread tests/date_range_test.py
- Preserve top-level metadata fields from first response chunk in _fetch_chunked_data
- Add exact call count assertion to multi-chunk date range test

Co-Authored-By: Claude <noreply@anthropic.com>
@veerendra2

Copy link
Copy Markdown
Owner Author

Addressed both Copilot review suggestions:

  1. Preserve Top-Level Metadata (fitbit_cli/fitbit_api.py): _fetch_chunked_data now initializes result_dict as a copy of the first chunk's response dictionary before replacing result_dict[key] with the aggregated list. This preserves any top-level metadata fields and keeps behavior consistent with --raw-json output.
  2. Strict Call Count Assertion (tests/date_range_test.py): Added self.assertEqual(self.api.make_request.call_count, 2) to test_range_over_30_days_multi_chunk to ensure exact call count enforcement.

All unit tests (35/35) and linters (black, isort, pylint 10/10, mypy) pass cleanly.

@veerendra2
veerendra2 merged commit 20dd1d6 into main Jul 29, 2026
2 checks passed
@veerendra2
veerendra2 deleted the feat/auto-chunk-date-range branch July 29, 2026 08:24
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.

Fix breathing and HRV API date range

2 participants