{# Shared by the health pages: header (⌂ 📅 … ··· Health ··· ⚙), under it the tabs Overview|Body|Sleep|Heart|Activity; a floating + = Measurements, number formats, the measurement dialog (health.js). Import "with context" (uses v). #} {% from "_header.html" import nav_btns, settings_btn, title_block, subline, section_tabs %} {% from "health/_watch.html" import hm %} {% macro n(x, d=1) %}{% if x is none %}—{% else %}{{ ("%." ~ d ~ "f") | format(x) }}{% endif %}{% endmacro %} {% macro sgn(x, d=1) %}{{ "+" if x > 0 else ("−" if x < 0 else "±") }}{{ ("%." ~ d ~ "f") | format(x | abs) }}{% endmacro %} {% macro dm(d) %}{{ d.day }} {{ d.strftime("%b") }}{{ " " ~ d.year if d.year != v.today.year }}{% endmacro %} {# hover strips: one per bucket, health.js shows its tip (+ click opens data-href) #} {% macro hits(c, href=None) %}{% for h in c.hits %}{% endfor %}{% endmacro %} {% macro chart(c, id, href=None) %} {% if c %} {% for s in c.bands %}{% endfor %} {% for t in c.yt %}{{ t.label }}{% endfor %} {% for t in c.xt %}{{ t.label }}{% endfor %} {% for l in c.lines %}{% for r in l.rects %}{% endfor %}{% if l.d %}{% endif %}{% for x, y in l.dots %}{% endfor %}{% endfor %} {{ hits(c, href) }} {% if c.lines | length > 1 %}
{% for l in c.lines %}{{ l.name }}{% endfor %}
{% endif %} {% else %}

Nothing in this period.

{% endif %} {% endmacro %} {# sleep window: one bar per night from bedtime to wake-up (watch.window_chart) #} {% macro window(c, href=None) %} {% if c %} {% for t in c.yt %}{{ t.label }}{% endfor %} {% for t in c.xt %}{{ t.label }}{% endfor %} {% for r in c.rects %}{% endfor %} {{ hits(c, href) }} {% else %}

Nothing in this period.

{% endif %} {% endmacro %} {# range + grouping switches; links keep the other query values #} {% macro qs(r=None, g=None) %}?{% set q = dict(request.args) %}{% if r %}{% set _ = q.update(r=r) %}{% endif %}{% if g %}{% set _ = q.update(g=g) %}{% endif %}{{ q | urlencode }}{% endmacro %} {% macro ranges() %}
{% if v.grains is defined and v.grains | length > 1 %}{% endif %}
{% endmacro %} {# a card title whose explanation shows on hover / tap #} {% macro title(text, tip, small=None) %}

{% if tip %}{{ text }}{{ tip }}{% else %}{{ text }}{% endif %}{% if small %} {{ small }}{% endif %}

{% endmacro %} {% macro more(n) %}{% if n %}

… and {{ n }} more — pick a shorter period to see them.

{% endif %}{% endmacro %} {% macro assets() %} {% endmacro %} {# add = what the floating + opens on this tab ("measure", "bp", "ox"); hovering it lists all three (adder() — the dialog, with a tab per kind) #} {% macro head(sub, add="measure") %} {% set ADD_KINDS = [("measure", "Body measurements"), ("bp", "Blood pressure"), ("ox", "Blood oxygen")] %}
{{ nav_btns() }} {{ title_block("Health", "/health") }} {{ settings_btn("health") }}
{{ subline(sub) }} {{ section_tabs("health", {"overview": "/health", "body": "/health/body", "sleep": "/health/sleep", "heart": "/health/heart", "activity": "/health/activity"}.get(tab, "-")) }}
{% endmacro %} {% macro note() %} {% if v.prof and v.prof.missing %}
Set your {{ v.prof.missing | join(" and ") }} in Settings ▸ Health — BMI and most formulas need {{ "them" if v.prof.missing | length > 1 else "it" }}.
{% endif %} {% endmacro %} {# a table's pages: ?=N (the other query args kept), back to # #} {% macro pager(param, cur, pages, anchor) %}{% if pages > 1 %}{% set q = dict(request.args) %} {% endif %}{% endmacro %} {# The add dialog, on every health page: a tab per kind — body measurements (one row per day; picking a day that has values loads them), blood pressure, blood oxygen (one reading each, /health/api/vital). Editing an entry opens its tab, the tabs hidden. health.js. #} {% macro adder() %} {% set ADD_KINDS = [("measure", "Body measurements"), ("bp", "Blood pressure"), ("ox", "Blood oxygen")] %} {% set today_iso = add_form.today %} {% endmacro %} {# ranges by age + sex: hidden, shown on hover / focus (tap on touch) over the category #} {% macro bar(sc) %}{% if sc %}{% for s in sc.segs %}{% endfor %}{% if sc.at is not none %}{% endif %}{% endif %}{% endmacro %} {% macro fat_pop(label) %}{% set b = v.body %}{% if b.fat_band %}{{ label }} Body fat, {{ "women" if v.prof.sex == "female" else "men" }} {{ bar(b.fat_bar) }} agelowhealthyhighvery high {% for a, z, h, o, vo in b.fat_ranges %}{{ a }}–{{ z }}< {{ h }}{{ h }}–{{ o }}{{ o }}–{{ vo }}{{ vo }}+{% endfor %} % · Gallagher et al. 2000{% else %}{{ label }}{% endif %}{% endmacro %} {% macro bmi_pop(label) %}{% set b = v.body %}{{ label }} BMI {{ bar(b.bmi_bar) }} WHO, every adult: under 18.5 underweight · 18.5–25 normal · 25–30 overweight · 30+ obese. Not different for women and men. agedesirable {% for a, z, lo, hi in b.bmi_ages %}{{ a }}{{ "+" if z > 120 else "–" ~ z }}{{ lo }}–{{ hi }}{% endfor %} By age: US National Research Council 1989{% endmacro %} {# heart-rate zones: table with a bar per zone (watch.zone_rows) / a thin strip per workout #} {% macro zone_table(rows) %} {% for z in rows %}{% endfor %}
{{ z.name }} {% if z.from %}{{ z.from }}{{ ("–" ~ z.to) if z.to else "+" }}{% else %}< {{ z.to + 1 }}{% endif %} {{ (z.sec // 60) }} min · {{ z.pct }} %
{% endmacro %} {% macro zone_strip(pct) %}{% for x in pct %}{% if x %}{% endif %}{% endfor %}{% endmacro %} {# what the zones are based on, e.g. "heart-rate reserve · max 187 (age) · resting 64 (watch)" #} {% macro zone_basis(p) %}{{ "heart-rate reserve" if p.method == "hrr" else "% of max" }} · max {{ p.hrmax }} ({{ "setting" if p.max_set else "from age" }}){% if p.method == "hrr" %} · resting {{ p.rest }} ({{ "setting" if p.rest_set else "watch data" }}){% endif %}{% endmacro %} {# one night: score ring (breakdown on hover), numbers, the stages with hover tips — Sleep page + Overview #} {% macro night(t, g, goal) %}
{{ t.score }}score Sleep score {{ t.score }} / 100 {% for k, p in t.parts.items() %}{{ k }}{{ p if p is not none else "—" }} / {{ {"Duration": 50, "Deep sleep": 20, "Efficiency": 15, "Interruptions": 15}[k] }}{% endfor %} Duration: full at {{ "%g" | format([goal, 8] | min - 0.5) }} h+; deep: full at 20 %; efficiency: asleep ÷ in bed, full at 95 %; interruptions: −4 per wake-up. Our own formula.
Asleep
{{ hm(t.asleep) }}
In bed
{{ t.start.strftime("%H:%M") }}–{{ t.end.strftime("%H:%M") }}
Deep
{% if t.deep_pct is not none %}{{ hm(t.deep) }} · {{ t.deep_pct | round | int }} %{% else %}—{% endif %}
Light
{{ hm(t.light) if t.light else "—" }}
Awake
{{ hm(t.awake or 0) }} · {{ t.wakeups or 0 }}×
Efficiency
{{ (t.eff * 100) | round | int }} %
{% for l in g.lanes %}{{ l.label }}{% endfor %} {% for l in g.lanes %}{% endfor %} {% for b in g.blocks %}{% endfor %} {% for t in g.ticks %}{{ t.label }}{% endfor %}
{% endmacro %} {# a workout: heart rate over time on the zone bands, with hover tips — workout page + Overview #} {% macro hr_graph(g, cls="hl-hr") %} {% if g %} {% for b in g.bands %}{% endfor %} {% for t in g.yt %}{{ t.label }}{% endfor %} {% for t in g.xt %}{{ t.label }}{% endfor %} {{ hits(g) }} {% else %}

No heart rate recorded for this workout.

{% endif %} {% endmacro %}