Skip to content

Conversation

@codebymini
Copy link
Collaborator

Add Advanced Statistics View

Summary

This PR introduces a comprehensive statistics view that provides detailed glucose and treatment analytics across multiple time periods (1, 14, and 30 days).

Features Added

📊 Core Statistics

  • Aggregated Stats View: Central dashboard displaying key metrics
    • GMI (Glucose Management Indicator) with toggle to eHbA1c
    • Average glucose
    • Standard deviation with toggle to CV (Coefficient of Variation)
    • Total daily dose (insulin)
    • Average bolus and carbs
    • Basal comparison (programmed vs. actual delivered)

📈 Ambulatory Glucose Profile (AGP)

  • Visualizes glucose percentiles (5th, 25th, 50th/median, 75th, 95th) across a 24-hour period
  • Helps identify patterns and glucose variability throughout the day
  • Interactive graph with hour-by-hour breakdown

⏱️ Time in Range (TIR)

  • Period-based analysis (Night, Morning, Day, Evening, Average)
  • Categorizes glucose levels:
    • Very Low (<54 mg/dL)
    • Low (54-70 mg/dL)
    • In Range (70-180 mg/dL or 70-140 mg/dL in tight mode)
    • High (180-250 mg/dL)
    • Very High (>250 mg/dL)
  • Toggle between standard TIR and TITR (Time in Tight Range)
  • Stacked bar chart visualization

🎯 Glucose Risk Index (GRI)

  • Calculates and visualizes glucose variability risk
  • Risk grid showing classification zones
  • Comprehensive risk assessment metrics

Technical Implementation

New Components

  • AggregatedStatsView.swift - Main statistics container
  • AGPCalculator.swift, AGPView.swift, AGPViewModel.swift - AGP implementation
  • TIRCalculator.swift, TIRView.swift, TIRViewModel.swift - TIR implementation
  • GRICalculator.swift, GRIView.swift, GRIViewModel.swift - GRI implementation
  • SimpleStatsViewModel.swift - Basic stats calculations
  • StatsDataService.swift - Data management service
  • StatsDataFetcher.swift - Historical data fetching (up to 30 days)
  • ChartContainerView.swift - Chart wrapper utilities

Data Management

  • Added separate stats data storage arrays in MainViewController:
    • statsBGData - Blood glucose readings
    • statsBolusData - Bolus entries
    • statsSMBData - SMB entries
    • statsCarbData - Carb entries
    • statsBasalData - Basal rate data
  • Supports up to 30 days of historical data
  • Automatic data fetching with progress tracking

User Preferences

Added new storage preferences:

  • showGMI - Toggle between GMI and eHbA1c display
  • showStdDev - Toggle between Standard Deviation and CV
  • showTITR - Toggle between TIR (180 mg/dL) and TITR (140 mg/dL)

UI Integration

  • Added "Statistics" menu item to More Menu
  • Accessible from Settings menu
  • Full-screen modal presentation with navigation
  • Supports dark mode
  • Period selector (1 day, 14 days, 30 days)
  • Pull-to-refresh functionality

Bug Fixes

  • Fixed string formatting in MainViewController+updateStats.swift (removed duplicate % symbols in format strings)

Changes to Existing Files

  • SettingsMenuView.swift - Added wrapper for accessing statistics
  • MoreMenuViewController.swift - Added statistics menu entry
  • MainViewController.swift - Added stats data storage arrays
  • Storage.swift - Added statistics display preferences
  • project.pbxproj - Added Stats folder and file references

@codebymini codebymini linked an issue Nov 22, 2025 that may be closed by this pull request
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.

Feature request: Statistics view

2 participants