Skip to content

Conversation

@dlvoy
Copy link
Contributor

@dlvoy dlvoy commented Jan 15, 2026

This PR introduces an Time In Range (TIR) chart for the main overview screen, providing users with predictive insights about their daily glucose management.

Overview

The new TIR chart displays two complementary graphs of your glucose control for the current day:

daily_time_in_range_graph

Enable TIR chart from the overview screen menu (chart settings). The chart automatically updates with new glucose readings and adjusts predictions as the day progresses.

enabling_tir_graph

Till Now Bar

Shows your actual glucose distribution from midnight until the current moment:

  • Below range percentage (< target low)
  • In range percentage (within target)
  • Above range percentage (> target high)

Worst and Best Case Bar

A predictive visualization showing potential end-of-day outcomes:

  • Worst case scenario (top): Assumes no readings in range till end of a day (shown in gray)
  • Best case scenario (bottom): Assumes remaining time is all in range
  • Visual gradient: A trapezoid shape transitions from worst (narrow green bar) to best (full green bar), showing the range of possible outcomes

History dialog graph

Adds graph to history dialog, displaying TIR for time range shown on graph.

tir_on_history_dialog

User Benefits

  • Goal Awareness: See if you're on track for a good TIR day
  • Motivation: Visual feedback shows how much you can still improve today
  • Realistic Expectations: Understand both pessimistic and optimistic scenarios
  • Quick Assessment: No mental math needed—the gradient bar provides instant insight

Features

Data Validation

Displays "not enough data" message when:

  • Fewer than 10 SGV readings available
  • Worst-case in-range percentage ≤ 1%

Visual Design Features

  • Color-coded segments: Uses theme-aware colors (red/green/yellow) matching AAPS theme
  • Percentage labels: Clear percentage display for each segment
  • Range notation: Shows "X% .. Y%" for the combined scenario (e.g., "65% .. 89%") readability

Technical Details

  • DST-aware calculations: Correctly handles daylight saving time transitions
  • Percentage normalization: Ensures displayed values always sum to 100%
  • Validated preferences: Uses user-configured target ranges (mg/dL or mmol/L)
  • Backward compatible: Maintains single-row TIR display for history browser dialog

- Add TIR chart type to overview configuration menu
- Implement today's TIR calculation from midnight to now
- Create custom horizontal stacked bar chart view
- Display below/in/above range percentages with color coding
- Auto-refresh every 60 seconds with existing refresh loop
- Integrate TIR chart into history browser layout
- Update dynamically when user changes date filters
- Unit tests for TIR calculation logic
@sonarqubecloud
Copy link

@vanelsberg
Copy link
Contributor

vanelsberg commented Jan 17, 2026

👍Will have a look at this.

TIR: What range? E.g: 3.9-10 or 3.9-7.8 (see statistics)

@dlvoy
Copy link
Contributor Author

dlvoy commented Jan 17, 2026

TIR: What range? E.g: 3.9-10 or 3.9-7.8 (see statistics)

It uses user configurable LOW and HIGH markers - visualization range config, so "green" area of main SGV chart. By default it is 70-180 (3.9-10.0) but LOW marker can be configured in range 25-160, and HIGH 90-250

@mick711
Copy link

mick711 commented Jan 18, 2026

I like time in range, just for me time in range by hours help more than day.

@vanelsberg
Copy link
Contributor

Merges with dev ok. Looks good to me. No issues encountered.
Helpful addition. Do like displaying the percentages: hours/when I already can see on the BG curve.

(Ok for me. Just wondering if this belongs to AAPS "overview" or to "Statistics" 🤔- The later already gives info on TIR?)

@dlvoy
Copy link
Contributor Author

dlvoy commented Jan 18, 2026

Thanks for review!
Idea is to give immediate visibility of "where you are" right now, and what outcomes are possible from now - in terms of keeping SGV in range. It is visible on graph by seeing how much green and yellow/red points are there, but hard to quantify at glance.

Stats give post-factum analysis of TIR and many other metrics, per day, week etc. This - on the other hand - is meant to be glanced - to feel how good are you doing reaching the goal. I felt need for that after my doctor ordered me to improve my TIR. While stats dialog updated after midnight to tell how was yesterday, i had hard time to feel how i am doing right now and - if i am on good track.

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.

3 participants