# Tasks: Use CentralDB for Activities **Feature Branch**: `002-feature-use-centraldb` **Date**: 2025-10-11 **Spec**: /home/sstent/Projects/FitTrack_ReportGenerator/specs/002-feature-use-centraldb/spec.md ## Summary This document outlines the tasks required to implement the "Use CentralDB for Activities" feature. ## Phase 1: Setup - [X] T001: Add `httpx` to the project dependencies in `pyproject.toml`. - [X] T002: Add configuration for the CentralDB API base URL to the application settings. ## Phase 2: Foundational Components - [X] T003: Implement a `CentralDBClient` class in `src/clients/centraldb_client.py` to interact with the CentralDB API. This client should use `httpx` for making asynchronous requests. - [X] T004: Implement methods in `CentralDBClient` for: - Downloading a FIT file (`GET /activities/{activity_id}/file`). - Getting an analysis artifact (`GET /activities/{activity_id}/analysis`). - Creating an analysis artifact (`POST /activities/{activity_id}/analysis`). - Uploading a chart (`POST /activities/{activity_id}/analysis/charts`). - Retrieving a chart (`GET /activities/{activity_id}/analysis/charts/{chart_type}`). - [X] T005: Implement an in-memory cache in `src/core/cache.py` to store the last 5 analysis results. ## Phase 3: User Story 1 - Retrieve analysis from CentralDB **Goal**: Enable users to retrieve analysis charts and summaries for activities stored in CentralDB. **Independent Test Criteria**: A user can request a chart or a summary for an activity ID that exists in CentralDB and receive the correct analysis without having to upload the file. - [X] T006 [US1]: Update the `GET /api/analysis/{analysis_id}/summary` endpoint in `api/routers/analysis.py`. - [X] T007 [US1]: In the summary endpoint, implement the logic to: - Check the local cache for the analysis. - If not in cache, check CentralDB for the analysis artifact. - If not in CentralDB, download the FIT file, perform the analysis, and store the results in CentralDB and the local cache. - [X] T008 [US1]: Update the `GET /api/analysis/{analysis_id}/charts` endpoint in `api/routers/analysis.py`. - [X] T009 [US1]: In the charts endpoint, implement the logic to: - Check the local cache for the chart. - If not in cache, check CentralDB for the chart. - If not in CentralDB, download the FIT file, perform the analysis, generate the chart, and store it in CentralDB and the local cache. - [X] T010 [US1]: Write integration tests for the updated endpoints to verify the interaction with the CentralDB API. (tests/integration/test_centraldb_integration.py) ## Phase 4: Polish & Cross-Cutting Concerns - [X] T011: Review and refine error handling for the new CentralDB integration. - [X] T012: Add logging for all interactions with the CentralDB API. ## Dependencies - Phase 1 must be completed before Phase 2. - Phase 2 must be completed before Phase 3. - Phase 3 must be completed before Phase 4. ## Parallel Execution Examples ### User Story 1 (P1) - T006 and T008 can be worked on in parallel. - T007 and T009 can be worked on in parallel after T006 and T008 are complete.