AccelerometerScreen.tsx

Displays the core temperature history graph and a 24-hour activity summary dashboard

Purpose

This module renders the Dashboard tab, presenting a scrollable summary of the user’s core temperature activity over the past 24 hours. It fetches stored prediction history, computes derived statistics, and renders them in two cards: a live temperature graph and a “last 24 hours” summary with zone breakdown.

Its responsibilities include:

  • Polling the core temperature history database on focus and every 60 seconds
  • Computing session-level statistics from raw prediction records
  • Classifying each temperature reading into a heat-risk zone
  • Rendering a proportional horizontal zone bar and legend
  • Displaying peak temperature with zone color and trend indicator
  • Lazy-fetching the current WBGT value when the advanced section is opened
  • Formatting all temperatures according to the user’s unit system preference
  • Localizing all labels via react-i18next

Invariants

Polling on Focus

Data is refreshed immediately when the tab receives focus and every 60 seconds thereafter via setInterval.

The interval is cleared via the useFocusEffect cleanup return to prevent stale updates when the tab is not visible.


Zone Classification

Every temperature reading is classified into exactly one of four zones using a descending threshold scan:

ZoneMin temp (°C)Color
red40rgba(239,68,68,1)
orange38.5rgba(249,115,22,1)
yellow38rgba(234,179,8,1)
green−∞rgba(34,197,94,1)

Zone thresholds must stay in sync with Dashboard.tsx TEMP_ZONES.


Zone Time Cap

Individual inter-prediction gaps are capped at 60 minutes when accumulating zone time.

This prevents a single large gap (e.g. overnight inactivity) from inflating zone totals.


Active Gap Definition

Two consecutive predictions are considered part of the same active session when the gap between them is ≤ 2 minutes.

Gaps larger than 2 minutes reset the current session counter and do not contribute to monitoringMins.


WBGT Lazy Load

The WBGT value is only fetched when the advanced section is opened for the first time.

Once fetched, it is cached in component state and not re-fetched on subsequent opens. A value of -1 signals that WBGT is unavailable.


Trend Detection

A trend is computed from the last 5 predictions within the most recent 6-hour window.

Delta vs prior averageTrend
> 0.2 °CRising ↑
< −0.2 °CCooling ↓
within ±0.2 °CNone

Fewer than 3 records always produce no trend.


Variants

Empty State

When no predictions exist within the 24-hour window, the zone bar and legend are replaced with a localized “no data today” hint text.


Advanced Section

The advanced card section is collapsed by default and toggled by a pressable chevron row.

When expanded, it reveals: total prediction count, average temperature, current WBGT, time at risk (red + orange zones combined), and longest continuous session duration.


Exports

AccelerometerScreen (default)

export default function AccelerometerScreen(): JSX.Element

Renders the full dashboard tab with core temperature graph and 24-hour summary statistics.

Has no props; reads unit system preference from profileStore on focus.