CGM time in range (windowed)
cgm_time_in_rangeCalculate Time in Range, Time Below Range, and Time Above Range for any glucose window with customizable target range and wake/sleep or mealtime presets. Returns mean, median, and GMI.
Instructions
Compute Time in Range (TIR), Time Below Range, and Time Above Range over a specific time window with a customizable target range. Use this for mealtime TIR (e.g. 7am-10am breakfast window), overnight TIR (e.g. 23:00-07:00), or specific date-range comparisons. Returns total_readings, readings_in_window, mean_glucose, median_glucose, and GMI (Glucose Management Indicator, estimated A1C per ADA / Bergenstal 2018: GMI% = 3.31 + 0.02392 × mean_mg_dL). Supports a time_window preset ("wake" = 06:00-22:00, "sleep" = 22:00-06:00, "all") OR explicit start_hour / end_hour (0-24, UTC) for recurring hour-of-day filtering. Defaults: 24h load, ADA 70-180 mg/dL, time_window=all. Pulls from cgm_glucose_window data; falls back to mock in unauth mode.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| hours | No | How many hours of data to load before filtering. Default 24. | |
| end_hour | No | Explicit recurring hour-of-day end (0-24, UTC). May be < start_hour to wrap midnight (e.g. 22→6). | |
| end_time | No | ISO-8601 timestamp of window end. Defaults to the latest reading available. | |
| start_hour | No | Explicit recurring hour-of-day start (0-24, UTC). Use with end_hour to override time_window preset. | |
| start_time | No | ISO-8601 timestamp of window start. Defaults to the earliest reading available. | |
| target_low | No | Low end of target range in mg/dL. Default 70 (ADA). | |
| target_high | No | High end of target range in mg/dL. Default 180 (ADA). | |
| time_window | No | Hour-of-day preset. "wake" = 06:00-22:00, "sleep" = 22:00-06:00 (wraps midnight), "all" = no hour filter. Default "all". Overridden by explicit start_hour/end_hour. | |
| privacy_mode | No | Optional privacy mode: summary | structured | raw. summary omits device/patient identifiers when present; structured/raw return full payload. |