Apple Health Query Skill
Use this skill to analyze Apple Health data already synced into local SQLite by the collector.
Tools to use
- - Shell tool: run
scripts/query_health.py to pull fresh JSON data. - HTTP tool: optionally verify collector availability with
/healthz before troubleshooting missing data.
Workflow
- 1. (Optional health check) Verify collector is reachable when user reports stale/missing data:
-
curl -fsS http://<collector-host>:8443/healthz
- if TLS is enabled:
curl -fsS https://<collector-host>:8443/healthz
- 2. Query the local database via shell (preferred default):
-
python scripts/query_health.py --window-hours 24 --sleep-nights 7 --types heart_rate,glucose,sleep_stage
- 3. Adjust parameters to user intent:
- Short check-in:
--window-hours 1
- Daily review:
--window-hours 24 --sleep-nights 7
- Alert follow-up: keep
--types narrow to requested metrics.
- 4. Summarize with numbers and timestamps, then give practical next steps.
- Always include safety framing: informational only, not medical advice; suggest clinician contact for extreme/persistent readings.
Output expectations
Base your answer on the returned JSON fields:
- -
generated_at, user_id, INLINECODE10 - INLINECODE11 entries with INLINECODE12
- INLINECODE13 entries with INLINECODE14
Response style guardrails
- - Cite the exact time window used (for example: “last 24 hours” and “last 7 nights”).
- Highlight notable thresholds carefully (e.g., glucose outside typical 70–180 mg/dL range).
- Tie suggestions to observed values; avoid generic advice.
- Never hardcode user IDs or DB paths—
scripts/query_health.py already reads .env.
Live Heart Rate
The collector stores real-time BLE heart rate events from Wahoo HR straps (and compatible sensors) in the live_events table. Use this for workout monitoring, recent-activity check-ins, or comparing live readings against resting baseline.
Tools to use
- - Shell tool: run
scripts/query_live_hr.py to pull live HR events and per-session summaries.
Workflow
- 1. Query recent live HR events (default: last 60 minutes):
-
python scripts/query_live_hr.py --window-minutes 60
- 2. Narrow to the last workout or a specific timeframe:
-
python scripts/query_live_hr.py --window-minutes 120
- 3. Filter to a specific session (use a session UUID from a previous query):
-
python scripts/query_live_hr.py --session-id <uuid> --window-minutes 180
- 4. Filter to a specific device (useful when multiple sensors are paired):
- INLINECODE22
Output fields
Base your answer on the returned JSON:
- -
summary — aggregate stats for the queried window:
-
count — total event count
-
latest_bpm,
min_bpm,
max_bpm,
avg_bpm,
median_bpm,
stddev_bpm
-
latest_zone — heart rate zone:
resting (<60),
normal (60–99),
elevated (100–139),
high (≥140)
- -
sessions[] — per-session breakdown with session_id, event_count, start_ts, end_ts, device_name, avg_bpm, min_bpm, INLINECODE44 - INLINECODE45 — individual readings with
ts, value (BPM), session_id, seq, device_id, INLINECODE51
Guidance
- - Workout summary: report
avg_bpm, max_bpm, and duration (start_ts → end_ts of the session). - Zone coaching: map
latest_zone to practical advice (e.g., elevated zone during recovery warrants attention). - Unusual readings: flag sustained HR >150 or <40 bpm; recommend clinician contact if persistent.
- Data freshness: if
count is 0, the sensor may not be paired or the session may not have started — advise the user to open the Live HR screen on their iPhone.
Apple Health 查询技能
使用此技能分析已由采集器同步到本地 SQLite 中的 Apple Health 数据。
使用的工具
- - Shell 工具:运行 scripts/query_health.py 获取最新的 JSON 数据。
- HTTP 工具:在排查缺失数据前,可选择通过 /healthz 验证采集器可用性。
工作流程
- 1. (可选健康检查)当用户报告数据过期/缺失时,验证采集器是否可达:
- curl -fsS http://<采集器主机>:8443/healthz
- 如果启用了 TLS:curl -fsS https://<采集器主机>:8443/healthz
- 2. 通过 Shell 查询本地数据库(默认首选方式):
- python scripts/query
health.py --window-hours 24 --sleep-nights 7 --types heartrate,glucose,sleep_stage
- 3. 根据用户意图调整参数:
- 快速查看:--window-hours 1
- 每日回顾:--window-hours 24 --sleep-nights 7
- 警报跟进:将 --types 限制为请求的指标。
- 4. 用数字和时间戳进行总结,然后给出实用的后续步骤。
- 始终包含安全说明:仅供参考,不构成医疗建议;建议极端/持续读数时联系临床医生。
输出预期
根据返回的 JSON 字段进行回答:
- - generatedat、userid、windowhours
- quantity.<指标>[] 条目,包含 {ts, value, unit, source, device}
- sleep[] 条目,包含 {startts, end_ts, category, source, device}
回复风格规范
- - 引用使用的确切时间窗口(例如:“过去 24 小时”和“过去 7 晚”)。
- 谨慎突出值得注意的阈值(例如,血糖超出典型 70–180 mg/dL 范围)。
- 将建议与观察到的数值联系起来;避免泛泛的建议。
- 切勿硬编码用户 ID 或数据库路径——scripts/query_health.py 已读取 .env 文件。
实时心率
采集器将来自 Wahoo 心率带(及兼容传感器)的实时 BLE 心率事件存储在 live_events 表中。用于锻炼监测、近期活动检查,或将实时读数与静息基线进行比较。
使用的工具
- - Shell 工具:运行 scripts/querylivehr.py 获取实时心率事件和每次会话的摘要。
工作流程
- 1. 查询最近的实时心率事件(默认:过去 60 分钟):
- python scripts/query
livehr.py --window-minutes 60
- 2. 缩小到最后一次锻炼或特定时间范围:
- python scripts/query
livehr.py --window-minutes 120
- 3. 过滤到特定会话(使用之前查询中的会话 UUID):
- python scripts/query
livehr.py --session-id
--window-minutes 180
- 4. 过滤到特定设备(当多个传感器配对时很有用):
- python scripts/querylivehr.py --device-id --window-minutes 60
输出字段
根据返回的 JSON 进行回答:
- count — 总事件数
- latestbpm、minbpm、maxbpm、avgbpm、medianbpm、stddevbpm
- latest_zone — 心率区间:resting(<60)、normal(60–99)、elevated(100–139)、high(≥140)
- - sessions[] — 每次会话的细分,包含 sessionid、eventcount、startts、endts、devicename、avgbpm、minbpm、maxbpm
- events[] — 单个读数,包含 ts、value(BPM)、sessionid、seq、deviceid、sourcedevicename
指导建议
- - 锻炼摘要:报告 avgbpm、maxbpm 和持续时间(会话的 startts → endts)。
- 区间指导:将 latest_zone 映射到实用建议(例如,恢复期间处于 elevated 区间需要关注)。
- 异常读数:标记持续 HR >150 或 <40 bpm;如果持续存在,建议联系临床医生。
- 数据新鲜度:如果 count 为 0,则传感器可能未配对或会话尚未开始——建议用户在 iPhone 上打开实时心率屏幕。