feat: TPP trend visualization (Story 20.4)#105
Conversation
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
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (12)
📝 WalkthroughWalkthroughIntroduces 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
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~65 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Summary
Story
20.4: TPP Trend Visualization
Test plan
Summary by CodeRabbit
New Features
Chores