{# rows=N caps the table at N rows behind a "Show all"; filter="placeholder" adds a filter box (app.js). #} {% macro table(rows, cols, links={}, cap=0, filter="") -%} {% if rows %}
{% for c in cols %}{% endfor %}{% for r in rows %}{% for c in cols %}{% set v = r.get(c) %} 24 %} class="wrap"{% endif %}>{% if c in links and r.get(links[c][1]) is not none %}{{ v|fmt(c) }}{% else %}{{ v|fmt(c) }}{% endif %}{% endfor %}{% endfor %}
{{ LABELS.get(c) or (c|replace("_", " ")|capitalize) }}
{% else %}{{ empty("No rows yet.") }}{% endif %} {%- endmacro %} {# One muted line for an empty table or list: sentence case, "No X yet." #} {% macro empty(msg) %}

{{ msg }}

{% endmacro %} {% macro csrf() %}{% endmacro %} {# A one-line result of the last action (msg=... in the query string): green, or red for "Error: ...". #} {% macro flash(msg) %}{% if msg %}

{{ msg }}

{% endif %}{% endmacro %} {# The page's title row: h1, an optional one-line subtitle, and (via call) actions on the right. #} {% macro page_head(title, sub="") %}

{{ title }}

{% if sub %}

{{ sub }}

{% endif %}
{% if caller %}
{{ caller() }}
{% endif %}
{% endmacro %} {# A headline number: label, value, one line under it. tone: "money" colours the value by sign; else a class. #} {% macro kpi(label, value, sub="", tone="", cls="", small=False) -%}
{{ label }}
{{ value|money(true) if tone == 'money' else value }}
{% if sub %}
{{ sub }}
{% endif %}
{%- endmacro %} {% macro pnl_cls(v) %}{{ 'good' if v is not none and v > 0 else ('bad' if v is not none and v < 0 else '') }}{% endmacro %} {# One sport_status.py cell (state ok|partial|none|na, short, text, sub) as a fixed-width quick-look badge: a colour dot, the short numeric value and a label, with the full text/sub as a hover tooltip. #} {% macro status_badge(label, x) %}{% set cls = {"ok": "good", "partial": "warn", "none": "bad", "na": "muted"}[x.state] %}{{ x.short }} {{ label }}{% endmacro %} {# A signed money amount coloured by its sign: +$12.30 green, -$4.00 red, $0.00 plain. #} {% macro pnl(v, bold=False) %}{% if v is not none %}<{{ 'b' if bold else 'span' }} class="{{ pnl_cls(v) }}">{{ v|money(true) }}{% endif %}{% endmacro %} {% macro bar(fair, mid=None, cls="", kalshi_mid=None) -%} {%- set fair = fair if fair == fair else none %}{% set mid = mid if mid == mid else none %}{% set kalshi_mid = kalshi_mid if kalshi_mid == kalshi_mid else none %}
{% if fair is not none %}
{% endif %}{% if mid is not none %}
{% endif %}{% if kalshi_mid is not none %}{% endif %}
{%- endmacro %} {% macro pct(p, digits=0) -%}{% set lo = 0.5 / 10 ** digits %}{% if p is none or p != p %}–{% elif 0 < p * 100 < lo %}<{{ ("%." ~ digits ~ "f%%")|format(lo * 2) }}{% elif 100 - lo < p * 100 < 100 %}>{{ ("%." ~ digits ~ "f%%")|format(100 - lo * 2) }}{% else %}{{ ("%." ~ digits ~ "f%%")|format(p * 100) }}{% endif %}{%- endmacro %} {% macro venue_chips(venues, mine=None) -%}
{% set ns = namespace(first_live=true) %}{% for v in venues %}{% if v.venue.kind == 'private' %}{% if mine and mine.open %}Private book · {{ mine.open }} mine{% else %}Private book{% endif %} {% elif v.venue.status == 'soon' %}{{ v.venue.name }} · soon {% elif v.listed %}{% set pressed = ns.first_live %}{% if ns.first_live %}{% set ns.first_live = false %}{% endif %} {% else %}{{ v.venue.name }} · pending{% endif %}{% endfor %}
{%- endmacro %} {% macro chart(c) -%} {% if c and c.lines %} {% for y in c.yticks %}{{ y.label }}{% endfor %} {% for x in c.xticks %}{{ x.label }}{% endfor %} {% for m in c.markers %}{{ m.label }}{% endfor %} {% for l in c.lines %}{% if l.fair_y is not none %}{% endif %}{% endfor %} {% if c.zero_y is defined and c.zero_y is not none %}{% endif %}
{% for l in c.lines %}{{ l.label }}{% endfor %}{% if c.zero_y is not defined %} · solid = {{ c.venue if c.venue is defined else 'Polymarket' }} price, dotted = our fair{% endif %}
{% endif %} {%- endmacro %} {% macro pc(x) %}{% if x is not none and x >= 0.0005 %}{{ "%.1f"|format(x * 100) }}%{% elif x is not none %}–{% endif %}{% endmacro %} {% macro px(x) %}{{ "%.2f"|format(x) if x is not none else "–" }}{% endmacro %} {% set kind_word = {"race_win": "wins", "race_podium": "on the podium", "race_pole": "on pole", "race_h2h": "(first ahead)", "race_constructor_top": "top constructor", "race_safety_car": "in the race", "race_red_flag": "in the race", "race_rain": "in the race", "race_fastest_lap": "fastest lap"} %} {# One edge / gap cell (a probability difference, fair vs market): warn over 10 pts either way, good over +2, bad under -2. label replaces the "+1.2 pts" text (the exchange "Call" column), good overrides the +2 test, mark=false drops the warning glyph and tooltip, warn=false the warn tone too, cls adds classes. #} {% macro edge_cell(e, label=none, good=none, mark=true, cls="", pts=true, warn=true) -%} {%- set big = warn and e and (e > 0.10 or e < -0.10) -%} {%- set tone = 'warn' if big else (('good' if good else '') if good is not none else ('good' if e and e > 0.02 else ('bad' if e and e < -0.02 else ''))) -%} {%- if label is not none %}{{ label }}{% elif e is not none %}{{ "%+.1f"|format(e * 100) }}{{ " pts" if pts }}{% endif %}{% if big and mark %} ⚠{% endif %} {%- endmacro %} {% macro new_badge(n=0) %}{{ n ~ " " if n else "" }}new{% endmacro %} {% macro paper_banner(n) %}{% if n and n.profile %}
Fantasy account · {{ n.profile }} Polymarket P&L {{ n.pnl|money(true) }} {% if n.private is not none %}Private book {{ n.private|money(true) }}{% endif %} Strategy: track record and how it got here → · Positions →
{% endif %}{% endmacro %} {# Demo-only context: an info bubble, tagged invisibly (data-tag="demo-context") so it can be found and dropped for real users: RACINGLINES_DEMO_CONTEXT=0 hides every one; before launch, delete the calls (grep -rn demo_context racinglines/web/templates). Not used on the 101 page, which is the demo's own. #} {% macro demo_context(title="") %}{% if demo_context_on() %}{% endif %}{% endmacro %} {# The compact source note (owner, 2026-10-13): one muted line naming where a page's numbers come from: the sport's results feed(s) (sports/.toml [sources]), the price venues shown, and the model run behind the fair values (racinglines/attribution.py note). sport: a sport or competition code, or a list; venues: codes, names or Venue objects. #} {% macro source_note(sport=none, venues=none, run=none, as_of=none, model=false, sportsbook=false) -%} {%- if sources_note is defined %}{% set n = sources_note(sport, venues, run, as_of, model, sportsbook) -%} {%- if n.parts %}

Sources: {% for p in n.parts %}{{ p.label }}: {% for i in p.entries %}{% if i.url %}{{ i.name }}{% else %}{{ i.name }}{% endif %}{{ ", " if not loop.last }}{% endfor %}{{ " · " if not loop.last }}{% endfor %}

{% endif %}{% endif %} {%- endmacro %}