Skip to content

feat: TPP trend visualization (Story 20.4)#105

Merged
rajish merged 7 commits into
masterfrom
feature/story-20-4-tpp-trend-visualization
Mar 27, 2026
Merged

feat: TPP trend visualization (Story 20.4)#105
rajish merged 7 commits into
masterfrom
feature/story-20-4-tpp-trend-visualization

Conversation

@rajish

@rajish rajish commented Mar 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds "Token Efficiency" section to analytics window with per-model TPP charts
  • Two-tier visualization: prominent benchmark diamonds + lighter passive data points using Swift Charts
  • 7-point moving average trend line with shift detection (>20% deviation annotations)
  • Plain-English insight banner ("Your token efficiency dropped ~X% recently")
  • Rate limit weighting discovery card from benchmark variants
  • Time range support (24h/7d/30d/All) with model picker and series toggles
  • 16 new unit tests (10 TPPChartDataService + 6 TPPChartData model tests)

Story

20.4: TPP Trend Visualization

Test plan

  • All XCTest unit tests pass
  • Code review findings addressed
  • Build succeeds with xcodebuild

Summary by CodeRabbit

  • New Features

    • Added "Token Efficiency Trend" analytics section displaying historical token efficiency data as interactive charts with passive vs. benchmark measurements, trend lines, and shift detection annotations.
    • Included model selection, series visibility toggles, insight banners, and rate-limit weighting discovery information within the analytics view.
  • Chores

    • Updated sprint status and planning documentation for upcoming TPP-related development work.

rajish added 7 commits March 28, 2026 00:55
Add Token Efficiency Trend section to analytics window with per-model
charts showing benchmark points (diamonds), passive data (circles),
7-point moving average trend line, shift detection annotations, and
plain-English insight banner. Includes model picker, series toggles,
rate limit weighting discovery card, and time-range-aware data
resolution (individual/daily/weekly averages).

New files:
- TPPChartData model (chart points, shift annotations, weighting discovery)
- TPPChartDataService (data transformation, averaging, trend computation)
- TPPTrendChartView (Swift Charts two-tier visualization)
- TPPSectionView (container with controls, legend, empty state)

Tests: 14 tests covering insight text, averaging, moving average, shift
detection, model discovery, weighting ratios, time range filtering, and
model struct properties.
- Drop @unchecked Sendable from TPPChartDataService (all stored state is immutable let, plain Sendable suffices)
- Replace fragile benchmarkMeasurements.last with explicit max(by: timestamp) for correctness
- Remove computed property chartDataService that recreated service on every access; instantiate inline in loadData()
- Replace DateFormatter allocation in weightingCard render with .formatted(date:time:) call
- Fix AC-1: suppress empty shell when chartData.isEmpty and benchmark is disabled; task modifier preserved so section re-evaluates when passive data arrives
@rajish
rajish merged commit 8e87326 into master Mar 27, 2026
0 of 2 checks passed
@rajish
rajish deleted the feature/story-20-4-tpp-trend-visualization branch March 27, 2026 23:56
@coderabbitai

coderabbitai Bot commented Mar 27, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3377354f-5cc6-4195-88ec-5c359de0dd09

📥 Commits

Reviewing files that changed from the base of the PR and between 4a3d985 and 3277c5d.

📒 Files selected for processing (12)
  • _bmad-output/implementation-artifacts/20-3-tpp-data-model-passive-measurement-engine.md
  • _bmad-output/implementation-artifacts/20-4-tpp-trend-visualization.md
  • _bmad-output/implementation-artifacts/20-5-historical-tpp-backfill.md
  • _bmad-output/implementation-artifacts/sprint-status.yaml
  • cc-hdrm/Models/TPPChartData.swift
  • cc-hdrm/Services/TPPChartDataService.swift
  • cc-hdrm/Services/TPPChartDataServiceProtocol.swift
  • cc-hdrm/Views/AnalyticsView.swift
  • cc-hdrm/Views/TPPSectionView.swift
  • cc-hdrm/Views/TPPTrendChartView.swift
  • cc-hdrmTests/Models/TPPChartDataTests.swift
  • cc-hdrmTests/Services/TPPChartDataServiceTests.swift

📝 Walkthrough

Walkthrough

Introduces TPP trend visualization functionality with a service layer for data transformation, models for chart representation, SwiftUI views for rendering trends and insights, and comprehensive test coverage. Resets Story 20.3 task checklist to ready-for-dev status and promotes Stories 20.4 and 20.5 from backlog.

Changes

Cohort / File(s) Summary
Story Documentation & Status
_bmad-output/implementation-artifacts/20-3-tpp-data-model-passive-measurement-engine.md, _bmad-output/implementation-artifacts/20-4-tpp-trend-visualization.md, _bmad-output/implementation-artifacts/20-5-historical-tpp-backfill.md, _bmad-output/implementation-artifacts/sprint-status.yaml
Story 20.3 reverted to ready-for-dev with all tasks unchecked; Stories 20.4 and 20.5 added as comprehensive implementation specs and marked ready-for-dev in status tracking.
Data Models
cc-hdrm/Models/TPPChartData.swift
Defines chart data structures: TPPChartPoint, TPPShiftAnnotation, TPPWeightingDiscovery, TPPChartData with computed isEmpty property and static empty instance; introduces ShiftDirection enum.
Service Layer
cc-hdrm/Services/TPPChartDataServiceProtocol.swift, cc-hdrm/Services/TPPChartDataService.swift
Implements protocol-based service for loading and transforming TPP measurements into chart-ready structures; includes daily/weekly averaging, 7-point moving-average trend computation, shift detection (>20% sustained deviation), insight text generation, and model discovery with frequency sorting.
UI Views
cc-hdrm/Views/TPPSectionView.swift, cc-hdrm/Views/TPPTrendChartView.swift
TPPSectionView manages data loading, model selection, series visibility toggles, and renders insight banner, legend, and weighting discovery card; TPPTrendChartView uses Apple Charts to render benchmark diamonds and passive circles with confidence-based opacity, smoothed trend line, and shift annotations.
Analytics Integration
cc-hdrm/Views/AnalyticsView.swift
Conditionally inserts TPPSectionView with divider after BenchmarkSectionView when tppStorageService is available, wiring time range dependencies and reload triggers.
Test Coverage
cc-hdrmTests/Models/TPPChartDataTests.swift, cc-hdrmTests/Services/TPPChartDataServiceTests.swift
Unit tests validate model properties and computed values; service tests verify insight generation scenarios, daily/weekly averaging, moving-average correctness, shift detection, model discovery sorting, weighting ratios, and time-range filtering via mock storage.

Sequence Diagram

sequenceDiagram
    participant User as User / AnalyticsView
    participant TPPSectionView
    participant TPPChartDataService
    participant TPPStorageService
    participant TPPTrendChartView

    User->>TPPSectionView: Load with timeRange + model
    activate TPPSectionView
    TPPSectionView->>TPPChartDataService: loadTPPData(timeRange, model)
    activate TPPChartDataService
    
    TPPChartDataService->>TPPStorageService: Fetch measurements
    activate TPPStorageService
    TPPStorageService-->>TPPChartDataService: [TPPMeasurement...]
    deactivate TPPStorageService
    
    TPPChartDataService->>TPPChartDataService: Partition passive/benchmark
    TPPChartDataService->>TPPChartDataService: Compute daily/weekly averages
    TPPChartDataService->>TPPChartDataService: Generate 7-point moving average
    TPPChartDataService->>TPPChartDataService: Detect shifts (>20% deviation)
    TPPChartDataService->>TPPChartDataService: Generate insight text
    
    TPPChartDataService-->>TPPSectionView: TPPChartData
    deactivate TPPChartDataService
    
    TPPSectionView->>TPPTrendChartView: Pass chartData + visibility flags
    activate TPPTrendChartView
    TPPTrendChartView->>TPPTrendChartView: Render benchmark diamonds
    TPPTrendChartView->>TPPTrendChartView: Render passive circles
    TPPTrendChartView->>TPPTrendChartView: Render trend line
    TPPTrendChartView->>TPPTrendChartView: Render shift annotations
    TPPTrendChartView-->>User: Display chart
    deactivate TPPTrendChartView
    deactivate TPPSectionView
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~65 minutes

Poem

🐰 A trend most fine, in tokens tall,
Seven points smooth, we see it all,
Shifts detected, benchmarks gleam,
Charts awaken from the dream!
Data flows through every layer—
Efficiency's own prayer!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/story-20-4-tpp-trend-visualization

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant