Spaces:
Sleeping
feat: dark mode, market and quarter context on The Brief, faster cold start
Browse filesUI
- Migrate the whole app to a dark palette driven by dashboard/theme.py
tokens rather than an overlay, including a registered Plotly template so
charts theme globally. Streamlit base set to dark in config.toml.
- The Brief now opens with what a memo about a listed company must show:
a market band (price and move, market cap, 52-week range with position
marker, dividend yield) and the quarter's reported figures (revenue, EPS,
gross and operating margin, FCF with deltas). Rows come from the same
masked view Financials uses, so a hidden figure stays hidden.
- Surface what_changed on The Brief itself; it was only reachable from
another screen although it is the first thing the brief promises.
- Warn when most facts are unverified instead of showing a thin brief with
no explanation.
- Landing page explaining each destination, with saved briefs as entry
points, for visitors arriving with no ticker.
- Company Primer: prose sections rendered as cards rather than dataframes,
which were clipping sentences mid-word; empty sections collapse into one
gaps footer instead of printing bare headers.
- Full-width watch list (was capped at 760px, leaving half the row empty),
shared Q3/2026 period formatting, de-duplicated evidence CTA.
Fixes
- Dividend yield read 35.00% instead of 0.34%: yfinance returns
dividendYield as a percent and trailingAnnualDividendYield as a fraction
on the same payload, so derive it from dividendRate / price instead.
- fetch_multiples stopped failing closed once currency (which has a
default) entered the emptiness check; exclude it.
- Cold start blocked ~90s on an eager cross-encoder load that defeated the
module's own lazy loading; warm it on a background thread instead (~12s).
- briefs.db opens in WAL with a busy timeout: two Streamlit sessions on a
shared Space could collide and silently render an empty state.
Add deploy_check.py, a read-only preflight for the Space (uncommitted
data/, Company Primer coverage per ticker, local vs hf/main refs).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
- .streamlit/config.toml +5 -5
- analytics/valuation.py +39 -5
- app.py +144 -39
- dashboard/agent_graph.py +3 -3
- dashboard/chat.py +31 -5
- dashboard/company_primer.py +176 -84
- dashboard/components.py +121 -63
- dashboard/financials.py +29 -23
- dashboard/i18n.py +252 -14
- dashboard/market_read.py +2 -2
- dashboard/nav.py +9 -9
- dashboard/provenance.py +1 -1
- dashboard/signals_view.py +7 -7
- dashboard/theme.py +227 -103
- dashboard/verdict.py +411 -58
- deploy_check.py +214 -0
- storage/briefs_db.py +28 -9
- storage/reranker.py +38 -9
- tests/test_dashboard_components.py +42 -13
- tests/test_deploy_check.py +61 -0
|
@@ -1,7 +1,7 @@
|
|
| 1 |
[theme]
|
| 2 |
-
base = "
|
| 3 |
-
primaryColor = "#
|
| 4 |
-
backgroundColor = "#
|
| 5 |
-
secondaryBackgroundColor = "#
|
| 6 |
-
textColor = "#
|
| 7 |
font = "sans serif"
|
|
|
|
| 1 |
[theme]
|
| 2 |
+
base = "dark"
|
| 3 |
+
primaryColor = "#34d399"
|
| 4 |
+
backgroundColor = "#0e1217"
|
| 5 |
+
secondaryBackgroundColor = "#151a21"
|
| 6 |
+
textColor = "#e8eef5"
|
| 7 |
font = "sans serif"
|
|
@@ -38,14 +38,21 @@ def _safe_float(v) -> Optional[float]:
|
|
| 38 |
|
| 39 |
|
| 40 |
def fetch_multiples(ticker: str) -> tuple[Optional[dict], Optional[str]]:
|
| 41 |
-
"""Fetch current public trading multiples for *ticker* via yfinance.
|
| 42 |
|
| 43 |
Returns (data, error). data has trailing_pe, forward_pe, ev_to_sales,
|
| 44 |
-
ev_to_ebitda, market_cap
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
"""
|
| 47 |
from storage.earnings_cache import get as cache_get, set as cache_set
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
| 49 |
cached = cache_get(cache_key, ttl_hours=6)
|
| 50 |
if cached is not None:
|
| 51 |
return cached, None
|
|
@@ -63,8 +70,35 @@ def fetch_multiples(ticker: str) -> tuple[Optional[dict], Optional[str]]:
|
|
| 63 |
"ev_to_sales": _safe_float(info.get("enterpriseToRevenue")),
|
| 64 |
"ev_to_ebitda": _safe_float(info.get("enterpriseToEbitda")),
|
| 65 |
"market_cap": _safe_float(info.get("marketCap")),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
}
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
return None, "no valuation data available"
|
| 69 |
cache_set(cache_key, result)
|
| 70 |
return result, None
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
def fetch_multiples(ticker: str) -> tuple[Optional[dict], Optional[str]]:
|
| 41 |
+
"""Fetch current public trading multiples and quote for *ticker* via yfinance.
|
| 42 |
|
| 43 |
Returns (data, error). data has trailing_pe, forward_pe, ev_to_sales,
|
| 44 |
+
ev_to_ebitda, market_cap plus the live quote fields (price, previous_close,
|
| 45 |
+
currency, 52-week range) — any may be None if yfinance doesn't expose it for
|
| 46 |
+
this ticker. Cached 6h to avoid hammering the API.
|
| 47 |
+
|
| 48 |
+
The quote rides along on the ``.info`` call the multiples already make, so
|
| 49 |
+
showing a price on the brief costs no extra request.
|
| 50 |
"""
|
| 51 |
from storage.earnings_cache import get as cache_get, set as cache_set
|
| 52 |
+
# v3 — v1 payloads predate the quote fields, v2 predates the derived
|
| 53 |
+
# dividend yield. Bump whenever the payload shape changes, or a warm cache
|
| 54 |
+
# serves rows that are missing the new keys.
|
| 55 |
+
cache_key = f"VALUATION:v3:{ticker.upper()}"
|
| 56 |
cached = cache_get(cache_key, ttl_hours=6)
|
| 57 |
if cached is not None:
|
| 58 |
return cached, None
|
|
|
|
| 70 |
"ev_to_sales": _safe_float(info.get("enterpriseToRevenue")),
|
| 71 |
"ev_to_ebitda": _safe_float(info.get("enterpriseToEbitda")),
|
| 72 |
"market_cap": _safe_float(info.get("marketCap")),
|
| 73 |
+
"price": _safe_float(
|
| 74 |
+
info.get("currentPrice") or info.get("regularMarketPrice")
|
| 75 |
+
),
|
| 76 |
+
"previous_close": _safe_float(
|
| 77 |
+
info.get("regularMarketPreviousClose") or info.get("previousClose")
|
| 78 |
+
),
|
| 79 |
+
"currency": (info.get("currency") or "USD") or "USD",
|
| 80 |
+
"week52_high": _safe_float(info.get("fiftyTwoWeekHigh")),
|
| 81 |
+
"week52_low": _safe_float(info.get("fiftyTwoWeekLow")),
|
| 82 |
+
# Never read "dividendYield" directly: yfinance reports it as a
|
| 83 |
+
# percent (0.35 for AAPL) while "trailingAnnualDividendYield" on the
|
| 84 |
+
# same payload is a fraction (0.0034). Any magnitude heuristic gets
|
| 85 |
+
# one of them wrong, so derive the yield from the annual rate and
|
| 86 |
+
# the price, which are both unambiguous.
|
| 87 |
+
"dividend_yield_pct": None,
|
| 88 |
}
|
| 89 |
+
_rate = _safe_float(
|
| 90 |
+
info.get("dividendRate") or info.get("trailingAnnualDividendRate")
|
| 91 |
+
)
|
| 92 |
+
if _rate and result["price"]:
|
| 93 |
+
result["dividend_yield_pct"] = _rate / result["price"] * 100
|
| 94 |
+
# "currency" always has a default, so it must be excluded from the
|
| 95 |
+
# emptiness check — otherwise a ticker yfinance knows nothing about
|
| 96 |
+
# would come back as data rather than failing closed.
|
| 97 |
+
if not any(
|
| 98 |
+
value is not None
|
| 99 |
+
for key, value in result.items()
|
| 100 |
+
if key != "currency"
|
| 101 |
+
):
|
| 102 |
return None, "no valuation data available"
|
| 103 |
cache_set(cache_key, result)
|
| 104 |
return result, None
|
|
@@ -19,9 +19,12 @@ import dashboard.agent_graph as agent_graph
|
|
| 19 |
st.set_page_config(page_title="Amplegest", page_icon="📊", layout="wide", initial_sidebar_state="expanded")
|
| 20 |
inject_global_css()
|
| 21 |
|
| 22 |
-
#
|
|
|
|
|
|
|
|
|
|
| 23 |
if not st.session_state.get("_reranker_warmed"):
|
| 24 |
-
from storage.reranker import
|
| 25 |
_warmup_reranker()
|
| 26 |
st.session_state["_reranker_warmed"] = True
|
| 27 |
|
|
@@ -89,6 +92,13 @@ with st.sidebar:
|
|
| 89 |
_pending_ticker = st.session_state.pop("_pending_ticker", None)
|
| 90 |
if _pending_ticker:
|
| 91 |
st.session_state["ticker_input_box"] = _pending_ticker
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
_raw_ticker = st.text_input(
|
| 94 |
t("ticker_label"), placeholder=t("ticker_placeholder"),
|
|
@@ -128,8 +138,12 @@ with st.sidebar:
|
|
| 128 |
if _persisted:
|
| 129 |
st.session_state["brief"] = _persisted
|
| 130 |
st.session_state["brief_ticker"] = ticker_input
|
| 131 |
-
except Exception:
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
# Inline brief lookup — _get_cached_brief() is defined after this block
|
| 135 |
_sb = st.session_state.get("brief")
|
|
@@ -146,7 +160,7 @@ with st.sidebar:
|
|
| 146 |
st.divider()
|
| 147 |
st.markdown(
|
| 148 |
f'<div style="font-size:0.6rem;font-weight:700;text-transform:uppercase;'
|
| 149 |
-
f'letter-spacing:0.1em;color:#
|
| 150 |
unsafe_allow_html=True,
|
| 151 |
)
|
| 152 |
for _row in _coverage:
|
|
@@ -177,6 +191,23 @@ def _get_cached_brief() -> dict | None:
|
|
| 177 |
cached = st.session_state.get("brief")
|
| 178 |
if cached and st.session_state.get("brief_ticker") == ticker_input:
|
| 179 |
return cached
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
return None
|
| 181 |
|
| 182 |
|
|
@@ -297,7 +328,7 @@ def _reliability_bar_html(brief: dict) -> str:
|
|
| 297 |
return ""
|
| 298 |
|
| 299 |
pct = {k: round(v * 100 / total) for k, v in counts.items()}
|
| 300 |
-
colors = {"HIGH": GREEN, "MEDIUM": AMBER, "LOW": "#
|
| 301 |
segments = "".join(
|
| 302 |
f'<span style="display:inline-block;height:100%;width:{pct[k]}%;background:{colors[k]};"></span>'
|
| 303 |
for k in ("HIGH", "MEDIUM", "LOW") if pct[k] > 0
|
|
@@ -307,7 +338,7 @@ def _reliability_bar_html(brief: dict) -> str:
|
|
| 307 |
f'<span title="{t("sources_prefix")} {title}" style="display:inline-flex;align-items:center;gap:5px;">'
|
| 308 |
f'<span style="font-size:0.68rem;color:{TEXT_FAINT};">{t("sources_prefix")}</span>'
|
| 309 |
f'<span style="display:inline-block;width:60px;height:7px;border-radius:4px;overflow:hidden;'
|
| 310 |
-
f'background:#
|
| 311 |
f'</span>'
|
| 312 |
)
|
| 313 |
|
|
@@ -354,7 +385,7 @@ def _render_ticker_bar(ticker: str, brief: dict) -> None:
|
|
| 354 |
color = GREEN if d1 >= 0 else RED
|
| 355 |
prefix = "+" if d1 >= 0 else ""
|
| 356 |
d1_html = (
|
| 357 |
-
f'<span style="background:{"#
|
| 358 |
f'color:{color};border:1px solid {color}33;'
|
| 359 |
f'border-radius:4px;padding:2px 8px;font-size:0.75rem;font-weight:600;">'
|
| 360 |
f'D1 {prefix}{d1:.1f}%</span>'
|
|
@@ -383,11 +414,11 @@ def _render_ticker_bar(ticker: str, brief: dict) -> None:
|
|
| 383 |
)
|
| 384 |
|
| 385 |
# Dot separator helper
|
| 386 |
-
sep = f'<span style="color:#
|
| 387 |
|
| 388 |
inner_parts = [
|
| 389 |
-
f'<span style="font-weight:700;font-size:0.9rem;color:#
|
| 390 |
-
f'<span style="font-size:0.82rem;color:#
|
| 391 |
]
|
| 392 |
if date_html:
|
| 393 |
inner_parts.append(date_html)
|
|
@@ -495,17 +526,17 @@ def _live_trace_fragment() -> None:
|
|
| 495 |
pct = int(progress_val * 100)
|
| 496 |
ticker_label = gen.get("ticker", "")
|
| 497 |
st.markdown(
|
| 498 |
-
f'<div style="background:#
|
| 499 |
f'padding:16px 20px;margin-bottom:16px;">'
|
| 500 |
f'<div style="display:flex;justify-content:space-between;align-items:baseline;margin-bottom:4px;">'
|
| 501 |
-
f'<div style="font-size:0.88rem;font-weight:600;color:#
|
| 502 |
-
f'{t("generating_brief")} — <code style="background:#
|
| 503 |
f'</div>'
|
| 504 |
-
f'<div style="font-size:1rem;font-weight:700;color:#
|
| 505 |
f'</div>'
|
| 506 |
-
f'<div style="font-size:0.75rem;color:#
|
| 507 |
-
f'<div style="background:#
|
| 508 |
-
f'<div style="background:linear-gradient(90deg,#
|
| 509 |
f'width:{pct}%;border-radius:999px;transition:width 0.4s ease;"></div>'
|
| 510 |
f'</div>'
|
| 511 |
f'</div>',
|
|
@@ -611,10 +642,10 @@ def _render_company_route(ticker: str, config: RunConfig | None) -> None:
|
|
| 611 |
if profile is None:
|
| 612 |
st.markdown(
|
| 613 |
f"""
|
| 614 |
-
<div style="text-align:center;padding:48px 0;color:#
|
| 615 |
<div style="width:32px;height:32px;margin:0 auto 12px;border-radius:8px;
|
| 616 |
-
background:#
|
| 617 |
-
<div style="font-size:1.1rem;font-weight:600;margin-bottom:6px;color:#
|
| 618 |
<div style="font-size:0.9rem;">{t("overview_empty_body")}</div>
|
| 619 |
</div>
|
| 620 |
""",
|
|
@@ -662,6 +693,92 @@ def _render_company_route(ticker: str, config: RunConfig | None) -> None:
|
|
| 662 |
st.caption(market_error)
|
| 663 |
|
| 664 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 665 |
gen_error = st.session_state.pop("_gen_error", None)
|
| 666 |
if gen_error:
|
| 667 |
err_ticker, err_msg = gen_error
|
|
@@ -673,19 +790,7 @@ active_key = st.session_state.get("nav_key", "company")
|
|
| 673 |
if gen["running"] or gen.get("trace"):
|
| 674 |
_live_trace_fragment()
|
| 675 |
elif not ticker_input:
|
| 676 |
-
|
| 677 |
-
f"""
|
| 678 |
-
<div style="text-align:center;padding:80px 0;color:#6b7280;">
|
| 679 |
-
<div style="width:40px;height:40px;margin:0 auto 16px;border-radius:10px;
|
| 680 |
-
background:#ecfdf5;border:1px solid #a7f3d0;"></div>
|
| 681 |
-
<div style="font-size:1.2rem;font-weight:600;margin-bottom:8px;color:#0a0a0a;">{t("landing_title")}</div>
|
| 682 |
-
<div style="font-size:0.9rem;max-width:420px;margin:0 auto;line-height:1.6;">
|
| 683 |
-
{t("landing_body")}
|
| 684 |
-
</div>
|
| 685 |
-
</div>
|
| 686 |
-
""",
|
| 687 |
-
unsafe_allow_html=True,
|
| 688 |
-
)
|
| 689 |
else:
|
| 690 |
# Active ticker, not generating — show context bar then route to section
|
| 691 |
brief = _get_display_brief(_get_cached_brief(), ticker_input, run_cfg)
|
|
@@ -701,10 +806,10 @@ else:
|
|
| 701 |
else:
|
| 702 |
st.markdown(
|
| 703 |
f"""
|
| 704 |
-
<div style="text-align:center;padding:48px 0;color:#
|
| 705 |
<div style="width:32px;height:32px;margin:0 auto 12px;border-radius:8px;
|
| 706 |
-
background:#
|
| 707 |
-
<div style="font-size:1.1rem;font-weight:600;margin-bottom:6px;color:#
|
| 708 |
<div style="font-size:0.9rem;">{t("snapshot_empty_body")}</div>
|
| 709 |
</div>
|
| 710 |
""",
|
|
@@ -726,8 +831,8 @@ else:
|
|
| 726 |
# ── Global data disclaimer ─────────────────────────────────────────────────────
|
| 727 |
if ticker_input and not gen.get("running") and not gen.get("trace"):
|
| 728 |
st.markdown(
|
| 729 |
-
f'<div style="margin-top:40px;border-top:1px solid #
|
| 730 |
-
f'font-size:0.72rem;color:#
|
| 731 |
f'{t("disclaimer")}'
|
| 732 |
f'</div>',
|
| 733 |
unsafe_allow_html=True,
|
|
|
|
| 19 |
st.set_page_config(page_title="Amplegest", page_icon="📊", layout="wide", initial_sidebar_state="expanded")
|
| 20 |
inject_global_css()
|
| 21 |
|
| 22 |
+
# Warm the reranker on a background thread. This used to block the first render:
|
| 23 |
+
# importing torch + sentence-transformers costs tens of seconds on a cold process,
|
| 24 |
+
# and doing it here meant the visitor saw a blank page for all of it before any
|
| 25 |
+
# chrome appeared. A search that arrives mid-load waits on the model's own lock.
|
| 26 |
if not st.session_state.get("_reranker_warmed"):
|
| 27 |
+
from storage.reranker import warmup_async as _warmup_reranker
|
| 28 |
_warmup_reranker()
|
| 29 |
st.session_state["_reranker_warmed"] = True
|
| 30 |
|
|
|
|
| 92 |
_pending_ticker = st.session_state.pop("_pending_ticker", None)
|
| 93 |
if _pending_ticker:
|
| 94 |
st.session_state["ticker_input_box"] = _pending_ticker
|
| 95 |
+
# Opening a saved company should land on the same screen a freshly
|
| 96 |
+
# generated one does. Routing one to Company Overview and the other to
|
| 97 |
+
# The Brief gave the app two different "first screens" for the same
|
| 98 |
+
# state. Only redirect from the default landing route, so a deliberate
|
| 99 |
+
# tab choice survives switching company.
|
| 100 |
+
if st.session_state.get("nav_key") == "company":
|
| 101 |
+
st.session_state["_nav_pending_key"] = "verdict"
|
| 102 |
|
| 103 |
_raw_ticker = st.text_input(
|
| 104 |
t("ticker_label"), placeholder=t("ticker_placeholder"),
|
|
|
|
| 138 |
if _persisted:
|
| 139 |
st.session_state["brief"] = _persisted
|
| 140 |
st.session_state["brief_ticker"] = ticker_input
|
| 141 |
+
except Exception as _exc:
|
| 142 |
+
# Surfaced, not swallowed — a silent failure here is exactly what
|
| 143 |
+
# makes The Brief / What Changed wrongly ask to regenerate a
|
| 144 |
+
# brief that was already produced and persisted.
|
| 145 |
+
import sys
|
| 146 |
+
print(f"[app] persisted brief reload failed for {ticker_input!r}: {_exc}", file=sys.stderr)
|
| 147 |
|
| 148 |
# Inline brief lookup — _get_cached_brief() is defined after this block
|
| 149 |
_sb = st.session_state.get("brief")
|
|
|
|
| 160 |
st.divider()
|
| 161 |
st.markdown(
|
| 162 |
f'<div style="font-size:0.6rem;font-weight:700;text-transform:uppercase;'
|
| 163 |
+
f'letter-spacing:0.1em;color:#707b8a;padding:0 2px 4px;">{t("coverage_title")}</div>',
|
| 164 |
unsafe_allow_html=True,
|
| 165 |
)
|
| 166 |
for _row in _coverage:
|
|
|
|
| 191 |
cached = st.session_state.get("brief")
|
| 192 |
if cached and st.session_state.get("brief_ticker") == ticker_input:
|
| 193 |
return cached
|
| 194 |
+
# Defense-in-depth: the sidebar auto-load already tries this once per
|
| 195 |
+
# rerun, but session_state can lose "brief" between reruns (WebSocket
|
| 196 |
+
# reconnect, concurrent-session DB lock, etc.) without ticker_input
|
| 197 |
+
# changing. Retry here so a tab switch never asks to regenerate a brief
|
| 198 |
+
# that was already produced and persisted for this ticker.
|
| 199 |
+
if ticker_input and not st.session_state["gen"]["running"]:
|
| 200 |
+
try:
|
| 201 |
+
from storage import briefs_db
|
| 202 |
+
persisted = briefs_db.get_brief(ticker_input)
|
| 203 |
+
except Exception as exc:
|
| 204 |
+
import sys
|
| 205 |
+
print(f"[app] _get_cached_brief reload failed for {ticker_input!r}: {exc}", file=sys.stderr)
|
| 206 |
+
persisted = None
|
| 207 |
+
if persisted:
|
| 208 |
+
st.session_state["brief"] = persisted
|
| 209 |
+
st.session_state["brief_ticker"] = ticker_input
|
| 210 |
+
return persisted
|
| 211 |
return None
|
| 212 |
|
| 213 |
|
|
|
|
| 328 |
return ""
|
| 329 |
|
| 330 |
pct = {k: round(v * 100 / total) for k, v in counts.items()}
|
| 331 |
+
colors = {"HIGH": GREEN, "MEDIUM": AMBER, "LOW": "#707b8a"}
|
| 332 |
segments = "".join(
|
| 333 |
f'<span style="display:inline-block;height:100%;width:{pct[k]}%;background:{colors[k]};"></span>'
|
| 334 |
for k in ("HIGH", "MEDIUM", "LOW") if pct[k] > 0
|
|
|
|
| 338 |
f'<span title="{t("sources_prefix")} {title}" style="display:inline-flex;align-items:center;gap:5px;">'
|
| 339 |
f'<span style="font-size:0.68rem;color:{TEXT_FAINT};">{t("sources_prefix")}</span>'
|
| 340 |
f'<span style="display:inline-block;width:60px;height:7px;border-radius:4px;overflow:hidden;'
|
| 341 |
+
f'background:#2b323c;">{segments}</span>'
|
| 342 |
f'</span>'
|
| 343 |
)
|
| 344 |
|
|
|
|
| 385 |
color = GREEN if d1 >= 0 else RED
|
| 386 |
prefix = "+" if d1 >= 0 else ""
|
| 387 |
d1_html = (
|
| 388 |
+
f'<span style="background:{"#10251d" if d1 >= 0 else "#2a1416"};'
|
| 389 |
f'color:{color};border:1px solid {color}33;'
|
| 390 |
f'border-radius:4px;padding:2px 8px;font-size:0.75rem;font-weight:600;">'
|
| 391 |
f'D1 {prefix}{d1:.1f}%</span>'
|
|
|
|
| 414 |
)
|
| 415 |
|
| 416 |
# Dot separator helper
|
| 417 |
+
sep = f'<span style="color:#3a424e;font-size:0.7rem;">·</span>'
|
| 418 |
|
| 419 |
inner_parts = [
|
| 420 |
+
f'<span style="font-weight:700;font-size:0.9rem;color:#e8eef5;">{ticker}</span>',
|
| 421 |
+
f'<span style="font-size:0.82rem;color:#c3ccd6;">{company}</span>',
|
| 422 |
]
|
| 423 |
if date_html:
|
| 424 |
inner_parts.append(date_html)
|
|
|
|
| 526 |
pct = int(progress_val * 100)
|
| 527 |
ticker_label = gen.get("ticker", "")
|
| 528 |
st.markdown(
|
| 529 |
+
f'<div style="background:#151a21;border:1px solid #2b323c;border-radius:12px;'
|
| 530 |
f'padding:16px 20px;margin-bottom:16px;">'
|
| 531 |
f'<div style="display:flex;justify-content:space-between;align-items:baseline;margin-bottom:4px;">'
|
| 532 |
+
f'<div style="font-size:0.88rem;font-weight:600;color:#e8eef5;">'
|
| 533 |
+
f'{t("generating_brief")} — <code style="background:#1a2029;padding:1px 7px;border-radius:5px;font-size:0.82rem;">{ticker_label}</code>'
|
| 534 |
f'</div>'
|
| 535 |
+
f'<div style="font-size:1rem;font-weight:700;color:#34d399;">{pct}%</div>'
|
| 536 |
f'</div>'
|
| 537 |
+
f'<div style="font-size:0.75rem;color:#8a95a3;margin-bottom:10px;">{progress_label}</div>'
|
| 538 |
+
f'<div style="background:#2b323c;border-radius:999px;height:7px;overflow:hidden;">'
|
| 539 |
+
f'<div style="background:linear-gradient(90deg,#34d399,#10b981);height:100%;'
|
| 540 |
f'width:{pct}%;border-radius:999px;transition:width 0.4s ease;"></div>'
|
| 541 |
f'</div>'
|
| 542 |
f'</div>',
|
|
|
|
| 642 |
if profile is None:
|
| 643 |
st.markdown(
|
| 644 |
f"""
|
| 645 |
+
<div style="text-align:center;padding:48px 0;color:#8a95a3;">
|
| 646 |
<div style="width:32px;height:32px;margin:0 auto 12px;border-radius:8px;
|
| 647 |
+
background:#10251d;border:1px solid #1f5b45;"></div>
|
| 648 |
+
<div style="font-size:1.1rem;font-weight:600;margin-bottom:6px;color:#e8eef5;">{t("overview_empty_title")}</div>
|
| 649 |
<div style="font-size:0.9rem;">{t("overview_empty_body")}</div>
|
| 650 |
</div>
|
| 651 |
""",
|
|
|
|
| 693 |
st.caption(market_error)
|
| 694 |
|
| 695 |
|
| 696 |
+
def _render_landing(coverage: list[dict]) -> None:
|
| 697 |
+
"""First screen for a visitor with no ticker selected.
|
| 698 |
+
|
| 699 |
+
The previous version was a single sentence over an empty green square: it
|
| 700 |
+
never said what a brief actually contains, and the only thing a newcomer
|
| 701 |
+
could click — the saved-brief list — sat below the fold in the sidebar.
|
| 702 |
+
This states the promise, names the five sections, and puts the saved briefs
|
| 703 |
+
front and centre so the app can be seen working without waiting for a run.
|
| 704 |
+
"""
|
| 705 |
+
from dashboard.theme import (
|
| 706 |
+
BG, BORDER, TEXT, TEXT_MUTED, TEXT_FAINT, BRAND_GREEN, AI_COLOR,
|
| 707 |
+
)
|
| 708 |
+
|
| 709 |
+
st.markdown(
|
| 710 |
+
f"""
|
| 711 |
+
<div style="max-width:720px;margin:36px 0 28px;">
|
| 712 |
+
<div style="font-size:1.75rem;font-weight:700;color:{TEXT};
|
| 713 |
+
letter-spacing:-0.02em;line-height:1.25;margin-bottom:12px;">
|
| 714 |
+
{t("landing_title")}
|
| 715 |
+
</div>
|
| 716 |
+
<div style="font-size:0.95rem;color:{TEXT_MUTED};line-height:1.65;">
|
| 717 |
+
{t("landing_body")}
|
| 718 |
+
</div>
|
| 719 |
+
</div>
|
| 720 |
+
""",
|
| 721 |
+
unsafe_allow_html=True,
|
| 722 |
+
)
|
| 723 |
+
|
| 724 |
+
# ── What you get — one card per destination, in nav order ────────────────
|
| 725 |
+
st.markdown(
|
| 726 |
+
f'<div style="font-size:0.6rem;font-weight:700;text-transform:uppercase;'
|
| 727 |
+
f'letter-spacing:0.1em;color:{TEXT_FAINT};margin:8px 0 10px;">'
|
| 728 |
+
f'{t("landing_sections_title")}</div>',
|
| 729 |
+
unsafe_allow_html=True,
|
| 730 |
+
)
|
| 731 |
+
cards = [
|
| 732 |
+
("nav_company", "landing_card_company", BRAND_GREEN),
|
| 733 |
+
("nav_verdict", "landing_card_verdict", BRAND_GREEN),
|
| 734 |
+
("nav_signals", "landing_card_signals", BRAND_GREEN),
|
| 735 |
+
("nav_financials", "landing_card_financials", BRAND_GREEN),
|
| 736 |
+
("nav_chat", "landing_card_chat", AI_COLOR),
|
| 737 |
+
]
|
| 738 |
+
cols = st.columns(len(cards), gap="small")
|
| 739 |
+
for col, (label_key, body_key, accent) in zip(cols, cards):
|
| 740 |
+
with col:
|
| 741 |
+
st.markdown(
|
| 742 |
+
f'<div style="background:{BG};border:1px solid {BORDER};'
|
| 743 |
+
f'border-left:3px solid {accent};border-radius:10px;'
|
| 744 |
+
f'padding:14px 16px;height:100%;min-height:150px;">'
|
| 745 |
+
f'<div style="font-size:0.85rem;font-weight:600;color:{TEXT};'
|
| 746 |
+
f'margin-bottom:7px;">{t(label_key)}</div>'
|
| 747 |
+
f'<div style="font-size:0.78rem;color:{TEXT_MUTED};line-height:1.55;">'
|
| 748 |
+
f'{t(body_key)}</div>'
|
| 749 |
+
f'</div>',
|
| 750 |
+
unsafe_allow_html=True,
|
| 751 |
+
)
|
| 752 |
+
|
| 753 |
+
# ── Saved briefs — the fastest path to seeing real output ────────────────
|
| 754 |
+
st.markdown(
|
| 755 |
+
f'<div style="font-size:0.6rem;font-weight:700;text-transform:uppercase;'
|
| 756 |
+
f'letter-spacing:0.1em;color:{TEXT_FAINT};margin:30px 0 6px;">'
|
| 757 |
+
f'{t("landing_start_title")}</div>',
|
| 758 |
+
unsafe_allow_html=True,
|
| 759 |
+
)
|
| 760 |
+
if not coverage:
|
| 761 |
+
st.caption(t("landing_start_empty"))
|
| 762 |
+
return
|
| 763 |
+
st.markdown(
|
| 764 |
+
f'<div style="font-size:0.82rem;color:{TEXT_MUTED};margin-bottom:12px;">'
|
| 765 |
+
f'{t("landing_start_body")}</div>',
|
| 766 |
+
unsafe_allow_html=True,
|
| 767 |
+
)
|
| 768 |
+
# Cap the row so a long coverage list cannot stretch the buttons to slivers.
|
| 769 |
+
row = coverage[:6]
|
| 770 |
+
for col, entry in zip(st.columns(max(len(row), 3), gap="small"), row):
|
| 771 |
+
with col:
|
| 772 |
+
label = (
|
| 773 |
+
f'{entry["ticker"]} · {entry["filing_date"]}'
|
| 774 |
+
if entry.get("filing_date") else entry["ticker"]
|
| 775 |
+
)
|
| 776 |
+
if st.button(label, key=f'landing_cov_{entry["ticker"]}',
|
| 777 |
+
use_container_width=True):
|
| 778 |
+
st.session_state["_pending_ticker"] = entry["ticker"]
|
| 779 |
+
st.rerun()
|
| 780 |
+
|
| 781 |
+
|
| 782 |
gen_error = st.session_state.pop("_gen_error", None)
|
| 783 |
if gen_error:
|
| 784 |
err_ticker, err_msg = gen_error
|
|
|
|
| 790 |
if gen["running"] or gen.get("trace"):
|
| 791 |
_live_trace_fragment()
|
| 792 |
elif not ticker_input:
|
| 793 |
+
_render_landing(_coverage)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 794 |
else:
|
| 795 |
# Active ticker, not generating — show context bar then route to section
|
| 796 |
brief = _get_display_brief(_get_cached_brief(), ticker_input, run_cfg)
|
|
|
|
| 806 |
else:
|
| 807 |
st.markdown(
|
| 808 |
f"""
|
| 809 |
+
<div style="text-align:center;padding:48px 0;color:#8a95a3;">
|
| 810 |
<div style="width:32px;height:32px;margin:0 auto 12px;border-radius:8px;
|
| 811 |
+
background:#10251d;border:1px solid #1f5b45;"></div>
|
| 812 |
+
<div style="font-size:1.1rem;font-weight:600;margin-bottom:6px;color:#e8eef5;">{t("snapshot_empty_title")}</div>
|
| 813 |
<div style="font-size:0.9rem;">{t("snapshot_empty_body")}</div>
|
| 814 |
</div>
|
| 815 |
""",
|
|
|
|
| 831 |
# ── Global data disclaimer ─────────────────────────────────────────────────────
|
| 832 |
if ticker_input and not gen.get("running") and not gen.get("trace"):
|
| 833 |
st.markdown(
|
| 834 |
+
f'<div style="margin-top:40px;border-top:1px solid #2b323c;padding-top:12px;'
|
| 835 |
+
f'font-size:0.72rem;color:#707b8a;line-height:1.5;">'
|
| 836 |
f'{t("disclaimer")}'
|
| 837 |
f'</div>',
|
| 838 |
unsafe_allow_html=True,
|
|
@@ -272,7 +272,7 @@ def _svg(state: dict) -> str:
|
|
| 272 |
|
| 273 |
# ── Signals node ─────────────────────────────────────────────────────────
|
| 274 |
if is_signals_phase:
|
| 275 |
-
sf, ss, st_ = BRAND_GREEN, BRAND_GREEN_DARK, "#
|
| 276 |
else:
|
| 277 |
sf, ss, st_ = BG_MUTED, BORDER_STRONG, TEXT_MUTED
|
| 278 |
p.append(_rect(_SIG_CX - _PILL_W // 2, _SIG_CY - _PILL_H // 2,
|
|
@@ -293,7 +293,7 @@ def _svg(state: dict) -> str:
|
|
| 293 |
|
| 294 |
# ── Synthesis node ────────────────────────────────────────────────────────
|
| 295 |
if is_synthesis_active:
|
| 296 |
-
yf, ys, yt_ = BRAND_GREEN, BRAND_GREEN_DARK, "#
|
| 297 |
elif is_synthesis_done:
|
| 298 |
yf, ys, yt_ = BULL_BG, BULL_BORDER, GREEN
|
| 299 |
else:
|
|
@@ -308,7 +308,7 @@ def _svg(state: dict) -> str:
|
|
| 308 |
ty = tcy - _TOOL_H // 2
|
| 309 |
|
| 310 |
if name in active:
|
| 311 |
-
tf, ts, tt_, tsw = BRAND_GREEN, BRAND_GREEN_DARK, "#
|
| 312 |
fw = 700
|
| 313 |
elif name in used:
|
| 314 |
tf, ts, tt_, tsw = BULL_BG, BULL_BORDER, GREEN, 1.5
|
|
|
|
| 272 |
|
| 273 |
# ── Signals node ─────────────────────────────────────────────────────────
|
| 274 |
if is_signals_phase:
|
| 275 |
+
sf, ss, st_ = BRAND_GREEN, BRAND_GREEN_DARK, "#151a21"
|
| 276 |
else:
|
| 277 |
sf, ss, st_ = BG_MUTED, BORDER_STRONG, TEXT_MUTED
|
| 278 |
p.append(_rect(_SIG_CX - _PILL_W // 2, _SIG_CY - _PILL_H // 2,
|
|
|
|
| 293 |
|
| 294 |
# ── Synthesis node ────────────────────────────────────────────────────────
|
| 295 |
if is_synthesis_active:
|
| 296 |
+
yf, ys, yt_ = BRAND_GREEN, BRAND_GREEN_DARK, "#151a21"
|
| 297 |
elif is_synthesis_done:
|
| 298 |
yf, ys, yt_ = BULL_BG, BULL_BORDER, GREEN
|
| 299 |
else:
|
|
|
|
| 308 |
ty = tcy - _TOOL_H // 2
|
| 309 |
|
| 310 |
if name in active:
|
| 311 |
+
tf, ts, tt_, tsw = BRAND_GREEN, BRAND_GREEN_DARK, "#151a21", 2.0
|
| 312 |
fw = 700
|
| 313 |
elif name in used:
|
| 314 |
tf, ts, tt_, tsw = BULL_BG, BULL_BORDER, GREEN, 1.5
|
|
@@ -9,6 +9,7 @@ from __future__ import annotations
|
|
| 9 |
import streamlit as st
|
| 10 |
|
| 11 |
from agent.llm import RunConfig, classify_llm_error
|
|
|
|
| 12 |
from dashboard.theme import (
|
| 13 |
BORDER,
|
| 14 |
BG_MUTED,
|
|
@@ -34,10 +35,35 @@ _TOOL_LABELS: dict[str, str] = {
|
|
| 34 |
}
|
| 35 |
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
def _watch_to_question(item: str) -> str:
|
| 38 |
"""Reword a `what_to_watch` item into a chat question (pure, no LLM call)."""
|
| 39 |
-
|
| 40 |
-
return f'What do the filings and transcript say about: "{item}"?'
|
| 41 |
|
| 42 |
|
| 43 |
def _searched_labels(sources: list[dict]) -> list[str]:
|
|
@@ -107,7 +133,7 @@ def render(ticker: str, brief: dict | None = None, config: RunConfig | None = No
|
|
| 107 |
for msg in history:
|
| 108 |
role = msg["role"]
|
| 109 |
with st.chat_message(role):
|
| 110 |
-
st.markdown(msg["content"])
|
| 111 |
if role == "assistant":
|
| 112 |
if msg.get("sources"):
|
| 113 |
_render_sources_expander(msg["sources"])
|
|
@@ -136,7 +162,7 @@ def render(ticker: str, brief: dict | None = None, config: RunConfig | None = No
|
|
| 136 |
# Display the user message immediately.
|
| 137 |
history.append({"role": "user", "content": question})
|
| 138 |
with st.chat_message("user"):
|
| 139 |
-
st.markdown(question)
|
| 140 |
|
| 141 |
# Call the chat agent and stream the answer.
|
| 142 |
searched: list[str] = []
|
|
@@ -155,7 +181,7 @@ def render(ticker: str, brief: dict | None = None, config: RunConfig | None = No
|
|
| 155 |
answer = f'⚠️ {friendly or t("chat_error").format(error=f"`{exc}`")}'
|
| 156 |
sources = []
|
| 157 |
|
| 158 |
-
st.markdown(answer)
|
| 159 |
if sources:
|
| 160 |
_render_sources_expander(sources)
|
| 161 |
if searched:
|
|
|
|
| 9 |
import streamlit as st
|
| 10 |
|
| 11 |
from agent.llm import RunConfig, classify_llm_error
|
| 12 |
+
from dashboard.components import escape_dollars
|
| 13 |
from dashboard.theme import (
|
| 14 |
BORDER,
|
| 15 |
BG_MUTED,
|
|
|
|
| 35 |
}
|
| 36 |
|
| 37 |
|
| 38 |
+
# A watch item is a full monitoring instruction — routinely three sentences with
|
| 39 |
+
# guidance ranges and quoted management commentary. Embedding one whole turned
|
| 40 |
+
# each suggested-question chip into a five-line paragraph.
|
| 41 |
+
_WATCH_SUBJECT_CHARS = 72
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def _watch_subject(item: str) -> str:
|
| 45 |
+
"""Reduce a watch item to the thing being watched.
|
| 46 |
+
|
| 47 |
+
Watch items are written as "<subject>: <what to monitor and why>", so the
|
| 48 |
+
text before the first colon is the subject. Failing that, take the first
|
| 49 |
+
sentence, then hard-cap on a word boundary.
|
| 50 |
+
"""
|
| 51 |
+
text = " ".join(item.split()).strip().rstrip(".")
|
| 52 |
+
for separator in (":", "."):
|
| 53 |
+
head = text.split(separator, 1)[0].strip()
|
| 54 |
+
# Ignore a separator that fires inside a number or an abbreviation.
|
| 55 |
+
if 8 <= len(head) < len(text):
|
| 56 |
+
text = head
|
| 57 |
+
break
|
| 58 |
+
if len(text) <= _WATCH_SUBJECT_CHARS:
|
| 59 |
+
return text
|
| 60 |
+
cut = text.rfind(" ", 0, _WATCH_SUBJECT_CHARS)
|
| 61 |
+
return (text[:cut] if cut > 0 else text[:_WATCH_SUBJECT_CHARS]).rstrip(",;") + "…"
|
| 62 |
+
|
| 63 |
+
|
| 64 |
def _watch_to_question(item: str) -> str:
|
| 65 |
"""Reword a `what_to_watch` item into a chat question (pure, no LLM call)."""
|
| 66 |
+
return f'What do the filings and transcript say about: "{_watch_subject(item)}"?'
|
|
|
|
| 67 |
|
| 68 |
|
| 69 |
def _searched_labels(sources: list[dict]) -> list[str]:
|
|
|
|
| 133 |
for msg in history:
|
| 134 |
role = msg["role"]
|
| 135 |
with st.chat_message(role):
|
| 136 |
+
st.markdown(escape_dollars(msg["content"]))
|
| 137 |
if role == "assistant":
|
| 138 |
if msg.get("sources"):
|
| 139 |
_render_sources_expander(msg["sources"])
|
|
|
|
| 162 |
# Display the user message immediately.
|
| 163 |
history.append({"role": "user", "content": question})
|
| 164 |
with st.chat_message("user"):
|
| 165 |
+
st.markdown(escape_dollars(question))
|
| 166 |
|
| 167 |
# Call the chat agent and stream the answer.
|
| 168 |
searched: list[str] = []
|
|
|
|
| 181 |
answer = f'⚠️ {friendly or t("chat_error").format(error=f"`{exc}`")}'
|
| 182 |
sources = []
|
| 183 |
|
| 184 |
+
st.markdown(escape_dollars(answer))
|
| 185 |
if sources:
|
| 186 |
_render_sources_expander(sources)
|
| 187 |
if searched:
|
|
@@ -52,7 +52,9 @@ def _page_header(profile: dict, market: dict | None) -> None:
|
|
| 52 |
ticker = escape(str(profile.get("ticker") or ""))
|
| 53 |
sector = escape(str((market or {}).get("sector") or ""))
|
| 54 |
industry = escape(str((market or {}).get("industry") or ""))
|
| 55 |
-
|
|
|
|
|
|
|
| 56 |
meta = " · ".join(value for value in (ticker, sector, industry, as_of) if value)
|
| 57 |
st.markdown(
|
| 58 |
f'<div style="margin-bottom:18px;">'
|
|
@@ -64,13 +66,12 @@ def _page_header(profile: dict, market: dict | None) -> None:
|
|
| 64 |
)
|
| 65 |
|
| 66 |
|
| 67 |
-
def _identity(profile: dict) -> None:
|
| 68 |
identity = profile.get("identity") or {}
|
| 69 |
one_liner = _fact_text(identity.get("one_liner"))
|
| 70 |
business_model = _fact_text(identity.get("business_model"))
|
| 71 |
if not one_liner and not business_model:
|
| 72 |
-
|
| 73 |
-
return
|
| 74 |
source = identity.get("one_liner") or identity.get("business_model")
|
| 75 |
body = "".join(
|
| 76 |
(
|
|
@@ -92,12 +93,11 @@ def _identity(profile: dict) -> None:
|
|
| 92 |
)
|
| 93 |
|
| 94 |
|
| 95 |
-
def _business(profile: dict) -> None:
|
| 96 |
-
st.markdown(section_header(t("primer_business"), accent=BRAND_GREEN), unsafe_allow_html=True)
|
| 97 |
lines = profile.get("business_lines") or []
|
| 98 |
if not lines:
|
| 99 |
-
|
| 100 |
-
|
| 101 |
|
| 102 |
shares = [
|
| 103 |
(str(item.get("name") or ""), item.get("revenue_share_pct"))
|
|
@@ -109,7 +109,7 @@ def _business(profile: dict) -> None:
|
|
| 109 |
import plotly.graph_objects as go
|
| 110 |
|
| 111 |
fig = go.Figure()
|
| 112 |
-
palette = ["#
|
| 113 |
for index, (name, value) in enumerate(shares):
|
| 114 |
fig.add_bar(
|
| 115 |
y=["Revenue mix"],
|
|
@@ -127,7 +127,7 @@ def _business(profile: dict) -> None:
|
|
| 127 |
x=[100 - total],
|
| 128 |
name=t("primer_other"),
|
| 129 |
orientation="h",
|
| 130 |
-
marker_color="#
|
| 131 |
hovertemplate=f"{t('primer_other')}: {100-total:.1f}%<extra></extra>",
|
| 132 |
)
|
| 133 |
fig.update_layout(
|
|
@@ -139,40 +139,50 @@ def _business(profile: dict) -> None:
|
|
| 139 |
showlegend=False,
|
| 140 |
xaxis=dict(range=[0, 100], visible=False),
|
| 141 |
yaxis=dict(visible=False),
|
| 142 |
-
font=dict(family="Inter"),
|
| 143 |
)
|
| 144 |
st.plotly_chart(fig, use_container_width=True, config={"displayModeBar": False})
|
| 145 |
|
| 146 |
-
|
|
|
|
|
|
|
|
|
|
| 147 |
for item in lines[:5]:
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
t("primer_role"): _fact_text(fact),
|
| 156 |
-
t("primer_share"): (
|
| 157 |
-
f"{float(item['revenue_share_pct']):.1f}% · {item.get('share_period') or ''}"
|
| 158 |
-
if item.get("revenue_share_pct") is not None
|
| 159 |
-
else t("primer_not_disclosed")
|
| 160 |
-
),
|
| 161 |
-
t("primer_trend"): t(
|
| 162 |
-
f"primer_trend_{item.get('trend') or 'not_disclosed'}"
|
| 163 |
-
),
|
| 164 |
-
t("primer_framing"): framing,
|
| 165 |
-
}
|
| 166 |
)
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
|
| 170 |
-
def _geography(profile: dict) -> None:
|
| 171 |
-
st.markdown(section_header(t("primer_geography"), accent=BLUE), unsafe_allow_html=True)
|
| 172 |
exposures = profile.get("geographic_exposures") or []
|
| 173 |
if not exposures:
|
| 174 |
-
|
| 175 |
-
|
| 176 |
|
| 177 |
quantitative = [
|
| 178 |
item for item in exposures if item.get("revenue_share_pct") is not None
|
|
@@ -182,7 +192,7 @@ def _geography(profile: dict) -> None:
|
|
| 182 |
import plotly.graph_objects as go
|
| 183 |
|
| 184 |
fig = go.Figure()
|
| 185 |
-
palette = ["#
|
| 186 |
for index, item in enumerate(quantitative):
|
| 187 |
value = float(item["revenue_share_pct"])
|
| 188 |
name = str(item.get("name") or "")
|
|
@@ -205,7 +215,7 @@ def _geography(profile: dict) -> None:
|
|
| 205 |
showlegend=False,
|
| 206 |
xaxis=dict(range=[0, max(100, total)], visible=False),
|
| 207 |
yaxis=dict(visible=False),
|
| 208 |
-
font=dict(family="Inter"),
|
| 209 |
)
|
| 210 |
st.plotly_chart(fig, use_container_width=True, config={"displayModeBar": False})
|
| 211 |
|
|
@@ -228,26 +238,28 @@ def _geography(profile: dict) -> None:
|
|
| 228 |
st.dataframe(rows, use_container_width=True, hide_index=True)
|
| 229 |
|
| 230 |
|
| 231 |
-
def _evolution(profile: dict) -> None:
|
| 232 |
-
st.markdown(section_header(t("primer_evolution"), accent=BRAND_GREEN), unsafe_allow_html=True)
|
| 233 |
trends = profile.get("annual_trends") or []
|
| 234 |
changes = profile.get("strategic_changes") or []
|
| 235 |
if not trends and not changes:
|
| 236 |
-
|
| 237 |
-
|
| 238 |
if trends:
|
| 239 |
from plotly.subplots import make_subplots
|
| 240 |
import plotly.graph_objects as go
|
| 241 |
|
| 242 |
periods = [str(item.get("period") or "") for item in trends]
|
|
|
|
|
|
|
|
|
|
| 243 |
specs = [
|
| 244 |
-
("revenue_bn", t("primer_revenue"), "$B", 1),
|
| 245 |
-
("operating_margin", t("primer_op_margin"), "%", 2),
|
| 246 |
-
("free_cash_flow_bn", t("primer_fcf"), "$B", 3),
|
| 247 |
-
("eps", "EPS", "$", 4),
|
| 248 |
]
|
| 249 |
fig = make_subplots(rows=2, cols=2, subplot_titles=[item[1] for item in specs])
|
| 250 |
-
for key, _label,
|
| 251 |
values = [item.get(key) for item in trends]
|
| 252 |
display_values = [
|
| 253 |
value * 100 if key == "operating_margin" and value is not None else value
|
|
@@ -259,7 +271,7 @@ def _evolution(profile: dict) -> None:
|
|
| 259 |
y=display_values,
|
| 260 |
mode="lines+markers+text",
|
| 261 |
text=[
|
| 262 |
-
f"{value:.1f}{
|
| 263 |
for value in display_values
|
| 264 |
],
|
| 265 |
textposition="top center",
|
|
@@ -271,15 +283,26 @@ def _evolution(profile: dict) -> None:
|
|
| 271 |
row=1 if col <= 2 else 2,
|
| 272 |
col=col if col <= 2 else col - 2,
|
| 273 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
fig.update_layout(
|
| 275 |
height=430,
|
| 276 |
margin=dict(l=20, r=20, t=45, b=20),
|
| 277 |
paper_bgcolor="rgba(0,0,0,0)",
|
| 278 |
plot_bgcolor="rgba(0,0,0,0)",
|
| 279 |
-
font=dict(family="Inter", size=11),
|
| 280 |
)
|
| 281 |
fig.update_xaxes(showgrid=False)
|
| 282 |
-
fig.update_yaxes(showgrid=True, gridcolor="#
|
| 283 |
st.plotly_chart(fig, use_container_width=True, config={"displayModeBar": False})
|
| 284 |
|
| 285 |
if changes:
|
|
@@ -296,12 +319,11 @@ def _evolution(profile: dict) -> None:
|
|
| 296 |
st.dataframe(rows, use_container_width=True, hide_index=True)
|
| 297 |
|
| 298 |
|
| 299 |
-
def _attention(profile: dict) -> None:
|
| 300 |
-
st.markdown(section_header(t("primer_attention"), accent=AI_COLOR), unsafe_allow_html=True)
|
| 301 |
themes = profile.get("attention_themes") or []
|
| 302 |
if not themes:
|
| 303 |
-
|
| 304 |
-
|
| 305 |
for item in themes[:3]:
|
| 306 |
mentions = item.get("call_mentions") or []
|
| 307 |
trajectory = " → ".join(
|
|
@@ -330,18 +352,17 @@ def _attention(profile: dict) -> None:
|
|
| 330 |
)
|
| 331 |
|
| 332 |
|
| 333 |
-
def _market(profile: dict, market: dict | None) -> None:
|
| 334 |
-
st.markdown(section_header(t("primer_price"), accent=BLUE), unsafe_allow_html=True)
|
| 335 |
if not market or not market.get("history"):
|
| 336 |
-
|
| 337 |
-
|
| 338 |
import plotly.graph_objects as go
|
| 339 |
|
| 340 |
history = market["history"]
|
| 341 |
ticker = str(market.get("ticker") or profile.get("ticker") or "")
|
| 342 |
benchmark = str(market.get("benchmark") or "SPY")
|
| 343 |
series = [ticker, "SPY"] + ([] if benchmark == "SPY" else [benchmark])
|
| 344 |
-
colors = {ticker: BRAND_GREEN, "SPY": "#
|
| 345 |
fig = go.Figure()
|
| 346 |
for symbol in series:
|
| 347 |
fig.add_trace(
|
|
@@ -350,7 +371,7 @@ def _market(profile: dict, market: dict | None) -> None:
|
|
| 350 |
y=[item.get(symbol) for item in history],
|
| 351 |
mode="lines",
|
| 352 |
name=symbol,
|
| 353 |
-
line=dict(color=colors.get(symbol, "#
|
| 354 |
hovertemplate=f"{symbol} %{{y:.1f}}<extra></extra>",
|
| 355 |
)
|
| 356 |
)
|
|
@@ -380,7 +401,7 @@ def _market(profile: dict, market: dict | None) -> None:
|
|
| 380 |
event_dates.append(nearest["date"])
|
| 381 |
event_values.append(nearest[ticker])
|
| 382 |
event_symbols.append("triangle-up" if excess >= 0 else "triangle-down")
|
| 383 |
-
event_colors.append(BRAND_GREEN if excess >= 0 else "#
|
| 384 |
headline_text = (
|
| 385 |
t("primer_no_verified_catalyst")
|
| 386 |
if event.get("attribution_status") == "NO_VERIFIED_CATALYST"
|
|
@@ -414,13 +435,13 @@ def _market(profile: dict, market: dict | None) -> None:
|
|
| 414 |
margin=dict(l=20, r=20, t=10, b=20),
|
| 415 |
paper_bgcolor="rgba(0,0,0,0)",
|
| 416 |
plot_bgcolor="rgba(0,0,0,0)",
|
| 417 |
-
font=dict(family="Inter"),
|
| 418 |
legend=dict(orientation="h", y=1.05, x=0),
|
| 419 |
yaxis_title=t("primer_indexed_100"),
|
| 420 |
hovermode="x unified",
|
| 421 |
)
|
| 422 |
fig.update_xaxes(showgrid=False)
|
| 423 |
-
fig.update_yaxes(gridcolor="#
|
| 424 |
st.plotly_chart(fig, use_container_width=True, config={"displayModeBar": False})
|
| 425 |
st.caption(t("primer_price_caption").format(benchmark=benchmark))
|
| 426 |
|
|
@@ -450,15 +471,44 @@ def _market(profile: dict, market: dict | None) -> None:
|
|
| 450 |
)
|
| 451 |
|
| 452 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 453 |
def _news(news_items: list[dict], news_error: str | None) -> None:
|
| 454 |
st.markdown(section_header(t("primer_news"), accent=BLUE), unsafe_allow_html=True)
|
| 455 |
if not news_items:
|
| 456 |
st.info(news_error or t("primer_news_unavailable"))
|
| 457 |
return
|
| 458 |
-
|
|
|
|
|
|
|
|
|
|
| 459 |
title = escape(str(item.get("title") or ""))
|
| 460 |
url = escape(str(item.get("url") or ""))
|
| 461 |
-
date = escape(
|
| 462 |
st.markdown(
|
| 463 |
f'<div style="padding:9px 0;border-bottom:1px solid {BORDER};">'
|
| 464 |
f'<div style="font-size:{FS_META};color:{TEXT_MUTED};">{date}</div>'
|
|
@@ -468,22 +518,54 @@ def _news(news_items: list[dict], news_error: str | None) -> None:
|
|
| 468 |
)
|
| 469 |
|
| 470 |
|
| 471 |
-
def _watch(profile: dict) -> None:
|
| 472 |
-
st.markdown(section_header(t("primer_watch"), accent="#f59e0b"), unsafe_allow_html=True)
|
| 473 |
values = profile.get("watch_variables") or []
|
| 474 |
if not values:
|
| 475 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 476 |
return
|
| 477 |
-
|
| 478 |
-
{
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
}
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
|
|
|
|
|
|
| 487 |
|
| 488 |
|
| 489 |
def render(
|
|
@@ -495,14 +577,24 @@ def render(
|
|
| 495 |
news_error: str | None = None,
|
| 496 |
) -> None:
|
| 497 |
_page_header(profile, market)
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 504 |
_news(news_items or [], news_error)
|
| 505 |
-
_watch(profile)
|
|
|
|
|
|
|
|
|
|
| 506 |
|
| 507 |
coverage = profile.get("source_coverage") or {}
|
| 508 |
with st.expander(t("primer_sources"), expanded=False):
|
|
|
|
| 52 |
ticker = escape(str(profile.get("ticker") or ""))
|
| 53 |
sector = escape(str((market or {}).get("sector") or ""))
|
| 54 |
industry = escape(str((market or {}).get("industry") or ""))
|
| 55 |
+
# data_as_of is stored as a full ISO timestamp; the header only ever wants
|
| 56 |
+
# the calendar date — the time and offset read as a bug to a reader.
|
| 57 |
+
as_of = escape(str(profile.get("data_as_of") or "")[:10])
|
| 58 |
meta = " · ".join(value for value in (ticker, sector, industry, as_of) if value)
|
| 59 |
st.markdown(
|
| 60 |
f'<div style="margin-bottom:18px;">'
|
|
|
|
| 66 |
)
|
| 67 |
|
| 68 |
|
| 69 |
+
def _identity(profile: dict) -> str | None:
|
| 70 |
identity = profile.get("identity") or {}
|
| 71 |
one_liner = _fact_text(identity.get("one_liner"))
|
| 72 |
business_model = _fact_text(identity.get("business_model"))
|
| 73 |
if not one_liner and not business_model:
|
| 74 |
+
return t("primer_identity")
|
|
|
|
| 75 |
source = identity.get("one_liner") or identity.get("business_model")
|
| 76 |
body = "".join(
|
| 77 |
(
|
|
|
|
| 93 |
)
|
| 94 |
|
| 95 |
|
| 96 |
+
def _business(profile: dict) -> str | None:
|
|
|
|
| 97 |
lines = profile.get("business_lines") or []
|
| 98 |
if not lines:
|
| 99 |
+
return t("primer_business")
|
| 100 |
+
st.markdown(section_header(t("primer_business"), accent=BRAND_GREEN), unsafe_allow_html=True)
|
| 101 |
|
| 102 |
shares = [
|
| 103 |
(str(item.get("name") or ""), item.get("revenue_share_pct"))
|
|
|
|
| 109 |
import plotly.graph_objects as go
|
| 110 |
|
| 111 |
fig = go.Figure()
|
| 112 |
+
palette = ["#34d399", "#60a5fa", "#a78bfa", "#fbbf24", "#7b8593"]
|
| 113 |
for index, (name, value) in enumerate(shares):
|
| 114 |
fig.add_bar(
|
| 115 |
y=["Revenue mix"],
|
|
|
|
| 127 |
x=[100 - total],
|
| 128 |
name=t("primer_other"),
|
| 129 |
orientation="h",
|
| 130 |
+
marker_color="#3a424e",
|
| 131 |
hovertemplate=f"{t('primer_other')}: {100-total:.1f}%<extra></extra>",
|
| 132 |
)
|
| 133 |
fig.update_layout(
|
|
|
|
| 139 |
showlegend=False,
|
| 140 |
xaxis=dict(range=[0, 100], visible=False),
|
| 141 |
yaxis=dict(visible=False),
|
| 142 |
+
font=dict(family="Inter", color=TEXT_MUTED),
|
| 143 |
)
|
| 144 |
st.plotly_chart(fig, use_container_width=True, config={"displayModeBar": False})
|
| 145 |
|
| 146 |
+
# These cells hold whole sentences, and st.dataframe clipped them mid-word
|
| 147 |
+
# ("Included in 'Products' revenue categ"). Rendered as rows, the prose
|
| 148 |
+
# wraps and the numbers still line up.
|
| 149 |
+
cards: list[str] = []
|
| 150 |
for item in lines[:5]:
|
| 151 |
+
name = escape(str(item.get("name") or ""))
|
| 152 |
+
role = escape(_fact_text(item.get("description") or {}))
|
| 153 |
+
economics = escape(str(item.get("economics") or ""))
|
| 154 |
+
share = (
|
| 155 |
+
f"{float(item['revenue_share_pct']):.1f}%"
|
| 156 |
+
if item.get("revenue_share_pct") is not None
|
| 157 |
+
else escape(t("primer_not_disclosed"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
)
|
| 159 |
+
share_period = escape(str(item.get("share_period") or ""))
|
| 160 |
+
trend = escape(t(f"primer_trend_{item.get('trend') or 'not_disclosed'}"))
|
| 161 |
+
cards.append(
|
| 162 |
+
f'<div style="display:flex;gap:16px;align-items:flex-start;padding:13px 0;'
|
| 163 |
+
f'border-bottom:1px solid {BORDER};">'
|
| 164 |
+
f'<div style="flex:0 0 150px;">'
|
| 165 |
+
f'<div style="font-size:{FS_BODY};font-weight:650;color:{TEXT};">{name}</div>'
|
| 166 |
+
f'<div style="font-size:{FS_META};color:{TEXT_MUTED};margin-top:3px;">'
|
| 167 |
+
f'{share}{f" · {share_period}" if share_period else ""}</div>'
|
| 168 |
+
f'<div style="font-size:{FS_META};color:{TEXT_MUTED};">{trend}</div>'
|
| 169 |
+
f'</div>'
|
| 170 |
+
f'<div style="flex:1;min-width:0;">'
|
| 171 |
+
f'<div style="font-size:{FS_BODY};line-height:1.55;color:{TEXT};">{role}</div>'
|
| 172 |
+
+ (
|
| 173 |
+
f'<div style="font-size:{FS_META};line-height:1.5;color:{AI_COLOR};'
|
| 174 |
+
f'margin-top:5px;">AI · {economics}</div>' if economics else ""
|
| 175 |
+
)
|
| 176 |
+
+ f'</div></div>'
|
| 177 |
+
)
|
| 178 |
+
st.markdown("".join(cards), unsafe_allow_html=True)
|
| 179 |
|
| 180 |
|
| 181 |
+
def _geography(profile: dict) -> str | None:
|
|
|
|
| 182 |
exposures = profile.get("geographic_exposures") or []
|
| 183 |
if not exposures:
|
| 184 |
+
return t("primer_geography")
|
| 185 |
+
st.markdown(section_header(t("primer_geography"), accent=BLUE), unsafe_allow_html=True)
|
| 186 |
|
| 187 |
quantitative = [
|
| 188 |
item for item in exposures if item.get("revenue_share_pct") is not None
|
|
|
|
| 192 |
import plotly.graph_objects as go
|
| 193 |
|
| 194 |
fig = go.Figure()
|
| 195 |
+
palette = ["#60a5fa", "#34d399", "#a78bfa", "#fbbf24", "#7b8593"]
|
| 196 |
for index, item in enumerate(quantitative):
|
| 197 |
value = float(item["revenue_share_pct"])
|
| 198 |
name = str(item.get("name") or "")
|
|
|
|
| 215 |
showlegend=False,
|
| 216 |
xaxis=dict(range=[0, max(100, total)], visible=False),
|
| 217 |
yaxis=dict(visible=False),
|
| 218 |
+
font=dict(family="Inter", color=TEXT_MUTED),
|
| 219 |
)
|
| 220 |
st.plotly_chart(fig, use_container_width=True, config={"displayModeBar": False})
|
| 221 |
|
|
|
|
| 238 |
st.dataframe(rows, use_container_width=True, hide_index=True)
|
| 239 |
|
| 240 |
|
| 241 |
+
def _evolution(profile: dict) -> str | None:
|
|
|
|
| 242 |
trends = profile.get("annual_trends") or []
|
| 243 |
changes = profile.get("strategic_changes") or []
|
| 244 |
if not trends and not changes:
|
| 245 |
+
return t("primer_evolution")
|
| 246 |
+
st.markdown(section_header(t("primer_evolution"), accent=BRAND_GREEN), unsafe_allow_html=True)
|
| 247 |
if trends:
|
| 248 |
from plotly.subplots import make_subplots
|
| 249 |
import plotly.graph_objects as go
|
| 250 |
|
| 251 |
periods = [str(item.get("period") or "") for item in trends]
|
| 252 |
+
# (key, label, prefix, suffix, column) — the currency sign leads the
|
| 253 |
+
# number and the percent sign trails it; a single "unit" suffix rendered
|
| 254 |
+
# revenue as "383.3$B".
|
| 255 |
specs = [
|
| 256 |
+
("revenue_bn", t("primer_revenue"), "$", "B", 1),
|
| 257 |
+
("operating_margin", t("primer_op_margin"), "", "%", 2),
|
| 258 |
+
("free_cash_flow_bn", t("primer_fcf"), "$", "B", 3),
|
| 259 |
+
("eps", "EPS", "$", "", 4),
|
| 260 |
]
|
| 261 |
fig = make_subplots(rows=2, cols=2, subplot_titles=[item[1] for item in specs])
|
| 262 |
+
for key, _label, prefix, suffix, col in specs:
|
| 263 |
values = [item.get(key) for item in trends]
|
| 264 |
display_values = [
|
| 265 |
value * 100 if key == "operating_margin" and value is not None else value
|
|
|
|
| 271 |
y=display_values,
|
| 272 |
mode="lines+markers+text",
|
| 273 |
text=[
|
| 274 |
+
f"{prefix}{value:.1f}{suffix}" if value is not None else ""
|
| 275 |
for value in display_values
|
| 276 |
],
|
| 277 |
textposition="top center",
|
|
|
|
| 283 |
row=1 if col <= 2 else 2,
|
| 284 |
col=col if col <= 2 else col - 2,
|
| 285 |
)
|
| 286 |
+
# Each point carries its value as a label drawn above the marker, so
|
| 287 |
+
# plotly's auto-range clips the highest one. Pad the band explicitly.
|
| 288 |
+
plotted = [value for value in display_values if value is not None]
|
| 289 |
+
if plotted:
|
| 290 |
+
low, high = min(plotted), max(plotted)
|
| 291 |
+
pad = (high - low) * 0.28 or (abs(high) * 0.12 or 1.0)
|
| 292 |
+
fig.update_yaxes(
|
| 293 |
+
range=[low - pad * 0.45, high + pad],
|
| 294 |
+
row=1 if col <= 2 else 2,
|
| 295 |
+
col=col if col <= 2 else col - 2,
|
| 296 |
+
)
|
| 297 |
fig.update_layout(
|
| 298 |
height=430,
|
| 299 |
margin=dict(l=20, r=20, t=45, b=20),
|
| 300 |
paper_bgcolor="rgba(0,0,0,0)",
|
| 301 |
plot_bgcolor="rgba(0,0,0,0)",
|
| 302 |
+
font=dict(family="Inter", size=11, color=TEXT_MUTED),
|
| 303 |
)
|
| 304 |
fig.update_xaxes(showgrid=False)
|
| 305 |
+
fig.update_yaxes(showgrid=True, gridcolor="#2b323c", zeroline=False)
|
| 306 |
st.plotly_chart(fig, use_container_width=True, config={"displayModeBar": False})
|
| 307 |
|
| 308 |
if changes:
|
|
|
|
| 319 |
st.dataframe(rows, use_container_width=True, hide_index=True)
|
| 320 |
|
| 321 |
|
| 322 |
+
def _attention(profile: dict) -> str | None:
|
|
|
|
| 323 |
themes = profile.get("attention_themes") or []
|
| 324 |
if not themes:
|
| 325 |
+
return t("primer_attention")
|
| 326 |
+
st.markdown(section_header(t("primer_attention"), accent=AI_COLOR), unsafe_allow_html=True)
|
| 327 |
for item in themes[:3]:
|
| 328 |
mentions = item.get("call_mentions") or []
|
| 329 |
trajectory = " → ".join(
|
|
|
|
| 352 |
)
|
| 353 |
|
| 354 |
|
| 355 |
+
def _market(profile: dict, market: dict | None) -> str | None:
|
|
|
|
| 356 |
if not market or not market.get("history"):
|
| 357 |
+
return t("primer_price")
|
| 358 |
+
st.markdown(section_header(t("primer_price"), accent=BLUE), unsafe_allow_html=True)
|
| 359 |
import plotly.graph_objects as go
|
| 360 |
|
| 361 |
history = market["history"]
|
| 362 |
ticker = str(market.get("ticker") or profile.get("ticker") or "")
|
| 363 |
benchmark = str(market.get("benchmark") or "SPY")
|
| 364 |
series = [ticker, "SPY"] + ([] if benchmark == "SPY" else [benchmark])
|
| 365 |
+
colors = {ticker: BRAND_GREEN, "SPY": "#7b8593", benchmark: "#60a5fa"}
|
| 366 |
fig = go.Figure()
|
| 367 |
for symbol in series:
|
| 368 |
fig.add_trace(
|
|
|
|
| 371 |
y=[item.get(symbol) for item in history],
|
| 372 |
mode="lines",
|
| 373 |
name=symbol,
|
| 374 |
+
line=dict(color=colors.get(symbol, "#a78bfa"), width=2 if symbol == ticker else 1.5),
|
| 375 |
hovertemplate=f"{symbol} %{{y:.1f}}<extra></extra>",
|
| 376 |
)
|
| 377 |
)
|
|
|
|
| 401 |
event_dates.append(nearest["date"])
|
| 402 |
event_values.append(nearest[ticker])
|
| 403 |
event_symbols.append("triangle-up" if excess >= 0 else "triangle-down")
|
| 404 |
+
event_colors.append(BRAND_GREEN if excess >= 0 else "#ef4444")
|
| 405 |
headline_text = (
|
| 406 |
t("primer_no_verified_catalyst")
|
| 407 |
if event.get("attribution_status") == "NO_VERIFIED_CATALYST"
|
|
|
|
| 435 |
margin=dict(l=20, r=20, t=10, b=20),
|
| 436 |
paper_bgcolor="rgba(0,0,0,0)",
|
| 437 |
plot_bgcolor="rgba(0,0,0,0)",
|
| 438 |
+
font=dict(family="Inter", color=TEXT_MUTED),
|
| 439 |
legend=dict(orientation="h", y=1.05, x=0),
|
| 440 |
yaxis_title=t("primer_indexed_100"),
|
| 441 |
hovermode="x unified",
|
| 442 |
)
|
| 443 |
fig.update_xaxes(showgrid=False)
|
| 444 |
+
fig.update_yaxes(gridcolor="#2b323c", zeroline=False)
|
| 445 |
st.plotly_chart(fig, use_container_width=True, config={"displayModeBar": False})
|
| 446 |
st.caption(t("primer_price_caption").format(benchmark=benchmark))
|
| 447 |
|
|
|
|
| 471 |
)
|
| 472 |
|
| 473 |
|
| 474 |
+
def _news_date(raw: object) -> tuple[str, str]:
|
| 475 |
+
"""Return (display_date, sort_key) for a news item's publication date.
|
| 476 |
+
|
| 477 |
+
Feeds mix ISO 8601 with RFC 2822 ("Tue, 03 Feb 2026 09:00:00 GMT"). Slicing
|
| 478 |
+
the first ten characters works for the former and mangles the latter into
|
| 479 |
+
"Tue, 03 Fe", so both are parsed properly and anything unrecognised is shown
|
| 480 |
+
whole rather than cut mid-word.
|
| 481 |
+
"""
|
| 482 |
+
text = str(raw or "").strip()
|
| 483 |
+
if not text:
|
| 484 |
+
return "", ""
|
| 485 |
+
try:
|
| 486 |
+
return datetime.fromisoformat(text[:10]).date().isoformat(), text[:10]
|
| 487 |
+
except ValueError:
|
| 488 |
+
pass
|
| 489 |
+
try:
|
| 490 |
+
from email.utils import parsedate_to_datetime
|
| 491 |
+
parsed = parsedate_to_datetime(text)
|
| 492 |
+
if parsed is not None:
|
| 493 |
+
iso = parsed.date().isoformat()
|
| 494 |
+
return iso, iso
|
| 495 |
+
except (TypeError, ValueError):
|
| 496 |
+
pass
|
| 497 |
+
return text, ""
|
| 498 |
+
|
| 499 |
+
|
| 500 |
def _news(news_items: list[dict], news_error: str | None) -> None:
|
| 501 |
st.markdown(section_header(t("primer_news"), accent=BLUE), unsafe_allow_html=True)
|
| 502 |
if not news_items:
|
| 503 |
st.info(news_error or t("primer_news_unavailable"))
|
| 504 |
return
|
| 505 |
+
# Newest first — the feed order is not chronological.
|
| 506 |
+
dated = [(item, *_news_date(item.get("published_date"))) for item in news_items]
|
| 507 |
+
dated.sort(key=lambda row: row[2], reverse=True)
|
| 508 |
+
for item, display_date, _sort_key in dated[:5]:
|
| 509 |
title = escape(str(item.get("title") or ""))
|
| 510 |
url = escape(str(item.get("url") or ""))
|
| 511 |
+
date = escape(display_date)
|
| 512 |
st.markdown(
|
| 513 |
f'<div style="padding:9px 0;border-bottom:1px solid {BORDER};">'
|
| 514 |
f'<div style="font-size:{FS_META};color:{TEXT_MUTED};">{date}</div>'
|
|
|
|
| 518 |
)
|
| 519 |
|
| 520 |
|
| 521 |
+
def _watch(profile: dict) -> str | None:
|
|
|
|
| 522 |
values = profile.get("watch_variables") or []
|
| 523 |
if not values:
|
| 524 |
+
return t("primer_watch")
|
| 525 |
+
st.markdown(section_header(t("primer_watch"), accent="#fbbf24"), unsafe_allow_html=True)
|
| 526 |
+
# Same reason as the business lines: these are sentences, not table cells.
|
| 527 |
+
cards: list[str] = []
|
| 528 |
+
for item in values[:4]:
|
| 529 |
+
variable = escape(str(item.get("variable") or ""))
|
| 530 |
+
why = escape(str(item.get("why_it_matters") or ""))
|
| 531 |
+
next_point = escape(str(item.get("next_datapoint") or ""))
|
| 532 |
+
alert = escape(str(item.get("alert_signal") or ""))
|
| 533 |
+
meta = " · ".join(part for part in (next_point, alert) if part)
|
| 534 |
+
cards.append(
|
| 535 |
+
f'<div style="display:flex;gap:16px;align-items:flex-start;padding:13px 0;'
|
| 536 |
+
f'border-bottom:1px solid {BORDER};">'
|
| 537 |
+
f'<div style="flex:0 0 190px;font-size:{FS_BODY};font-weight:650;'
|
| 538 |
+
f'color:{TEXT};">{variable}</div>'
|
| 539 |
+
f'<div style="flex:1;min-width:0;">'
|
| 540 |
+
+ (
|
| 541 |
+
f'<div style="font-size:{FS_BODY};line-height:1.55;color:{AI_COLOR};">'
|
| 542 |
+
f'AI · {why}</div>' if why else ""
|
| 543 |
+
)
|
| 544 |
+
+ (
|
| 545 |
+
f'<div style="font-size:{FS_META};color:{TEXT_MUTED};margin-top:4px;">'
|
| 546 |
+
f'{meta}</div>' if meta else ""
|
| 547 |
+
)
|
| 548 |
+
+ f'</div></div>'
|
| 549 |
+
)
|
| 550 |
+
st.markdown("".join(cards), unsafe_allow_html=True)
|
| 551 |
+
|
| 552 |
+
|
| 553 |
+
def _render_gaps(gaps: list[str]) -> None:
|
| 554 |
+
"""List the sections that had no verified data, once, in muted text."""
|
| 555 |
+
if not gaps:
|
| 556 |
return
|
| 557 |
+
st.markdown(
|
| 558 |
+
f'<div style="margin-top:34px;padding-top:14px;border-top:1px solid {BORDER};">'
|
| 559 |
+
f'<div style="font-size:0.6rem;font-weight:700;text-transform:uppercase;'
|
| 560 |
+
f'letter-spacing:0.1em;color:{TEXT_MUTED};margin-bottom:6px;">'
|
| 561 |
+
f'{escape(t("primer_gaps_label"))}</div>'
|
| 562 |
+
f'<div style="font-size:0.8rem;color:{TEXT_MUTED};line-height:1.55;">'
|
| 563 |
+
f'{escape(" · ".join(gaps))}</div>'
|
| 564 |
+
f'<div style="font-size:0.72rem;color:{TEXT_MUTED};margin-top:6px;opacity:0.85;">'
|
| 565 |
+
f'{escape(t("primer_gaps_body"))}</div>'
|
| 566 |
+
f'</div>',
|
| 567 |
+
unsafe_allow_html=True,
|
| 568 |
+
)
|
| 569 |
|
| 570 |
|
| 571 |
def render(
|
|
|
|
| 577 |
news_error: str | None = None,
|
| 578 |
) -> None:
|
| 579 |
_page_header(profile, market)
|
| 580 |
+
# Each section returns its own name when it has nothing to show. Collecting
|
| 581 |
+
# them means one quiet line at the end instead of a full-width alert box
|
| 582 |
+
# wedged between every populated section.
|
| 583 |
+
gaps = [
|
| 584 |
+
label for label in (
|
| 585 |
+
_identity(profile),
|
| 586 |
+
_business(profile),
|
| 587 |
+
_geography(profile),
|
| 588 |
+
_evolution(profile),
|
| 589 |
+
_attention(profile),
|
| 590 |
+
_market(profile, market),
|
| 591 |
+
) if label
|
| 592 |
+
]
|
| 593 |
_news(news_items or [], news_error)
|
| 594 |
+
watch_gap = _watch(profile)
|
| 595 |
+
if watch_gap:
|
| 596 |
+
gaps.append(watch_gap)
|
| 597 |
+
_render_gaps(gaps)
|
| 598 |
|
| 599 |
coverage = profile.get("source_coverage") or {}
|
| 600 |
with st.expander(t("primer_sources"), expanded=False):
|
|
@@ -1,5 +1,6 @@
|
|
| 1 |
"""Shared UI component helpers used across dashboard tabs."""
|
| 2 |
from __future__ import annotations
|
|
|
|
| 3 |
import streamlit as st
|
| 4 |
from dashboard.i18n import t
|
| 5 |
from dashboard.theme import (
|
|
@@ -11,6 +12,23 @@ from dashboard.theme import (
|
|
| 11 |
FS_BODY, FS_META, FS_EYEBROW, FS_SECTION_LABEL,
|
| 12 |
)
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# ── Impact badge ─────────────────────────────────────────────────────────────
|
| 15 |
|
| 16 |
_IMPACT_DOT_COLORS = {
|
|
@@ -25,13 +43,13 @@ def impact_badge(level: str) -> str:
|
|
| 25 |
return ""
|
| 26 |
color, filled = spec
|
| 27 |
dots = "".join(
|
| 28 |
-
f'<span style="color:{color if i < filled else "#
|
| 29 |
for i in range(3)
|
| 30 |
)
|
| 31 |
return (
|
| 32 |
f'<span title="Impact: {level}" style="display:inline-flex;align-items:center;gap:3px;'
|
| 33 |
-
f'background:#
|
| 34 |
-
f'<span style="font-size:0.6rem;font-weight:600;color:#
|
| 35 |
f'{dots}</span>'
|
| 36 |
)
|
| 37 |
|
|
@@ -70,11 +88,11 @@ def interpretation_card(
|
|
| 70 |
# ── Source type badge ─────────────────────────────────────────────────────────
|
| 71 |
|
| 72 |
_SOURCE_STYLES: dict[str, tuple[str, str, str]] = {
|
| 73 |
-
"transcript": ("#
|
| 74 |
-
"10-q": ("#
|
| 75 |
-
"10-k": ("#
|
| 76 |
-
"filing": ("#
|
| 77 |
-
"news": ("#
|
| 78 |
}
|
| 79 |
|
| 80 |
def source_badge(s: str) -> str:
|
|
@@ -88,7 +106,7 @@ def source_badge(s: str) -> str:
|
|
| 88 |
f'border-radius:4px;padding:1px 8px;font-size:0.7rem;font-weight:500;">{s}</span>'
|
| 89 |
)
|
| 90 |
return (
|
| 91 |
-
f'<span style="background:#
|
| 92 |
f'border-radius:4px;padding:1px 8px;font-size:0.7rem;font-weight:500;">{s}</span>'
|
| 93 |
)
|
| 94 |
|
|
@@ -107,9 +125,9 @@ def eyebrow_label(text: str, color: str = TEXT_MUTED) -> str:
|
|
| 107 |
|
| 108 |
_IMPORTANCE_MAP: dict[str, tuple[str, str, str, str, str]] = {
|
| 109 |
# impact → (dot_char, dot_color, label_i18n_key, text_color, font_weight)
|
| 110 |
-
"HIGH": ("●", "#
|
| 111 |
-
"MEDIUM": ("●", "#
|
| 112 |
-
"LOW": ("●", "#
|
| 113 |
}
|
| 114 |
|
| 115 |
def importance_marker(impact: str) -> str:
|
|
@@ -190,21 +208,21 @@ def sort_by_impact(items: list[dict]) -> list[dict]:
|
|
| 190 |
|
| 191 |
# ── Evidence blockquote ───────────────────────────────────────────────────────
|
| 192 |
|
| 193 |
-
def evidence_quote(snippet: str, bg: str = "#
|
| 194 |
"""Renders a collapsible evidence snippet."""
|
| 195 |
if not snippet:
|
| 196 |
return ""
|
| 197 |
return (
|
| 198 |
f'<details style="margin:4px 0;">'
|
| 199 |
-
f'<summary style="cursor:pointer;font-size:0.68rem;color:#
|
| 200 |
f'list-style:none;display:inline-flex;align-items:center;gap:4px;user-select:none;">'
|
| 201 |
f'<span style="font-size:0.6rem;">▶</span> {t("view_quote")}'
|
| 202 |
f'</summary>'
|
| 203 |
f'<div style="margin-top:4px;padding:4px 10px;background:{bg};'
|
| 204 |
f'border-left:3px solid {border_color};border-radius:0 4px 4px 0;">'
|
| 205 |
-
f'<span style="font-size:0.95rem;line-height:1;color:#
|
| 206 |
f'font-family:Georgia,serif;margin-right:3px;vertical-align:-2px;">"</span>'
|
| 207 |
-
f'<span style="font-size:0.75rem;color:#
|
| 208 |
f'</div>'
|
| 209 |
f'</details>'
|
| 210 |
)
|
|
@@ -231,23 +249,23 @@ _ASSESSMENT_STYLES: dict[str, tuple[str, str, str]] = {
|
|
| 231 |
|
| 232 |
_DELTA_KIND_META: dict[str, tuple[str, str, str]] = {
|
| 233 |
# kind → (label, fg_color, bg_color)
|
| 234 |
-
"risk_added": ("NEW RISK", "#
|
| 235 |
-
"risk_removed": ("REMOVED RISK", "#
|
| 236 |
-
"risk_reworded": ("REWORDED RISK", "#
|
| 237 |
-
"guidance_language_shift": ("GUIDANCE SHIFT", "#
|
| 238 |
-
"term_frequency": ("FREQUENCY SHIFT", "#
|
| 239 |
-
"kpi_dropped": ("DROPPED KPI", "#
|
| 240 |
-
"tone_trend": ("TONE TREND", "#
|
| 241 |
-
"topic_arc": ("TOPIC ARC", "#
|
| 242 |
-
"recurring_evasion": ("RECURRING EVASION", "#
|
| 243 |
-
"topic_fade": ("TOPIC FADE", "#
|
| 244 |
}
|
| 245 |
|
| 246 |
-
_SIG_COLORS: dict[str, str] = {"HIGH": "#
|
| 247 |
|
| 248 |
|
| 249 |
def significance_badge(sig: str) -> str:
|
| 250 |
-
color = _SIG_COLORS.get(sig, "#
|
| 251 |
return (
|
| 252 |
f'<span style="background:{color}1a;color:{color};border:1px solid {color}44;'
|
| 253 |
f'border-radius:4px;padding:1px 7px;font-size:0.65rem;font-weight:700;'
|
|
@@ -255,30 +273,70 @@ def significance_badge(sig: str) -> str:
|
|
| 255 |
)
|
| 256 |
|
| 257 |
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
|
|
|
|
|
|
|
|
|
| 270 |
)
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
f'<span style="font-size:0.6rem;font-weight:700;text-transform:uppercase;'
|
| 276 |
-
f'color:
|
| 277 |
-
f'
|
| 278 |
-
f'margin-top:3px;">“{after}”</div>'
|
| 279 |
f'</div>'
|
| 280 |
)
|
| 281 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
|
| 283 |
|
| 284 |
def section_header(label: str, accent: str = TEXT_MUTED, icon: str = "") -> str:
|
|
@@ -322,7 +380,7 @@ def numbered_list(
|
|
| 322 |
f'padding:12px 0;border-bottom:1px solid {BORDER};">'
|
| 323 |
f'<span style="display:inline-flex;align-items:center;justify-content:center;'
|
| 324 |
f'width:22px;height:22px;border-radius:50%;flex-shrink:0;margin-top:1px;'
|
| 325 |
-
f'background:{GRAY};color:
|
| 326 |
f'<span style="font-size:{FS_BODY};line-height:1.55;color:{TEXT};">{item}</span>'
|
| 327 |
f'</div>'
|
| 328 |
)
|
|
@@ -344,11 +402,11 @@ def numbered_list(
|
|
| 344 |
|
| 345 |
_SIGNAL_TYPE_COLORS: dict[str, tuple[str, str]] = {
|
| 346 |
# signal_type → (fg_color, bg_color); labels resolve via t(f"sig_{type}")
|
| 347 |
-
"language_drift": ("#
|
| 348 |
-
"qa_evasion": ("#
|
| 349 |
-
"omission": ("#
|
| 350 |
-
"emphasis_shift": ("#
|
| 351 |
-
"accounting_quality": ("#
|
| 352 |
}
|
| 353 |
|
| 354 |
|
|
@@ -388,9 +446,9 @@ def _signal_category_chip(sig) -> str:
|
|
| 388 |
_, fg, bg = _DELTA_KIND_META[cat]
|
| 389 |
return _pill(t(f"dk_{cat}"), fg, bg)
|
| 390 |
if sig.kind == "risk":
|
| 391 |
-
return _pill(cat, GRAY, "#
|
| 392 |
if sig.kind == "quality":
|
| 393 |
-
return _pill(_DIMENSION_LABELS.get(cat, cat.replace("_", " ").title()), GRAY, "#
|
| 394 |
return ""
|
| 395 |
|
| 396 |
|
|
@@ -398,8 +456,8 @@ def _tension_body(sig) -> str:
|
|
| 398 |
extra = sig.extra or {}
|
| 399 |
sides = []
|
| 400 |
for key_label, fg, reading_key, ev_key in (
|
| 401 |
-
("tension_surface", "#
|
| 402 |
-
("tension_deeper", "#
|
| 403 |
):
|
| 404 |
ev = extra.get(ev_key) or {}
|
| 405 |
ev = ev if isinstance(ev, dict) else {}
|
|
@@ -418,8 +476,8 @@ def _tension_body(sig) -> str:
|
|
| 418 |
|
| 419 |
def _delta_body(sig) -> str:
|
| 420 |
metric_html = (
|
| 421 |
-
f'<div style="font-size:0.72rem;font-weight:600;color:#
|
| 422 |
-
f'background:#
|
| 423 |
f'padding:4px 8px;margin-bottom:8px;">'
|
| 424 |
f'<span style="color:{TEXT_MUTED};font-size:0.65rem;font-weight:500;">'
|
| 425 |
f'{t("computed_label")} · </span>{sig.body}'
|
|
@@ -477,7 +535,7 @@ def signal_card(sig) -> None:
|
|
| 477 |
|
| 478 |
# ── Header row: taxonomy chips left, period + AI badge right ───────────
|
| 479 |
left_bits = [
|
| 480 |
-
_pill(t(_KIND_LABEL_KEYS.get(sig.kind, "kind_note")), GRAY, "#
|
| 481 |
_signal_category_chip(sig),
|
| 482 |
]
|
| 483 |
if sig.is_new:
|
|
@@ -494,7 +552,7 @@ def signal_card(sig) -> None:
|
|
| 494 |
if sig.kind in EXPERIMENTAL_AI_KINDS:
|
| 495 |
right_bits.append(ai_badge("AI · experimental"))
|
| 496 |
elif sig.kind in HEURISTIC_KINDS:
|
| 497 |
-
right_bits.append(_pill("Heuristic · validate", GRAY, "#
|
| 498 |
|
| 499 |
header = (
|
| 500 |
f'<div style="display:flex;align-items:center;justify-content:space-between;'
|
|
@@ -568,7 +626,7 @@ def signal_card(sig) -> None:
|
|
| 568 |
st.markdown(
|
| 569 |
f'<div class="primer-card" style="background:{BG};border:1px solid {BORDER};'
|
| 570 |
f'border-left:3px solid {accent};border-radius:0 10px 10px 0;'
|
| 571 |
-
f'padding:14px 18px;margin-bottom:10px;max-width:
|
| 572 |
f'{header}{headline_html}{body_html}{footer_html}'
|
| 573 |
f'</div>',
|
| 574 |
unsafe_allow_html=True,
|
|
|
|
| 1 |
"""Shared UI component helpers used across dashboard tabs."""
|
| 2 |
from __future__ import annotations
|
| 3 |
+
import re
|
| 4 |
import streamlit as st
|
| 5 |
from dashboard.i18n import t
|
| 6 |
from dashboard.theme import (
|
|
|
|
| 12 |
FS_BODY, FS_META, FS_EYEBROW, FS_SECTION_LABEL,
|
| 13 |
)
|
| 14 |
|
| 15 |
+
# Span de code CommonMark : run de backticks ouvrant (fence), contenu quelconque,
|
| 16 |
+
# fermé par un run de backticks de MÊME longueur, ni précédé ni suivi d'un backtick.
|
| 17 |
+
# Alternative : un $ non déjà échappé. Un unique re.sub arbitre les deux cas :
|
| 18 |
+
# un span matché est restitué tel quel, un $ hors span devient \$.
|
| 19 |
+
_CODE_SPAN_OR_DOLLAR = re.compile(
|
| 20 |
+
r"(?P<code>(?P<fence>`+)[\s\S]*?(?<!`)(?P=fence)(?!`))|(?<!\\)\$"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
def escape_dollars(text: str) -> str:
|
| 24 |
+
"""Escape $ so st.markdown does not render inline LaTeX. Code spans untouched."""
|
| 25 |
+
if not text:
|
| 26 |
+
return text
|
| 27 |
+
return _CODE_SPAN_OR_DOLLAR.sub(
|
| 28 |
+
lambda m: m.group("code") if m.group("code") is not None else "\\$",
|
| 29 |
+
text,
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
# ── Impact badge ─────────────────────────────────────────────────────────────
|
| 33 |
|
| 34 |
_IMPACT_DOT_COLORS = {
|
|
|
|
| 43 |
return ""
|
| 44 |
color, filled = spec
|
| 45 |
dots = "".join(
|
| 46 |
+
f'<span style="color:{color if i < filled else "#3a424e"};font-size:0.55rem;line-height:1;">●</span>'
|
| 47 |
for i in range(3)
|
| 48 |
)
|
| 49 |
return (
|
| 50 |
f'<span title="Impact: {level}" style="display:inline-flex;align-items:center;gap:3px;'
|
| 51 |
+
f'background:#1a2029;border:1px solid #2b323c;border-radius:4px;padding:1px 7px;">'
|
| 52 |
+
f'<span style="font-size:0.6rem;font-weight:600;color:#7b8593;letter-spacing:0.05em;">impact</span>'
|
| 53 |
f'{dots}</span>'
|
| 54 |
)
|
| 55 |
|
|
|
|
| 88 |
# ── Source type badge ─────────────────────────────────────────────────────────
|
| 89 |
|
| 90 |
_SOURCE_STYLES: dict[str, tuple[str, str, str]] = {
|
| 91 |
+
"transcript": ("#10251d", "#1f5b45", "#6ee7b7"),
|
| 92 |
+
"10-q": ("#111f33", "#1e3a5f", "#93c5fd"),
|
| 93 |
+
"10-k": ("#111f33", "#1e3a5f", "#93c5fd"),
|
| 94 |
+
"filing": ("#111f33", "#1e3a5f", "#93c5fd"),
|
| 95 |
+
"news": ("#2a1e13", "#5c3f1a", "#fdba74"),
|
| 96 |
}
|
| 97 |
|
| 98 |
def source_badge(s: str) -> str:
|
|
|
|
| 106 |
f'border-radius:4px;padding:1px 8px;font-size:0.7rem;font-weight:500;">{s}</span>'
|
| 107 |
)
|
| 108 |
return (
|
| 109 |
+
f'<span style="background:#1a2029;color:#8a95a3;border:1px solid #3a424e;'
|
| 110 |
f'border-radius:4px;padding:1px 8px;font-size:0.7rem;font-weight:500;">{s}</span>'
|
| 111 |
)
|
| 112 |
|
|
|
|
| 125 |
|
| 126 |
_IMPORTANCE_MAP: dict[str, tuple[str, str, str, str, str]] = {
|
| 127 |
# impact → (dot_char, dot_color, label_i18n_key, text_color, font_weight)
|
| 128 |
+
"HIGH": ("●", "#e8eef5", "imp_critical", "#e8eef5", "600"),
|
| 129 |
+
"MEDIUM": ("●", "#7b8593", "imp_important", "#7b8593", "500"),
|
| 130 |
+
"LOW": ("●", "#7b8593", "imp_context", "#7b8593", "500"),
|
| 131 |
}
|
| 132 |
|
| 133 |
def importance_marker(impact: str) -> str:
|
|
|
|
| 208 |
|
| 209 |
# ── Evidence blockquote ───────────────────────────────────────────────────────
|
| 210 |
|
| 211 |
+
def evidence_quote(snippet: str, bg: str = "#0e1217", border_color: str = "#2b323c") -> str:
|
| 212 |
"""Renders a collapsible evidence snippet."""
|
| 213 |
if not snippet:
|
| 214 |
return ""
|
| 215 |
return (
|
| 216 |
f'<details style="margin:4px 0;">'
|
| 217 |
+
f'<summary style="cursor:pointer;font-size:0.68rem;color:#707b8a;font-weight:500;'
|
| 218 |
f'list-style:none;display:inline-flex;align-items:center;gap:4px;user-select:none;">'
|
| 219 |
f'<span style="font-size:0.6rem;">▶</span> {t("view_quote")}'
|
| 220 |
f'</summary>'
|
| 221 |
f'<div style="margin-top:4px;padding:4px 10px;background:{bg};'
|
| 222 |
f'border-left:3px solid {border_color};border-radius:0 4px 4px 0;">'
|
| 223 |
+
f'<span style="font-size:0.95rem;line-height:1;color:#3a424e;'
|
| 224 |
f'font-family:Georgia,serif;margin-right:3px;vertical-align:-2px;">"</span>'
|
| 225 |
+
f'<span style="font-size:0.75rem;color:#8a95a3;font-style:italic;line-height:1.35;">{snippet}</span>'
|
| 226 |
f'</div>'
|
| 227 |
f'</details>'
|
| 228 |
)
|
|
|
|
| 249 |
|
| 250 |
_DELTA_KIND_META: dict[str, tuple[str, str, str]] = {
|
| 251 |
# kind → (label, fg_color, bg_color)
|
| 252 |
+
"risk_added": ("NEW RISK", "#f87171", "#2a1416"),
|
| 253 |
+
"risk_removed": ("REMOVED RISK", "#8a95a3", "#1a2029"),
|
| 254 |
+
"risk_reworded": ("REWORDED RISK", "#fbbf24", "#2a2113"),
|
| 255 |
+
"guidance_language_shift": ("GUIDANCE SHIFT", "#818cf8", "#1a1e3a"),
|
| 256 |
+
"term_frequency": ("FREQUENCY SHIFT", "#38bdf8", "#111f33"),
|
| 257 |
+
"kpi_dropped": ("DROPPED KPI", "#8a95a3", "#1a2029"),
|
| 258 |
+
"tone_trend": ("TONE TREND", "#a78bfa", "#1e1633"),
|
| 259 |
+
"topic_arc": ("TOPIC ARC", "#38bdf8", "#111f33"),
|
| 260 |
+
"recurring_evasion": ("RECURRING EVASION", "#ef4444", "#2a1416"),
|
| 261 |
+
"topic_fade": ("TOPIC FADE", "#8a95a3", "#1a2029"),
|
| 262 |
}
|
| 263 |
|
| 264 |
+
_SIG_COLORS: dict[str, str] = {"HIGH": "#f87171", "MEDIUM": "#fbbf24", "LOW": "#707b8a"}
|
| 265 |
|
| 266 |
|
| 267 |
def significance_badge(sig: str) -> str:
|
| 268 |
+
color = _SIG_COLORS.get(sig, "#707b8a")
|
| 269 |
return (
|
| 270 |
f'<span style="background:{color}1a;color:{color};border:1px solid {color}44;'
|
| 271 |
f'border-radius:4px;padding:1px 7px;font-size:0.65rem;font-weight:700;'
|
|
|
|
| 273 |
)
|
| 274 |
|
| 275 |
|
| 276 |
+
# Filing prose runs long — a risk-factor paragraph is routinely 800 characters.
|
| 277 |
+
# Anything past this is folded behind a disclosure so the card stays scannable.
|
| 278 |
+
_REDLINE_PREVIEW_CHARS = 230
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
def _clamped_passage(text: str, color: str) -> str:
|
| 282 |
+
"""Quote `text`, folding everything past the preview behind a disclosure.
|
| 283 |
+
|
| 284 |
+
The preview is the <summary> and only the remainder lives in the body, so
|
| 285 |
+
the passage appears exactly once whether the card is open or closed.
|
| 286 |
+
"""
|
| 287 |
+
if len(text) <= _REDLINE_PREVIEW_CHARS:
|
| 288 |
+
return (
|
| 289 |
+
f'<div style="font-size:0.78rem;font-style:italic;color:{color};'
|
| 290 |
+
f'line-height:1.45;margin-top:3px;">“{text}”</div>'
|
| 291 |
)
|
| 292 |
+
# Cut on a word boundary so the preview never ends mid-word.
|
| 293 |
+
cut = text.rfind(" ", 0, _REDLINE_PREVIEW_CHARS)
|
| 294 |
+
if cut <= 0:
|
| 295 |
+
cut = _REDLINE_PREVIEW_CHARS
|
| 296 |
+
head, tail = text[:cut], text[cut:].lstrip()
|
| 297 |
+
return (
|
| 298 |
+
f'<details style="margin-top:3px;">'
|
| 299 |
+
f'<summary style="cursor:pointer;list-style:none;">'
|
| 300 |
+
f'<span style="font-size:0.78rem;font-style:italic;color:{color};'
|
| 301 |
+
f'line-height:1.45;">“{head}…</span>'
|
| 302 |
+
f'<span class="primer-more" style="font-size:0.62rem;font-style:normal;font-weight:600;'
|
| 303 |
+
f'text-transform:uppercase;letter-spacing:0.06em;color:{TEXT_MUTED};'
|
| 304 |
+
f'margin-left:6px;white-space:nowrap;">{t("show_full_passage")}</span>'
|
| 305 |
+
f'</summary>'
|
| 306 |
+
f'<div style="font-size:0.78rem;font-style:italic;color:{color};'
|
| 307 |
+
f'line-height:1.45;">{tail}”</div>'
|
| 308 |
+
f'</details>'
|
| 309 |
+
)
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
def _redline_block(before: str, after: str) -> str:
|
| 313 |
+
"""Render before→after text with redline-style color coding.
|
| 314 |
+
|
| 315 |
+
The two passages sit side by side rather than stacked: they are meant to be
|
| 316 |
+
compared, and stacking two long quotes pushed the next card off-screen.
|
| 317 |
+
They wrap back to one column when the card is too narrow to split.
|
| 318 |
+
"""
|
| 319 |
+
sides: list[str] = []
|
| 320 |
+
for text, bg, border, label_color, body_color, label in (
|
| 321 |
+
(before, "#2a1416", "#fca5a5", "#f87171", "#fca5a5", "before"),
|
| 322 |
+
(after, "#10251d", "#6ee7b7", "#34d399", "#6ee7b7", "after"),
|
| 323 |
+
):
|
| 324 |
+
if not text:
|
| 325 |
+
continue
|
| 326 |
+
sides.append(
|
| 327 |
+
f'<div style="flex:1 1 300px;min-width:0;padding:8px 10px;background:{bg};'
|
| 328 |
+
f'border-left:3px solid {border};border-radius:0 4px 4px 0;">'
|
| 329 |
f'<span style="font-size:0.6rem;font-weight:700;text-transform:uppercase;'
|
| 330 |
+
f'color:{label_color};letter-spacing:0.07em;">{label}</span>'
|
| 331 |
+
f'{_clamped_passage(text, body_color)}'
|
|
|
|
| 332 |
f'</div>'
|
| 333 |
)
|
| 334 |
+
if not sides:
|
| 335 |
+
return ""
|
| 336 |
+
return (
|
| 337 |
+
f'<div style="display:flex;gap:8px;flex-wrap:wrap;align-items:flex-start;">'
|
| 338 |
+
f'{"".join(sides)}</div>'
|
| 339 |
+
)
|
| 340 |
|
| 341 |
|
| 342 |
def section_header(label: str, accent: str = TEXT_MUTED, icon: str = "") -> str:
|
|
|
|
| 380 |
f'padding:12px 0;border-bottom:1px solid {BORDER};">'
|
| 381 |
f'<span style="display:inline-flex;align-items:center;justify-content:center;'
|
| 382 |
f'width:22px;height:22px;border-radius:50%;flex-shrink:0;margin-top:1px;'
|
| 383 |
+
f'background:{GRAY};color:{BG};font-size:0.7rem;font-weight:700;">{i}</span>'
|
| 384 |
f'<span style="font-size:{FS_BODY};line-height:1.55;color:{TEXT};">{item}</span>'
|
| 385 |
f'</div>'
|
| 386 |
)
|
|
|
|
| 402 |
|
| 403 |
_SIGNAL_TYPE_COLORS: dict[str, tuple[str, str]] = {
|
| 404 |
# signal_type → (fg_color, bg_color); labels resolve via t(f"sig_{type}")
|
| 405 |
+
"language_drift": ("#818cf8", "#1a1e3a"), # indigo
|
| 406 |
+
"qa_evasion": ("#ef4444", "#2a1416"), # red
|
| 407 |
+
"omission": ("#f59e0b", "#2a2113"), # amber
|
| 408 |
+
"emphasis_shift": ("#8a95a3", "#1a2029"), # gray
|
| 409 |
+
"accounting_quality": ("#38bdf8", "#111f33"), # sky
|
| 410 |
}
|
| 411 |
|
| 412 |
|
|
|
|
| 446 |
_, fg, bg = _DELTA_KIND_META[cat]
|
| 447 |
return _pill(t(f"dk_{cat}"), fg, bg)
|
| 448 |
if sig.kind == "risk":
|
| 449 |
+
return _pill(cat, GRAY, "#1a2029")
|
| 450 |
if sig.kind == "quality":
|
| 451 |
+
return _pill(_DIMENSION_LABELS.get(cat, cat.replace("_", " ").title()), GRAY, "#1a2029")
|
| 452 |
return ""
|
| 453 |
|
| 454 |
|
|
|
|
| 456 |
extra = sig.extra or {}
|
| 457 |
sides = []
|
| 458 |
for key_label, fg, reading_key, ev_key in (
|
| 459 |
+
("tension_surface", "#10b981", "bullish_reading", "bullish_evidence"),
|
| 460 |
+
("tension_deeper", "#ef4444", "bearish_reading", "bearish_evidence"),
|
| 461 |
):
|
| 462 |
ev = extra.get(ev_key) or {}
|
| 463 |
ev = ev if isinstance(ev, dict) else {}
|
|
|
|
| 476 |
|
| 477 |
def _delta_body(sig) -> str:
|
| 478 |
metric_html = (
|
| 479 |
+
f'<div style="font-size:0.72rem;font-weight:600;color:#c3ccd6;'
|
| 480 |
+
f'background:#1a2029;border:1px solid #2b323c;border-radius:4px;'
|
| 481 |
f'padding:4px 8px;margin-bottom:8px;">'
|
| 482 |
f'<span style="color:{TEXT_MUTED};font-size:0.65rem;font-weight:500;">'
|
| 483 |
f'{t("computed_label")} · </span>{sig.body}'
|
|
|
|
| 535 |
|
| 536 |
# ── Header row: taxonomy chips left, period + AI badge right ───────────
|
| 537 |
left_bits = [
|
| 538 |
+
_pill(t(_KIND_LABEL_KEYS.get(sig.kind, "kind_note")), GRAY, "#1a2029"),
|
| 539 |
_signal_category_chip(sig),
|
| 540 |
]
|
| 541 |
if sig.is_new:
|
|
|
|
| 552 |
if sig.kind in EXPERIMENTAL_AI_KINDS:
|
| 553 |
right_bits.append(ai_badge("AI · experimental"))
|
| 554 |
elif sig.kind in HEURISTIC_KINDS:
|
| 555 |
+
right_bits.append(_pill("Heuristic · validate", GRAY, "#1a2029"))
|
| 556 |
|
| 557 |
header = (
|
| 558 |
f'<div style="display:flex;align-items:center;justify-content:space-between;'
|
|
|
|
| 626 |
st.markdown(
|
| 627 |
f'<div class="primer-card" style="background:{BG};border:1px solid {BORDER};'
|
| 628 |
f'border-left:3px solid {accent};border-radius:0 10px 10px 0;'
|
| 629 |
+
f'padding:14px 18px;margin-bottom:10px;max-width:1000px;">'
|
| 630 |
f'{header}{headline_html}{body_html}{footer_html}'
|
| 631 |
f'</div>',
|
| 632 |
unsafe_allow_html=True,
|
|
@@ -28,14 +28,14 @@ from dashboard.theme import (
|
|
| 28 |
from dashboard.components import impact_badge, section_header
|
| 29 |
|
| 30 |
_LAYOUT = dict(
|
| 31 |
-
plot_bgcolor=
|
| 32 |
-
paper_bgcolor=
|
| 33 |
-
font=dict(color=
|
| 34 |
margin=dict(l=10, r=10, t=58, b=10),
|
| 35 |
xaxis=dict(showgrid=False, zeroline=False, tickfont=dict(color=TEXT_MUTED)),
|
| 36 |
legend=dict(orientation="h", y=1.18, x=0, yanchor="bottom", bgcolor="rgba(0,0,0,0)", font=dict(size=11)),
|
| 37 |
)
|
| 38 |
-
_YAXIS_BASE = dict(showgrid=True, gridcolor="#
|
| 39 |
|
| 40 |
_MASKABLE_COLUMNS = {
|
| 41 |
"revenue",
|
|
@@ -192,20 +192,20 @@ def render(ticker: str, brief: Optional[dict] = None) -> None:
|
|
| 192 |
quarterly = sorted([r for r in rows if r.get("form_type") == "10-Q"], key=lambda r: r["filing_date"])
|
| 193 |
annual = sorted([r for r in rows if r.get("form_type") == "10-K"], key=lambda r: r["filing_date"])
|
| 194 |
quality_badge = (
|
| 195 |
-
f'<span style="background:#
|
| 196 |
'border-radius:4px;padding:2px 7px;font-size:0.65rem;font-weight:700;">VERIFIED</span>'
|
| 197 |
if rows and not partial_rows and not masked_rows else
|
| 198 |
-
f'<span style="background:#
|
| 199 |
'border-radius:4px;padding:2px 7px;font-size:0.65rem;font-weight:700;">METRICS HIDDEN</span>'
|
| 200 |
if not rows else ""
|
| 201 |
)
|
| 202 |
partial_badge = (
|
| 203 |
-
f' <span style="background:#
|
| 204 |
f'border-radius:4px;padding:2px 7px;font-size:0.65rem;font-weight:700;">{len(partial_rows)} PARTIAL</span>'
|
| 205 |
if partial_rows else ""
|
| 206 |
)
|
| 207 |
masked_badge = (
|
| 208 |
-
f' <span style="background:#
|
| 209 |
f'border-radius:4px;padding:2px 7px;font-size:0.65rem;font-weight:700;">{len(masked_rows)} MASKED</span>'
|
| 210 |
if masked_rows else ""
|
| 211 |
)
|
|
@@ -280,6 +280,12 @@ def render(ticker: str, brief: Optional[dict] = None) -> None:
|
|
| 280 |
# ── 1. KPI snapshot (moved from numbers.py) ───────────────────────────────────
|
| 281 |
|
| 282 |
def _render_snapshot(latest: dict, prior: dict) -> None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
metrics = [
|
| 284 |
("Revenue", _safe(latest.get("revenue")), _safe(prior.get("revenue")), "$", "B", 1e9),
|
| 285 |
("EPS (Diluted)", _safe(latest.get("eps")), _safe(prior.get("eps")), "$", "", 1),
|
|
@@ -314,7 +320,7 @@ def _render_snapshot(latest: dict, prior: dict) -> None:
|
|
| 314 |
<div class="primer-card" style="background:{BG};border:1px solid {BORDER};border-radius:10px;padding:18px 20px;">
|
| 315 |
<div style="font-size:0.72rem;color:{TEXT_FAINT};margin-bottom:4px;">{label}</div>
|
| 316 |
<div style="font-size:1.4rem;font-weight:700;color:{delta_color or TEXT};">{val_str}</div>
|
| 317 |
-
<div style="font-size:0.78rem;color:{TEXT_MUTED};margin-top:2px;">vs {prev_str}</div>
|
| 318 |
</div>
|
| 319 |
""",
|
| 320 |
unsafe_allow_html=True,
|
|
@@ -497,7 +503,7 @@ def _chart_balance(labels: list, data: list) -> None:
|
|
| 497 |
fig2.add_trace(go.Scatter(
|
| 498 |
name="D/E Ratio", x=labels, y=de,
|
| 499 |
mode="lines+markers",
|
| 500 |
-
line=dict(color="#
|
| 501 |
marker=dict(size=7, color=de_colors),
|
| 502 |
))
|
| 503 |
fig2.update_layout(
|
|
@@ -530,7 +536,7 @@ def _chart_capital_allocation(labels: list, data: list) -> None:
|
|
| 530 |
fig.add_trace(go.Bar(name="Dividends", x=labels, y=dividends,
|
| 531 |
marker_color=BLUE_A53, marker_line_color=BLUE, marker_line_width=1))
|
| 532 |
fig.add_trace(go.Bar(name="Buybacks", x=labels, y=buybacks,
|
| 533 |
-
marker_color=PURPLE_A53, marker_line_color="#
|
| 534 |
fig.add_trace(go.Scatter(name="Free Cash Flow", x=labels, y=fcf_b,
|
| 535 |
mode="lines+markers", line=dict(color=GREEN, width=2),
|
| 536 |
marker=dict(size=6, color=GREEN)))
|
|
@@ -581,7 +587,7 @@ _METRIC_COLORS = {
|
|
| 581 |
"EPS": BLUE,
|
| 582 |
"Operating margin": AMBER,
|
| 583 |
"Capex": GRAY,
|
| 584 |
-
"Gross margin": "#
|
| 585 |
}
|
| 586 |
|
| 587 |
_VERDICT_COLORS = {"beat": GREEN, "in-line": AMBER, "missed": RED, "pending": GRAY}
|
|
@@ -595,7 +601,7 @@ def _verdict_badge(verdict: str | None) -> str:
|
|
| 595 |
label = _VERDICT_LABELS.get(verdict, verdict.upper())
|
| 596 |
return (
|
| 597 |
f'<span style="font-size:0.65rem;font-weight:700;padding:2px 7px;border-radius:10px;'
|
| 598 |
-
f'background:{color};color:
|
| 599 |
)
|
| 600 |
|
| 601 |
|
|
@@ -647,10 +653,10 @@ def _render_guidance_bridge(latest: dict, rows: list, brief: Optional[dict]) ->
|
|
| 647 |
|
| 648 |
st.markdown(
|
| 649 |
f'<div style="display:grid;grid-template-columns:repeat(4,1fr);gap:10px;margin-bottom:20px;">'
|
| 650 |
-
f'{_score_chip("Beat", counts["beat"], GREEN, "#
|
| 651 |
-
f'{_score_chip("In-line", counts["in-line"], AMBER, "#
|
| 652 |
-
f'{_score_chip("Missed", counts["missed"], RED, "#
|
| 653 |
-
f'{_score_chip("Pending", counts["pending"], GRAY, "#
|
| 654 |
f'</div>',
|
| 655 |
unsafe_allow_html=True,
|
| 656 |
)
|
|
@@ -915,8 +921,8 @@ def _render_quarter_cards(quarters: list[dict], price_returns: dict, streak: int
|
|
| 915 |
if spct is not None:
|
| 916 |
sign = "+" if spct >= 0 else ""
|
| 917 |
chip_color = GREEN if spct >= 0 else RED
|
| 918 |
-
chip_bg = "#
|
| 919 |
-
chip_border = "#
|
| 920 |
chip_html = (
|
| 921 |
f'<span style="background:{chip_bg};color:{chip_color};border:1px solid {chip_border};'
|
| 922 |
f'border-radius:999px;padding:2px 9px;font-size:0.75rem;font-weight:600;">'
|
|
@@ -971,7 +977,7 @@ def _render_main_chart(quarters: list[dict]) -> None:
|
|
| 971 |
|
| 972 |
fig.add_trace(
|
| 973 |
go.Bar(name="Reported EPS", x=labels, y=reported,
|
| 974 |
-
marker_color="#
|
| 975 |
secondary_y=False,
|
| 976 |
)
|
| 977 |
fig.add_trace(
|
|
@@ -990,14 +996,14 @@ def _render_main_chart(quarters: list[dict]) -> None:
|
|
| 990 |
)
|
| 991 |
|
| 992 |
fig.update_layout(
|
| 993 |
-
plot_bgcolor=
|
| 994 |
-
paper_bgcolor=
|
| 995 |
font=dict(color=TEXT, family="Inter", size=11),
|
| 996 |
legend=dict(orientation="h", y=1.12, x=0, bgcolor="rgba(0,0,0,0)", font=dict(size=11)),
|
| 997 |
barmode="group",
|
| 998 |
margin=dict(l=10, r=10, t=40, b=10),
|
| 999 |
xaxis=dict(showgrid=False, zeroline=False, tickfont=dict(color=TEXT_MUTED)),
|
| 1000 |
-
yaxis=dict(showgrid=True, gridcolor="#
|
| 1001 |
tickprefix="$", title="EPS ($)", tickfont=dict(color=TEXT_MUTED)),
|
| 1002 |
yaxis2=dict(showgrid=False, zeroline=False, ticksuffix="%",
|
| 1003 |
title="Surprise %", title_font=dict(color=GREEN),
|
|
|
|
| 28 |
from dashboard.components import impact_badge, section_header
|
| 29 |
|
| 30 |
_LAYOUT = dict(
|
| 31 |
+
plot_bgcolor=BG,
|
| 32 |
+
paper_bgcolor=BG,
|
| 33 |
+
font=dict(color=TEXT, family="Inter", size=11),
|
| 34 |
margin=dict(l=10, r=10, t=58, b=10),
|
| 35 |
xaxis=dict(showgrid=False, zeroline=False, tickfont=dict(color=TEXT_MUTED)),
|
| 36 |
legend=dict(orientation="h", y=1.18, x=0, yanchor="bottom", bgcolor="rgba(0,0,0,0)", font=dict(size=11)),
|
| 37 |
)
|
| 38 |
+
_YAXIS_BASE = dict(showgrid=True, gridcolor="#232a34", zeroline=False, tickfont=dict(color=TEXT_MUTED))
|
| 39 |
|
| 40 |
_MASKABLE_COLUMNS = {
|
| 41 |
"revenue",
|
|
|
|
| 192 |
quarterly = sorted([r for r in rows if r.get("form_type") == "10-Q"], key=lambda r: r["filing_date"])
|
| 193 |
annual = sorted([r for r in rows if r.get("form_type") == "10-K"], key=lambda r: r["filing_date"])
|
| 194 |
quality_badge = (
|
| 195 |
+
f'<span style="background:#10251d;color:{GREEN};border:1px solid {GREEN}33;'
|
| 196 |
'border-radius:4px;padding:2px 7px;font-size:0.65rem;font-weight:700;">VERIFIED</span>'
|
| 197 |
if rows and not partial_rows and not masked_rows else
|
| 198 |
+
f'<span style="background:#2a2113;color:{AMBER};border:1px solid {AMBER}55;'
|
| 199 |
'border-radius:4px;padding:2px 7px;font-size:0.65rem;font-weight:700;">METRICS HIDDEN</span>'
|
| 200 |
if not rows else ""
|
| 201 |
)
|
| 202 |
partial_badge = (
|
| 203 |
+
f' <span style="background:#2a2113;color:{AMBER};border:1px solid {AMBER}55;'
|
| 204 |
f'border-radius:4px;padding:2px 7px;font-size:0.65rem;font-weight:700;">{len(partial_rows)} PARTIAL</span>'
|
| 205 |
if partial_rows else ""
|
| 206 |
)
|
| 207 |
masked_badge = (
|
| 208 |
+
f' <span style="background:#2a2113;color:{AMBER};border:1px solid {AMBER}55;'
|
| 209 |
f'border-radius:4px;padding:2px 7px;font-size:0.65rem;font-weight:700;">{len(masked_rows)} MASKED</span>'
|
| 210 |
if masked_rows else ""
|
| 211 |
)
|
|
|
|
| 280 |
# ── 1. KPI snapshot (moved from numbers.py) ───────────────────────────────────
|
| 281 |
|
| 282 |
def _render_snapshot(latest: dict, prior: dict) -> None:
|
| 283 |
+
# Name the comparison period so "vs $111.18B" cannot be read as the prior
|
| 284 |
+
# quarter when it is the year-ago quarter, or as an analyst estimate.
|
| 285 |
+
prior_period = str(prior.get("period") or "").strip()
|
| 286 |
+
prior_label = (
|
| 287 |
+
f' <span style="opacity:0.75;">({prior_period})</span>' if prior_period else ""
|
| 288 |
+
)
|
| 289 |
metrics = [
|
| 290 |
("Revenue", _safe(latest.get("revenue")), _safe(prior.get("revenue")), "$", "B", 1e9),
|
| 291 |
("EPS (Diluted)", _safe(latest.get("eps")), _safe(prior.get("eps")), "$", "", 1),
|
|
|
|
| 320 |
<div class="primer-card" style="background:{BG};border:1px solid {BORDER};border-radius:10px;padding:18px 20px;">
|
| 321 |
<div style="font-size:0.72rem;color:{TEXT_FAINT};margin-bottom:4px;">{label}</div>
|
| 322 |
<div style="font-size:1.4rem;font-weight:700;color:{delta_color or TEXT};">{val_str}</div>
|
| 323 |
+
<div style="font-size:0.78rem;color:{TEXT_MUTED};margin-top:2px;">vs {prev_str}{prior_label}</div>
|
| 324 |
</div>
|
| 325 |
""",
|
| 326 |
unsafe_allow_html=True,
|
|
|
|
| 503 |
fig2.add_trace(go.Scatter(
|
| 504 |
name="D/E Ratio", x=labels, y=de,
|
| 505 |
mode="lines+markers",
|
| 506 |
+
line=dict(color="#fbbf24", width=2),
|
| 507 |
marker=dict(size=7, color=de_colors),
|
| 508 |
))
|
| 509 |
fig2.update_layout(
|
|
|
|
| 536 |
fig.add_trace(go.Bar(name="Dividends", x=labels, y=dividends,
|
| 537 |
marker_color=BLUE_A53, marker_line_color=BLUE, marker_line_width=1))
|
| 538 |
fig.add_trace(go.Bar(name="Buybacks", x=labels, y=buybacks,
|
| 539 |
+
marker_color=PURPLE_A53, marker_line_color="#a78bfa", marker_line_width=1))
|
| 540 |
fig.add_trace(go.Scatter(name="Free Cash Flow", x=labels, y=fcf_b,
|
| 541 |
mode="lines+markers", line=dict(color=GREEN, width=2),
|
| 542 |
marker=dict(size=6, color=GREEN)))
|
|
|
|
| 587 |
"EPS": BLUE,
|
| 588 |
"Operating margin": AMBER,
|
| 589 |
"Capex": GRAY,
|
| 590 |
+
"Gross margin": "#c4b5fd",
|
| 591 |
}
|
| 592 |
|
| 593 |
_VERDICT_COLORS = {"beat": GREEN, "in-line": AMBER, "missed": RED, "pending": GRAY}
|
|
|
|
| 601 |
label = _VERDICT_LABELS.get(verdict, verdict.upper())
|
| 602 |
return (
|
| 603 |
f'<span style="font-size:0.65rem;font-weight:700;padding:2px 7px;border-radius:10px;'
|
| 604 |
+
f'background:{color};color:{BG};letter-spacing:0.05em;">{label}</span>'
|
| 605 |
)
|
| 606 |
|
| 607 |
|
|
|
|
| 653 |
|
| 654 |
st.markdown(
|
| 655 |
f'<div style="display:grid;grid-template-columns:repeat(4,1fr);gap:10px;margin-bottom:20px;">'
|
| 656 |
+
f'{_score_chip("Beat", counts["beat"], GREEN, "#10251d")}'
|
| 657 |
+
f'{_score_chip("In-line", counts["in-line"], AMBER, "#2a2113")}'
|
| 658 |
+
f'{_score_chip("Missed", counts["missed"], RED, "#2a1416")}'
|
| 659 |
+
f'{_score_chip("Pending", counts["pending"], GRAY, "#1a2029")}'
|
| 660 |
f'</div>',
|
| 661 |
unsafe_allow_html=True,
|
| 662 |
)
|
|
|
|
| 921 |
if spct is not None:
|
| 922 |
sign = "+" if spct >= 0 else ""
|
| 923 |
chip_color = GREEN if spct >= 0 else RED
|
| 924 |
+
chip_bg = "#10251d" if spct >= 0 else "#2a1416"
|
| 925 |
+
chip_border = "#1f5b45" if spct >= 0 else "#6b2b2f"
|
| 926 |
chip_html = (
|
| 927 |
f'<span style="background:{chip_bg};color:{chip_color};border:1px solid {chip_border};'
|
| 928 |
f'border-radius:999px;padding:2px 9px;font-size:0.75rem;font-weight:600;">'
|
|
|
|
| 977 |
|
| 978 |
fig.add_trace(
|
| 979 |
go.Bar(name="Reported EPS", x=labels, y=reported,
|
| 980 |
+
marker_color="#c3ccd6", width=0.3, offsetgroup=0),
|
| 981 |
secondary_y=False,
|
| 982 |
)
|
| 983 |
fig.add_trace(
|
|
|
|
| 996 |
)
|
| 997 |
|
| 998 |
fig.update_layout(
|
| 999 |
+
plot_bgcolor=BG,
|
| 1000 |
+
paper_bgcolor=BG,
|
| 1001 |
font=dict(color=TEXT, family="Inter", size=11),
|
| 1002 |
legend=dict(orientation="h", y=1.12, x=0, bgcolor="rgba(0,0,0,0)", font=dict(size=11)),
|
| 1003 |
barmode="group",
|
| 1004 |
margin=dict(l=10, r=10, t=40, b=10),
|
| 1005 |
xaxis=dict(showgrid=False, zeroline=False, tickfont=dict(color=TEXT_MUTED)),
|
| 1006 |
+
yaxis=dict(showgrid=True, gridcolor="#232a34", zeroline=False,
|
| 1007 |
tickprefix="$", title="EPS ($)", tickfont=dict(color=TEXT_MUTED)),
|
| 1008 |
yaxis2=dict(showgrid=False, zeroline=False, ticksuffix="%",
|
| 1009 |
title="Surprise %", title_font=dict(color=GREEN),
|
|
@@ -91,16 +91,82 @@ STRINGS: dict[str, dict[str, str]] = {
|
|
| 91 |
|
| 92 |
# ── Landing / empty states ─────────────────────────────────────────────
|
| 93 |
"landing_title": {
|
| 94 |
-
"en": "
|
| 95 |
-
"fr": "
|
| 96 |
-
"es": "
|
| 97 |
-
"de": "
|
| 98 |
},
|
| 99 |
"landing_body": {
|
| 100 |
-
"en": "
|
| 101 |
-
"fr": "
|
| 102 |
-
"es": "
|
| 103 |
-
"de": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
},
|
| 105 |
"snapshot_empty_title": {
|
| 106 |
"en": "Ready to analyze",
|
|
@@ -130,10 +196,10 @@ STRINGS: dict[str, dict[str, str]] = {
|
|
| 130 |
"de": "Stand",
|
| 131 |
},
|
| 132 |
"generated_prefix": {
|
| 133 |
-
"en": "
|
| 134 |
-
"fr": "
|
| 135 |
-
"es": "
|
| 136 |
-
"de": "
|
| 137 |
},
|
| 138 |
"sources_prefix": {
|
| 139 |
"en": "Sources:",
|
|
@@ -280,11 +346,170 @@ STRINGS: dict[str, dict[str, str]] = {
|
|
| 280 |
|
| 281 |
# ── Flat navigation (Decision Stack) ───────────────────────────────────
|
| 282 |
"nav_company": {"en": "Company Overview", "fr": "Vue d'ensemble", "es": "Panorama de la empresa", "de": "Unternehmensüberblick"},
|
| 283 |
-
"nav_verdict": {"en": "
|
| 284 |
"nav_chat": {"en": "Ask AI", "fr": "Demander à l'IA", "es": "Preguntar a la IA", "de": "KI fragen"},
|
| 285 |
-
"nav_signals": {"en": "
|
| 286 |
"nav_financials": {"en": "Financials", "fr": "Finances", "es": "Finanzas", "de": "Finanzen"},
|
| 287 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
"nav_no_data_tooltip": {
|
| 289 |
"en": "No data yet for this section",
|
| 290 |
"fr": "Pas encore de données pour cette rubrique",
|
|
@@ -570,6 +795,19 @@ STRINGS: dict[str, dict[str, str]] = {
|
|
| 570 |
"primer_backfill_warning": {"en": "Company Overview source coverage is incomplete. Run `python ingest.py {ticker}` to backfill the 10-K Business and segment/geography sections.", "fr": "La couverture des sources de la vue d'ensemble est incomplète. Lancez `python ingest.py {ticker}` pour récupérer les sections Business et segments/géographies du 10-K.", "es": "La cobertura de fuentes del panorama de la empresa está incompleta. Ejecute `python ingest.py {ticker}` para recuperar las secciones Business y segmentos/geografía del 10-K.", "de": "Die Quellenabdeckung des Unternehmensüberblicks ist unvollständig. Führen Sie `python ingest.py {ticker}` aus, um die 10-K-Abschnitte Business und Segmente/Geografie nachzuladen."},
|
| 571 |
"primer_backfill_warning_hosted": {"en": "This deployment's data snapshot does not yet include the 10-K Business and segment/geography sections for {ticker}. The maintainer needs to re-ingest locally and redeploy the data — this cannot be fixed from within the app.", "fr": "Le snapshot de données de ce déploiement ne contient pas encore les sections Business et segments/géographies du 10-K pour {ticker}. Le mainteneur doit relancer l’ingestion en local et redéployer les données — ce problème ne peut pas être corrigé depuis l’application.", "es": "La instantánea de datos de este despliegue aún no incluye las secciones Business y segmentos/geografía del 10-K para {ticker}. El responsable debe volver a ejecutar la ingesta localmente y redesplegar los datos; este problema no se puede corregir desde la aplicación.", "de": "Der Daten-Snapshot dieses Deployments enthält die 10-K-Abschnitte Business und Segmente/Geografie für {ticker} noch nicht. Der Betreiber muss die Daten lokal neu einlesen und erneut bereitstellen; dies kann nicht innerhalb der App behoben werden."},
|
| 572 |
"primer_identity_unavailable": {"en": "The business description is not yet available from verified sources.", "fr": "La description de l’activité n’est pas encore disponible dans les sources vérifiées.", "es": "La descripción del negocio aún no está disponible en fuentes verificadas.", "de": "Die Geschäftsbeschreibung ist aus verifizierten Quellen noch nicht verfügbar."},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 573 |
"primer_business": {"en": "How it makes money", "fr": "Comment l’entreprise gagne de l’argent", "es": "Cómo gana dinero", "de": "Wie das Unternehmen Geld verdient"},
|
| 574 |
"primer_business_unavailable": {"en": "No verified business-line disclosure is available.", "fr": "Aucune ventilation vérifiée des activités n’est disponible.", "es": "No hay desglose verificado de líneas de negocio.", "de": "Keine verifizierte Aufschlüsselung der Geschäftsbereiche verfügbar."},
|
| 575 |
"primer_geography": {"en": "Where it is exposed", "fr": "Où l’entreprise est exposée", "es": "Dónde está expuesta", "de": "Geografische Exponierung"},
|
|
|
|
| 91 |
|
| 92 |
# ── Landing / empty states ─────────────────────────────────────────────
|
| 93 |
"landing_title": {
|
| 94 |
+
"en": "Read a quarter in five minutes",
|
| 95 |
+
"fr": "Lisez un trimestre en cinq minutes",
|
| 96 |
+
"es": "Lea un trimestre en cinco minutos",
|
| 97 |
+
"de": "Ein Quartal in fünf Minuten erfassen",
|
| 98 |
},
|
| 99 |
"landing_body": {
|
| 100 |
+
"en": "Enter a ticker and Amplegest reads the latest SEC filings, the earnings call transcript and recent news, then writes a sourced research brief. Every fact carries its source and a reliability level. No buy or sell calls, no price targets.",
|
| 101 |
+
"fr": "Saisissez un ticker et Amplegest lit les derniers dépôts SEC, la transcription de la conférence de résultats et l'actualité récente, puis rédige un rapport sourcé. Chaque fait porte sa source et un niveau de fiabilité. Aucune recommandation d'achat ou de vente, aucun objectif de cours.",
|
| 102 |
+
"es": "Introduzca un ticker y Amplegest lee los últimos archivos de la SEC, la transcripción de la llamada de resultados y las noticias recientes, y luego redacta un informe con fuentes. Cada dato lleva su fuente y un nivel de fiabilidad. Sin recomendaciones de compra o venta, sin precios objetivo.",
|
| 103 |
+
"de": "Geben Sie ein Tickersymbol ein: Amplegest liest die aktuellen SEC-Einreichungen, das Transkript der Ergebniskonferenz und aktuelle Nachrichten und verfasst daraus einen belegten Bericht. Jede Aussage trägt ihre Quelle und eine Verlässlichkeitsstufe. Keine Kauf- oder Verkaufsempfehlungen, keine Kursziele.",
|
| 104 |
+
},
|
| 105 |
+
"landing_sections_title": {
|
| 106 |
+
"en": "What you get",
|
| 107 |
+
"fr": "Ce que vous obtenez",
|
| 108 |
+
"es": "Qué obtiene",
|
| 109 |
+
"de": "Was Sie erhalten",
|
| 110 |
+
},
|
| 111 |
+
"landing_start_title": {
|
| 112 |
+
"en": "Start with a saved brief",
|
| 113 |
+
"fr": "Commencez par un rapport enregistré",
|
| 114 |
+
"es": "Empiece con un informe guardado",
|
| 115 |
+
"de": "Mit einem gespeicherten Bericht starten",
|
| 116 |
+
},
|
| 117 |
+
"landing_start_body": {
|
| 118 |
+
"en": "These companies are already ingested — open one to see a finished brief without waiting for a run.",
|
| 119 |
+
"fr": "Ces sociétés sont déjà ingérées — ouvrez-en une pour voir un rapport terminé sans attendre une génération.",
|
| 120 |
+
"es": "Estas empresas ya están procesadas — abra una para ver un informe terminado sin esperar a una ejecución.",
|
| 121 |
+
"de": "Diese Unternehmen sind bereits eingelesen — öffnen Sie eines, um einen fertigen Bericht ohne Wartezeit zu sehen.",
|
| 122 |
+
},
|
| 123 |
+
"landing_start_empty": {
|
| 124 |
+
"en": "No saved briefs yet. Enter a ticker in the sidebar to generate the first one.",
|
| 125 |
+
"fr": "Aucun rapport enregistré. Saisissez un ticker dans la barre latérale pour générer le premier.",
|
| 126 |
+
"es": "Aún no hay informes guardados. Introduzca un ticker en la barra lateral para generar el primero.",
|
| 127 |
+
"de": "Noch keine gespeicherten Berichte. Geben Sie links ein Tickersymbol ein, um den ersten zu erstellen.",
|
| 128 |
+
},
|
| 129 |
+
"landing_card_company": {
|
| 130 |
+
"en": "How the company makes money, where it is exposed, and three years of revenue, margin, cash and EPS.",
|
| 131 |
+
"fr": "Comment la société gagne de l'argent, ses expositions, et trois ans de chiffre d'affaires, marge, trésorerie et BPA.",
|
| 132 |
+
"es": "Cómo gana dinero la empresa, dónde está expuesta y tres años de ingresos, margen, caja y BPA.",
|
| 133 |
+
"de": "Wie das Unternehmen Geld verdient, wo es exponiert ist, und drei Jahre Umsatz, Marge, Cash und Gewinn je Aktie.",
|
| 134 |
+
},
|
| 135 |
+
"landing_card_verdict": {
|
| 136 |
+
"en": "The quarter in one screen: what changed, what matters most, the bull and bear case, and what to watch next.",
|
| 137 |
+
"fr": "Le trimestre en un écran : ce qui a changé, ce qui compte le plus, les arguments haussiers et baissiers, et quoi surveiller.",
|
| 138 |
+
"es": "El trimestre en una pantalla: qué cambió, qué importa más, la tesis alcista y bajista, y qué vigilar.",
|
| 139 |
+
"de": "Das Quartal auf einem Schirm: was sich geändert hat, was am meisten zählt, Bull- und Bear-Case und worauf zu achten ist.",
|
| 140 |
+
},
|
| 141 |
+
"landing_card_signals": {
|
| 142 |
+
"en": "Side-by-side wording changes between this filing and the last, each with the source text behind it.",
|
| 143 |
+
"fr": "Les changements de formulation entre ce dépôt et le précédent, chacun avec son texte source.",
|
| 144 |
+
"es": "Los cambios de redacción entre este archivo y el anterior, cada uno con su texto fuente.",
|
| 145 |
+
"de": "Formulierungsänderungen zwischen dieser und der letzten Einreichung, jeweils mit Quelltext.",
|
| 146 |
+
},
|
| 147 |
+
"landing_card_financials": {
|
| 148 |
+
"en": "Reported KPIs, quarterly series, peer multiples and the earnings-surprise history, all exportable.",
|
| 149 |
+
"fr": "KPI publiés, séries trimestrielles, multiples des comparables et historique des surprises, exportables.",
|
| 150 |
+
"es": "KPI publicados, series trimestrales, múltiplos de comparables e historial de sorpresas, exportables.",
|
| 151 |
+
"de": "Berichtete Kennzahlen, Quartalsreihen, Peer-Multiples und die Historie der Ergebnisüberraschungen, exportierbar.",
|
| 152 |
+
},
|
| 153 |
+
"landing_card_chat": {
|
| 154 |
+
"en": "Ask a question and get an answer drawn only from this company's filings and transcripts.",
|
| 155 |
+
"fr": "Posez une question et obtenez une réponse tirée uniquement des dépôts et transcriptions de cette société.",
|
| 156 |
+
"es": "Haga una pregunta y obtenga una respuesta extraída solo de los archivos y transcripciones de esta empresa.",
|
| 157 |
+
"de": "Stellen Sie eine Frage und erhalten Sie eine Antwort ausschließlich aus den Unterlagen dieses Unternehmens.",
|
| 158 |
+
},
|
| 159 |
+
"standout_number_label": {
|
| 160 |
+
"en": "Standout number",
|
| 161 |
+
"fr": "Chiffre marquant",
|
| 162 |
+
"es": "Cifra destacada",
|
| 163 |
+
"de": "Herausragende Zahl",
|
| 164 |
+
},
|
| 165 |
+
"non_obvious_takeaway_label": {
|
| 166 |
+
"en": "Non-obvious takeaway",
|
| 167 |
+
"fr": "À ne pas manquer",
|
| 168 |
+
"es": "Lo que no es obvio",
|
| 169 |
+
"de": "Nicht offensichtliche Erkenntnis",
|
| 170 |
},
|
| 171 |
"snapshot_empty_title": {
|
| 172 |
"en": "Ready to analyze",
|
|
|
|
| 196 |
"de": "Stand",
|
| 197 |
},
|
| 198 |
"generated_prefix": {
|
| 199 |
+
"en": "generated",
|
| 200 |
+
"fr": "généré le",
|
| 201 |
+
"es": "generado el",
|
| 202 |
+
"de": "erstellt am",
|
| 203 |
},
|
| 204 |
"sources_prefix": {
|
| 205 |
"en": "Sources:",
|
|
|
|
| 346 |
|
| 347 |
# ── Flat navigation (Decision Stack) ───────────────────────────────────
|
| 348 |
"nav_company": {"en": "Company Overview", "fr": "Vue d'ensemble", "es": "Panorama de la empresa", "de": "Unternehmensüberblick"},
|
| 349 |
+
"nav_verdict": {"en": "The Brief", "fr": "Le rapport", "es": "El informe", "de": "Der Bericht"},
|
| 350 |
"nav_chat": {"en": "Ask AI", "fr": "Demander à l'IA", "es": "Preguntar a la IA", "de": "KI fragen"},
|
| 351 |
+
"nav_signals": {"en": "What Changed", "fr": "Ce qui a changé", "es": "Qué ha cambiado", "de": "Was sich geändert hat"},
|
| 352 |
"nav_financials": {"en": "Financials", "fr": "Finances", "es": "Finanzas", "de": "Finanzen"},
|
| 353 |
|
| 354 |
+
# ── The Brief (verdict screen) ─────────────────────────────────────────
|
| 355 |
+
# These were hardcoded English in dashboard/verdict.py; several also named
|
| 356 |
+
# the old "Evidence & Deltas" label, which no longer exists in the nav.
|
| 357 |
+
# ── Market band + quarter KPIs on The Brief ────────────────────────────
|
| 358 |
+
"brief_price_label": {"en": "Price", "fr": "Cours", "es": "Precio", "de": "Kurs"},
|
| 359 |
+
"brief_market_cap_label": {"en": "Market cap", "fr": "Capitalisation", "es": "Capitalización", "de": "Marktkapitalisierung"},
|
| 360 |
+
"brief_52w_label": {"en": "52-week range", "fr": "Plage 52 semaines", "es": "Rango 52 semanas", "de": "52-Wochen-Spanne"},
|
| 361 |
+
"brief_div_yield_label": {"en": "Dividend yield", "fr": "Rendement du dividende", "es": "Rentabilidad por dividendo", "de": "Dividendenrendite"},
|
| 362 |
+
"brief_quote_note": {
|
| 363 |
+
"en": "Delayed quote via yfinance — market context only, not a valuation.",
|
| 364 |
+
"fr": "Cours différé via yfinance — contexte de marché uniquement, pas une valorisation.",
|
| 365 |
+
"es": "Cotización diferida vía yfinance — solo contexto de mercado, no una valoración.",
|
| 366 |
+
"de": "Verzögerter Kurs über yfinance — nur Marktkontext, keine Bewertung.",
|
| 367 |
+
},
|
| 368 |
+
"brief_quarter_title": {
|
| 369 |
+
"en": "The quarter in numbers",
|
| 370 |
+
"fr": "Le trimestre en chiffres",
|
| 371 |
+
"es": "El trimestre en cifras",
|
| 372 |
+
"de": "Das Quartal in Zahlen",
|
| 373 |
+
},
|
| 374 |
+
"brief_quarter_note": {
|
| 375 |
+
"en": "Reported figures from the filing named above. Full series and export in {section}.",
|
| 376 |
+
"fr": "Chiffres publiés dans le dépôt cité ci-dessus. Séries complètes et export dans {section}.",
|
| 377 |
+
"es": "Cifras publicadas en el archivo citado arriba. Series completas y exportación en {section}.",
|
| 378 |
+
"de": "Berichtete Zahlen aus der oben genannten Einreichung. Vollständige Reihen und Export in {section}.",
|
| 379 |
+
},
|
| 380 |
+
"brief_what_changed_title": {
|
| 381 |
+
"en": "What changed this quarter",
|
| 382 |
+
"fr": "Ce qui a changé ce trimestre",
|
| 383 |
+
"es": "Qué cambió este trimestre",
|
| 384 |
+
"de": "Was sich in diesem Quartal geändert hat",
|
| 385 |
+
},
|
| 386 |
+
"brief_watch_title": {
|
| 387 |
+
"en": "What to watch next",
|
| 388 |
+
"fr": "À surveiller ensuite",
|
| 389 |
+
"es": "Qué vigilar a continuación",
|
| 390 |
+
"de": "Worauf als Nächstes zu achten ist",
|
| 391 |
+
},
|
| 392 |
+
"brief_watch_more": {
|
| 393 |
+
"en": "{count} more watch items",
|
| 394 |
+
"fr": "{count} autres points à surveiller",
|
| 395 |
+
"es": "{count} puntos más a vigilar",
|
| 396 |
+
"de": "{count} weitere Beobachtungspunkte",
|
| 397 |
+
},
|
| 398 |
+
"brief_watch_more_one": {
|
| 399 |
+
"en": "1 more watch item",
|
| 400 |
+
"fr": "1 autre point à surveiller",
|
| 401 |
+
"es": "1 punto más a vigilar",
|
| 402 |
+
"de": "1 weiterer Beobachtungspunkt",
|
| 403 |
+
},
|
| 404 |
+
"brief_metric_revenue": {"en": "Revenue", "fr": "Chiffre d’affaires", "es": "Ingresos", "de": "Umsatz"},
|
| 405 |
+
"brief_metric_eps": {"en": "EPS (diluted)", "fr": "BPA (dilué)", "es": "BPA (diluido)", "de": "Gewinn je Aktie (verwässert)"},
|
| 406 |
+
"brief_metric_gross_margin": {"en": "Gross margin", "fr": "Marge brute", "es": "Margen bruto", "de": "Bruttomarge"},
|
| 407 |
+
"brief_metric_op_margin": {"en": "Operating margin", "fr": "Marge opérationnelle", "es": "Margen operativo", "de": "Operative Marge"},
|
| 408 |
+
"brief_metric_fcf": {"en": "Free cash flow", "fr": "Flux de trésorerie disponible", "es": "Flujo de caja libre", "de": "Freier Cashflow"},
|
| 409 |
+
"read_through_label": {
|
| 410 |
+
"en": "What this quarter means",
|
| 411 |
+
"fr": "Ce que signifie ce trimestre",
|
| 412 |
+
"es": "Qué significa este trimestre",
|
| 413 |
+
"de": "Was dieses Quartal bedeutet",
|
| 414 |
+
},
|
| 415 |
+
"thesis_test_title": {
|
| 416 |
+
"en": "Bull and bear case",
|
| 417 |
+
"fr": "Arguments haussiers et baissiers",
|
| 418 |
+
"es": "Tesis alcista y bajista",
|
| 419 |
+
"de": "Bull- und Bear-Case",
|
| 420 |
+
},
|
| 421 |
+
"thesis_confirming": {
|
| 422 |
+
"en": "Supports the bull case",
|
| 423 |
+
"fr": "Soutient la thèse haussière",
|
| 424 |
+
"es": "Apoya la tesis alcista",
|
| 425 |
+
"de": "Stützt den Bull-Case",
|
| 426 |
+
},
|
| 427 |
+
"thesis_challenging": {
|
| 428 |
+
"en": "Supports the bear case",
|
| 429 |
+
"fr": "Soutient la thèse baissière",
|
| 430 |
+
"es": "Apoya la tesis bajista",
|
| 431 |
+
"de": "Stützt den Bear-Case",
|
| 432 |
+
},
|
| 433 |
+
"thesis_unavailable": {
|
| 434 |
+
"en": "No bull or bear points passed source verification for this quarter, so this section is empty rather than unsourced. The underlying wording changes are still in {section}.",
|
| 435 |
+
"fr": "Aucun argument haussier ou baissier n'a passé la vérification des sources pour ce trimestre ; cette section est donc vide plutôt que non sourcée. Les changements de formulation restent consultables dans {section}.",
|
| 436 |
+
"es": "Ningún punto alcista o bajista superó la verificación de fuentes este trimestre, por lo que esta sección está vacía en lugar de no verificada. Los cambios de redacción siguen en {section}.",
|
| 437 |
+
"de": "Für dieses Quartal hat kein Bull- oder Bear-Punkt die Quellenprüfung bestanden; der Abschnitt bleibt daher leer statt unbelegt. Die Formulierungsänderungen finden sich weiterhin in {section}.",
|
| 438 |
+
},
|
| 439 |
+
"swing_factor_title": {
|
| 440 |
+
"en": "Swing factor",
|
| 441 |
+
"fr": "Facteur décisif",
|
| 442 |
+
"es": "Factor decisivo",
|
| 443 |
+
"de": "Ausschlaggebender Faktor",
|
| 444 |
+
},
|
| 445 |
+
"swing_hypothesis_note": {
|
| 446 |
+
"en": "Hypothesis — validate against the cited evidence.",
|
| 447 |
+
"fr": "Hypothèse — à valider avec les sources citées.",
|
| 448 |
+
"es": "Hipótesis — valídela con las fuentes citadas.",
|
| 449 |
+
"de": "Hypothese — anhand der zitierten Belege prüfen.",
|
| 450 |
+
},
|
| 451 |
+
"swing_default_headline": {
|
| 452 |
+
"en": "Potential decision swing",
|
| 453 |
+
"fr": "Point de bascule potentiel",
|
| 454 |
+
"es": "Posible punto de inflexión",
|
| 455 |
+
"de": "Möglicher Wendepunkt",
|
| 456 |
+
},
|
| 457 |
+
"swing_if_confirmed": {
|
| 458 |
+
"en": "If confirmed",
|
| 459 |
+
"fr": "Si confirmé",
|
| 460 |
+
"es": "Si se confirma",
|
| 461 |
+
"de": "Wenn bestätigt",
|
| 462 |
+
},
|
| 463 |
+
"swing_if_challenged": {
|
| 464 |
+
"en": "If challenged",
|
| 465 |
+
"fr": "Si infirmé",
|
| 466 |
+
"es": "Si se refuta",
|
| 467 |
+
"de": "Wenn widerlegt",
|
| 468 |
+
},
|
| 469 |
+
"swing_implication": {
|
| 470 |
+
"en": "Implication:",
|
| 471 |
+
"fr": "Implication :",
|
| 472 |
+
"es": "Implicación:",
|
| 473 |
+
"de": "Implikation:",
|
| 474 |
+
},
|
| 475 |
+
"open_evidence_cta": {
|
| 476 |
+
"en": "See the source changes",
|
| 477 |
+
"fr": "Voir les changements sources",
|
| 478 |
+
"es": "Ver los cambios de origen",
|
| 479 |
+
"de": "Quellenänderungen ansehen",
|
| 480 |
+
},
|
| 481 |
+
"validate_evidence_cta": {
|
| 482 |
+
"en": "Check this against the sources",
|
| 483 |
+
"fr": "Vérifier avec les sources",
|
| 484 |
+
"es": "Comprobar con las fuentes",
|
| 485 |
+
"de": "Anhand der Quellen prüfen",
|
| 486 |
+
},
|
| 487 |
+
"evidence_weak_title": {
|
| 488 |
+
"en": "Most facts in this brief are not source-verified",
|
| 489 |
+
"fr": "La plupart des faits de ce rapport ne sont pas vérifiés",
|
| 490 |
+
"es": "La mayoría de los datos de este informe no están verificados",
|
| 491 |
+
"de": "Die meisten Aussagen in diesem Bericht sind nicht quellengeprüft",
|
| 492 |
+
},
|
| 493 |
+
"evidence_weak_body": {
|
| 494 |
+
"en": "{verified} of {total} statements could be matched back to their source text. Treat the rest as unconfirmed and check them in {section} before relying on them.",
|
| 495 |
+
"fr": "{verified} affirmation(s) sur {total} ont pu être rattachées à leur texte source. Considérez le reste comme non confirmé et vérifiez-le dans {section} avant de vous y fier.",
|
| 496 |
+
"es": "{verified} de {total} afirmaciones pudieron rastrearse hasta su texto fuente. Considere el resto sin confirmar y compruébelo en {section} antes de fiarse.",
|
| 497 |
+
"de": "{verified} von {total} Aussagen ließen sich auf ihren Quelltext zurückführen. Behandeln Sie den Rest als unbestätigt und prüfen Sie ihn in {section}.",
|
| 498 |
+
},
|
| 499 |
+
"verdict_tools_label": {
|
| 500 |
+
"en": "Sources and export",
|
| 501 |
+
"fr": "Sources et export",
|
| 502 |
+
"es": "Fuentes y exportación",
|
| 503 |
+
"de": "Quellen und Export",
|
| 504 |
+
},
|
| 505 |
+
|
| 506 |
+
"show_full_passage": {
|
| 507 |
+
"en": "show the rest",
|
| 508 |
+
"fr": "afficher la suite",
|
| 509 |
+
"es": "mostrar el resto",
|
| 510 |
+
"de": "Rest anzeigen",
|
| 511 |
+
},
|
| 512 |
+
|
| 513 |
"nav_no_data_tooltip": {
|
| 514 |
"en": "No data yet for this section",
|
| 515 |
"fr": "Pas encore de données pour cette rubrique",
|
|
|
|
| 795 |
"primer_backfill_warning": {"en": "Company Overview source coverage is incomplete. Run `python ingest.py {ticker}` to backfill the 10-K Business and segment/geography sections.", "fr": "La couverture des sources de la vue d'ensemble est incomplète. Lancez `python ingest.py {ticker}` pour récupérer les sections Business et segments/géographies du 10-K.", "es": "La cobertura de fuentes del panorama de la empresa está incompleta. Ejecute `python ingest.py {ticker}` para recuperar las secciones Business y segmentos/geografía del 10-K.", "de": "Die Quellenabdeckung des Unternehmensüberblicks ist unvollständig. Führen Sie `python ingest.py {ticker}` aus, um die 10-K-Abschnitte Business und Segmente/Geografie nachzuladen."},
|
| 796 |
"primer_backfill_warning_hosted": {"en": "This deployment's data snapshot does not yet include the 10-K Business and segment/geography sections for {ticker}. The maintainer needs to re-ingest locally and redeploy the data — this cannot be fixed from within the app.", "fr": "Le snapshot de données de ce déploiement ne contient pas encore les sections Business et segments/géographies du 10-K pour {ticker}. Le mainteneur doit relancer l’ingestion en local et redéployer les données — ce problème ne peut pas être corrigé depuis l’application.", "es": "La instantánea de datos de este despliegue aún no incluye las secciones Business y segmentos/geografía del 10-K para {ticker}. El responsable debe volver a ejecutar la ingesta localmente y redesplegar los datos; este problema no se puede corregir desde la aplicación.", "de": "Der Daten-Snapshot dieses Deployments enthält die 10-K-Abschnitte Business und Segmente/Geografie für {ticker} noch nicht. Der Betreiber muss die Daten lokal neu einlesen und erneut bereitstellen; dies kann nicht innerhalb der App behoben werden."},
|
| 797 |
"primer_identity_unavailable": {"en": "The business description is not yet available from verified sources.", "fr": "La description de l’activité n’est pas encore disponible dans les sources vérifiées.", "es": "La descripción del negocio aún no está disponible en fuentes verificadas.", "de": "Die Geschäftsbeschreibung ist aus verifizierten Quellen noch nicht verfügbar."},
|
| 798 |
+
"primer_identity": {"en": "What the company does", "fr": "Ce que fait l’entreprise", "es": "Qué hace la empresa", "de": "Was das Unternehmen macht"},
|
| 799 |
+
"primer_gaps_label": {
|
| 800 |
+
"en": "Not available for this company yet",
|
| 801 |
+
"fr": "Pas encore disponible pour cette société",
|
| 802 |
+
"es": "Aún no disponible para esta empresa",
|
| 803 |
+
"de": "Für dieses Unternehmen noch nicht verfügbar",
|
| 804 |
+
},
|
| 805 |
+
"primer_gaps_body": {
|
| 806 |
+
"en": "These sections stay empty rather than showing unverified text. They appear once the underlying disclosure has been ingested.",
|
| 807 |
+
"fr": "Ces sections restent vides plutôt que d’afficher du texte non vérifié. Elles apparaîtront une fois la source correspondante ingérée.",
|
| 808 |
+
"es": "Estas secciones quedan vacías en lugar de mostrar texto no verificado. Aparecerán cuando se procese la fuente correspondiente.",
|
| 809 |
+
"de": "Diese Abschnitte bleiben leer, statt ungeprüften Text zu zeigen. Sie erscheinen, sobald die zugehörige Quelle eingelesen ist.",
|
| 810 |
+
},
|
| 811 |
"primer_business": {"en": "How it makes money", "fr": "Comment l’entreprise gagne de l’argent", "es": "Cómo gana dinero", "de": "Wie das Unternehmen Geld verdient"},
|
| 812 |
"primer_business_unavailable": {"en": "No verified business-line disclosure is available.", "fr": "Aucune ventilation vérifiée des activités n’est disponible.", "es": "No hay desglose verificado de líneas de negocio.", "de": "Keine verifizierte Aufschlüsselung der Geschäftsbereiche verfügbar."},
|
| 813 |
"primer_geography": {"en": "Where it is exposed", "fr": "Où l’entreprise est exposée", "es": "Dónde está expuesta", "de": "Geografische Exponierung"},
|
|
@@ -155,7 +155,7 @@ def render_print_panel(mr: dict) -> None:
|
|
| 155 |
st.caption("Market reaction and consensus are hidden until period and event alignment are verified.")
|
| 156 |
return
|
| 157 |
from dashboard.theme import (
|
| 158 |
-
GREEN, RED, GRAY, BORDER, TEXT, TEXT_FAINT, BULL_BG, BEAR_BG, BG_MUTED,
|
| 159 |
)
|
| 160 |
|
| 161 |
cells: list[str] = []
|
|
@@ -249,7 +249,7 @@ def render_print_panel(mr: dict) -> None:
|
|
| 249 |
|
| 250 |
st.markdown(
|
| 251 |
f'<div class="primer-card" style="border:1px solid {BORDER};border-radius:12px;'
|
| 252 |
-
f'background:
|
| 253 |
f'<div style="display:flex;flex-wrap:wrap;align-items:stretch;">'
|
| 254 |
f'{"".join(cells)}</div>'
|
| 255 |
f'{provenance}'
|
|
|
|
| 155 |
st.caption("Market reaction and consensus are hidden until period and event alignment are verified.")
|
| 156 |
return
|
| 157 |
from dashboard.theme import (
|
| 158 |
+
GREEN, RED, GRAY, BORDER, TEXT, TEXT_FAINT, BULL_BG, BEAR_BG, BG, BG_MUTED,
|
| 159 |
)
|
| 160 |
|
| 161 |
cells: list[str] = []
|
|
|
|
| 249 |
|
| 250 |
st.markdown(
|
| 251 |
f'<div class="primer-card" style="border:1px solid {BORDER};border-radius:12px;'
|
| 252 |
+
f'background:{BG};margin-bottom:8px;">'
|
| 253 |
f'<div style="display:flex;flex-wrap:wrap;align-items:stretch;">'
|
| 254 |
f'{"".join(cells)}</div>'
|
| 255 |
f'{provenance}'
|
|
@@ -1,7 +1,7 @@
|
|
| 1 |
"""Data-driven sidebar navigation for Amplegest — institutional style.
|
| 2 |
|
| 3 |
Five primary destinations, from company onboarding to decision, audit, and tooling:
|
| 4 |
-
Company Overview →
|
| 5 |
|
| 6 |
Each item has a stable ``key`` decoupled from its display label,
|
| 7 |
so renaming a section never breaks routing.
|
|
@@ -16,11 +16,11 @@ from dashboard.i18n import t
|
|
| 16 |
# exclusively for the AI tool (Chat), so a glance at the sidebar tells you
|
| 17 |
# "data screen" from "AI screen" without six competing hues to parse.
|
| 18 |
SECTION_COLORS: dict[str, tuple[str, str, str]] = {
|
| 19 |
-
"company": ("#
|
| 20 |
-
"verdict": ("#
|
| 21 |
-
"signals": ("#
|
| 22 |
-
"financials": ("#
|
| 23 |
-
"chat": ("#
|
| 24 |
}
|
| 25 |
|
| 26 |
# ── Navigation items ──────────────────────────────────────────────────────────
|
|
@@ -139,18 +139,18 @@ def render(items: list[dict], active_key: str, brief: dict | None = None) -> Non
|
|
| 139 |
/* ── Nav button base — sidebar only, scoped to nav_ keys ─────────────── */
|
| 140 |
[data-testid="stSidebar"] [class*="st-key-nav_"] [data-testid="stBaseButton-secondary"] {{
|
| 141 |
background: transparent !important;
|
| 142 |
-
border: 1px solid #
|
| 143 |
border-radius: 6px !important;
|
| 144 |
padding: 7px 10px !important;
|
| 145 |
font-size: 0.84rem !important;
|
| 146 |
font-weight: 500 !important;
|
| 147 |
-
color: #
|
| 148 |
box-shadow: none !important;
|
| 149 |
justify-content: flex-start !important;
|
| 150 |
position: relative !important;
|
| 151 |
}}
|
| 152 |
[data-testid="stSidebar"] [class*="st-key-nav_"] [data-testid="stBaseButton-secondary"]:hover {{
|
| 153 |
-
background: #
|
| 154 |
}}
|
| 155 |
/* ── Per-section colors ───────────────────────────────────────────────── */
|
| 156 |
{per_section_css}
|
|
|
|
| 1 |
"""Data-driven sidebar navigation for Amplegest — institutional style.
|
| 2 |
|
| 3 |
Five primary destinations, from company onboarding to decision, audit, and tooling:
|
| 4 |
+
Company Overview → The Brief → What Changed → Financials → Ask AI
|
| 5 |
|
| 6 |
Each item has a stable ``key`` decoupled from its display label,
|
| 7 |
so renaming a section never breaks routing.
|
|
|
|
| 16 |
# exclusively for the AI tool (Chat), so a glance at the sidebar tells you
|
| 17 |
# "data screen" from "AI screen" without six competing hues to parse.
|
| 18 |
SECTION_COLORS: dict[str, tuple[str, str, str]] = {
|
| 19 |
+
"company": ("#34d399", "#10251d", "#1f5b45"), # emerald (brand)
|
| 20 |
+
"verdict": ("#34d399", "#10251d", "#1f5b45"), # emerald (brand)
|
| 21 |
+
"signals": ("#34d399", "#10251d", "#1f5b45"), # emerald (brand)
|
| 22 |
+
"financials": ("#34d399", "#10251d", "#1f5b45"), # emerald (brand)
|
| 23 |
+
"chat": ("#a78bfa", "#1e1633", "#432d7a"), # violet — AI, exclusively
|
| 24 |
}
|
| 25 |
|
| 26 |
# ── Navigation items ──────────────────────────────────────────────────────────
|
|
|
|
| 139 |
/* ── Nav button base — sidebar only, scoped to nav_ keys ─────────────── */
|
| 140 |
[data-testid="stSidebar"] [class*="st-key-nav_"] [data-testid="stBaseButton-secondary"] {{
|
| 141 |
background: transparent !important;
|
| 142 |
+
border: 1px solid #2b323c !important;
|
| 143 |
border-radius: 6px !important;
|
| 144 |
padding: 7px 10px !important;
|
| 145 |
font-size: 0.84rem !important;
|
| 146 |
font-weight: 500 !important;
|
| 147 |
+
color: #aab4c0 !important;
|
| 148 |
box-shadow: none !important;
|
| 149 |
justify-content: flex-start !important;
|
| 150 |
position: relative !important;
|
| 151 |
}}
|
| 152 |
[data-testid="stSidebar"] [class*="st-key-nav_"] [data-testid="stBaseButton-secondary"]:hover {{
|
| 153 |
+
background: #1e242d !important;
|
| 154 |
}}
|
| 155 |
/* ── Per-section colors ───────────────────────────────────────────────── */
|
| 156 |
{per_section_css}
|
|
@@ -117,7 +117,7 @@ def render_card(ticker: str, brief: dict, *, expanded: bool = False) -> None:
|
|
| 117 |
stale_badge = ""
|
| 118 |
if info["transcript_stale"]:
|
| 119 |
stale_badge = (
|
| 120 |
-
f'<span style="background:#
|
| 121 |
f'border-radius:4px;padding:1px 6px;font-size:0.65rem;font-weight:700;margin-left:6px;">'
|
| 122 |
f'{t("provenance_lagging")}</span>'
|
| 123 |
)
|
|
|
|
| 117 |
stale_badge = ""
|
| 118 |
if info["transcript_stale"]:
|
| 119 |
stale_badge = (
|
| 120 |
+
f'<span style="background:#2a2113;color:{AMBER};border:1px solid {AMBER}55;'
|
| 121 |
f'border-radius:4px;padding:1px 6px;font-size:0.65rem;font-weight:700;margin-left:6px;">'
|
| 122 |
f'{t("provenance_lagging")}</span>'
|
| 123 |
)
|
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
"""
|
| 2 |
|
| 3 |
Replaces the former MD&A / Earnings Call / Risks / Quality & Tone tabs:
|
| 4 |
their content is normalized by dashboard/signal_feed.py and rendered with
|
|
@@ -13,7 +13,7 @@ from dashboard import fmt_period
|
|
| 13 |
from dashboard.i18n import t
|
| 14 |
from dashboard.theme import (
|
| 15 |
GREEN, RED, GRAY, AMBER,
|
| 16 |
-
BG_MUTED, BORDER, TEXT, TEXT_MUTED, TEXT_FAINT,
|
| 17 |
BULL_BG, BEAR_BG,
|
| 18 |
FS_PAGE, FS_META, FS_EYEBROW,
|
| 19 |
)
|
|
@@ -46,7 +46,7 @@ def _gauge_html(score: int) -> str:
|
|
| 46 |
dot_color = GREEN if score > 0 else (RED if score < 0 else GRAY)
|
| 47 |
return (
|
| 48 |
f'<div style="margin:4px 0 2px;height:6px;border-radius:99px;position:relative;'
|
| 49 |
-
f'background:linear-gradient(90deg,#
|
| 50 |
f'<div style="position:absolute;top:50%;left:{pct:.1f}%;transform:translate(-50%,-50%);'
|
| 51 |
f'width:12px;height:12px;border-radius:50%;background:{dot_color};'
|
| 52 |
f'border:2px solid #fff;box-shadow:0 0 0 1.5px {dot_color};"></div>'
|
|
@@ -71,7 +71,7 @@ def _render_sentiment_strip(sentiment: dict | None) -> None:
|
|
| 71 |
section = sentiment.get(key)
|
| 72 |
if section is None or section.get("score") is None:
|
| 73 |
cells_html += (
|
| 74 |
-
f'<div style="padding:10px 12px;border-right:1px solid {BORDER};background:
|
| 75 |
f'<div style="font-size:{FS_EYEBROW};font-weight:700;text-transform:uppercase;'
|
| 76 |
f'letter-spacing:0.07em;color:{TEXT_MUTED};margin-bottom:6px;">{label}</div>'
|
| 77 |
f'<div style="font-size:0.68rem;color:{TEXT_MUTED};">—</div>'
|
|
@@ -82,7 +82,7 @@ def _render_sentiment_strip(sentiment: dict | None) -> None:
|
|
| 82 |
fg = GREEN if score > 0 else (RED if score < 0 else GRAY)
|
| 83 |
rationale = section.get("rationale", "")
|
| 84 |
cells_html += (
|
| 85 |
-
f'<div style="padding:10px 12px;border-right:1px solid {BORDER};background:
|
| 86 |
f'<div style="font-size:{FS_EYEBROW};font-weight:700;text-transform:uppercase;'
|
| 87 |
f'letter-spacing:0.07em;color:{TEXT_MUTED};margin-bottom:4px;">{label}</div>'
|
| 88 |
f'{_gauge_html(score)}'
|
|
@@ -118,7 +118,7 @@ def _sentiment_display_allowed(brief: dict) -> bool:
|
|
| 118 |
|
| 119 |
def _render_experimental_notice() -> None:
|
| 120 |
st.markdown(
|
| 121 |
-
f'<div style="background:#
|
| 122 |
f'border-left:3px solid {AMBER};border-radius:0 8px 8px 0;'
|
| 123 |
f'padding:9px 12px;margin:0 0 16px;font-size:{FS_META};'
|
| 124 |
f'line-height:1.5;color:{TEXT_MUTED};">'
|
|
@@ -339,7 +339,7 @@ def render(brief: dict, ticker: str) -> None:
|
|
| 339 |
st.markdown(
|
| 340 |
f'<div style="margin-bottom:16px;padding-bottom:12px;border-bottom:1px solid {BORDER};">'
|
| 341 |
f'<div style="font-size:{FS_PAGE};font-weight:700;color:{TEXT};letter-spacing:-0.02em;">'
|
| 342 |
-
f'
|
| 343 |
f'<div style="font-size:{FS_META};color:{TEXT_FAINT};margin-top:4px;">{subtitle}</div>'
|
| 344 |
f'</div>',
|
| 345 |
unsafe_allow_html=True,
|
|
|
|
| 1 |
+
"""What Changed — source-backed signals in one ranked, filterable stream.
|
| 2 |
|
| 3 |
Replaces the former MD&A / Earnings Call / Risks / Quality & Tone tabs:
|
| 4 |
their content is normalized by dashboard/signal_feed.py and rendered with
|
|
|
|
| 13 |
from dashboard.i18n import t
|
| 14 |
from dashboard.theme import (
|
| 15 |
GREEN, RED, GRAY, AMBER,
|
| 16 |
+
BG, BG_MUTED, BORDER, TEXT, TEXT_MUTED, TEXT_FAINT,
|
| 17 |
BULL_BG, BEAR_BG,
|
| 18 |
FS_PAGE, FS_META, FS_EYEBROW,
|
| 19 |
)
|
|
|
|
| 46 |
dot_color = GREEN if score > 0 else (RED if score < 0 else GRAY)
|
| 47 |
return (
|
| 48 |
f'<div style="margin:4px 0 2px;height:6px;border-radius:99px;position:relative;'
|
| 49 |
+
f'background:linear-gradient(90deg,#6b2b2f 0%,#6b5320 38%,#14352a 62%,#6ee7b7 100%);">'
|
| 50 |
f'<div style="position:absolute;top:50%;left:{pct:.1f}%;transform:translate(-50%,-50%);'
|
| 51 |
f'width:12px;height:12px;border-radius:50%;background:{dot_color};'
|
| 52 |
f'border:2px solid #fff;box-shadow:0 0 0 1.5px {dot_color};"></div>'
|
|
|
|
| 71 |
section = sentiment.get(key)
|
| 72 |
if section is None or section.get("score") is None:
|
| 73 |
cells_html += (
|
| 74 |
+
f'<div style="padding:10px 12px;border-right:1px solid {BORDER};background:{BG};">'
|
| 75 |
f'<div style="font-size:{FS_EYEBROW};font-weight:700;text-transform:uppercase;'
|
| 76 |
f'letter-spacing:0.07em;color:{TEXT_MUTED};margin-bottom:6px;">{label}</div>'
|
| 77 |
f'<div style="font-size:0.68rem;color:{TEXT_MUTED};">—</div>'
|
|
|
|
| 82 |
fg = GREEN if score > 0 else (RED if score < 0 else GRAY)
|
| 83 |
rationale = section.get("rationale", "")
|
| 84 |
cells_html += (
|
| 85 |
+
f'<div style="padding:10px 12px;border-right:1px solid {BORDER};background:{BG};">'
|
| 86 |
f'<div style="font-size:{FS_EYEBROW};font-weight:700;text-transform:uppercase;'
|
| 87 |
f'letter-spacing:0.07em;color:{TEXT_MUTED};margin-bottom:4px;">{label}</div>'
|
| 88 |
f'{_gauge_html(score)}'
|
|
|
|
| 118 |
|
| 119 |
def _render_experimental_notice() -> None:
|
| 120 |
st.markdown(
|
| 121 |
+
f'<div style="background:#2a2113;border:1px solid #6b5320;'
|
| 122 |
f'border-left:3px solid {AMBER};border-radius:0 8px 8px 0;'
|
| 123 |
f'padding:9px 12px;margin:0 0 16px;font-size:{FS_META};'
|
| 124 |
f'line-height:1.5;color:{TEXT_MUTED};">'
|
|
|
|
| 339 |
st.markdown(
|
| 340 |
f'<div style="margin-bottom:16px;padding-bottom:12px;border-bottom:1px solid {BORDER};">'
|
| 341 |
f'<div style="font-size:{FS_PAGE};font-weight:700;color:{TEXT};letter-spacing:-0.02em;">'
|
| 342 |
+
f'{t("nav_signals")}</div>'
|
| 343 |
f'<div style="font-size:{FS_META};color:{TEXT_FAINT};margin-top:4px;">{subtitle}</div>'
|
| 344 |
f'</div>',
|
| 345 |
unsafe_allow_html=True,
|
|
@@ -3,62 +3,62 @@ from __future__ import annotations
|
|
| 3 |
import streamlit as st
|
| 4 |
|
| 5 |
# ── Brand ─────────────────────────────────────────────────────────────────────
|
| 6 |
-
BRAND_GREEN = "#
|
| 7 |
-
BRAND_GREEN_DARK = "#
|
| 8 |
|
| 9 |
# ── Surfaces ──────────────────────────────────────────────────────────────────
|
| 10 |
-
BG = "#
|
| 11 |
-
BG_MUTED = "#
|
| 12 |
-
BORDER = "#
|
| 13 |
-
BORDER_STRONG = "#
|
| 14 |
|
| 15 |
# ── Text ──────────────────────────────────────────────────────────────────────
|
| 16 |
-
TEXT = "#
|
| 17 |
-
TEXT_MUTED = "#
|
| 18 |
-
TEXT_FAINT = "#
|
| 19 |
-
|
| 20 |
-
# ── Semantic palette (
|
| 21 |
-
GREEN = "#
|
| 22 |
-
BULL = "#
|
| 23 |
-
BULL_BG = "#
|
| 24 |
-
BULL_BORDER = "#
|
| 25 |
-
|
| 26 |
-
RED = "#
|
| 27 |
-
BEAR = "#
|
| 28 |
-
BEAR_BG = "#
|
| 29 |
-
BEAR_BORDER = "#
|
| 30 |
-
|
| 31 |
-
AMBER = "#
|
| 32 |
-
WARN = "#
|
| 33 |
-
WARN_BG = "#
|
| 34 |
-
WARN_BORDER = "#
|
| 35 |
-
|
| 36 |
-
BLUE = "#
|
| 37 |
-
INFO = "#
|
| 38 |
-
INFO_BG = "#
|
| 39 |
-
INFO_BORDER = "#
|
| 40 |
-
|
| 41 |
-
GRAY = "#
|
| 42 |
-
PURPLE = "#
|
| 43 |
-
AI_BG = "#
|
| 44 |
-
AI_BORDER = "#
|
| 45 |
-
AI_COLOR = "#
|
| 46 |
-
AI_BADGE_BG = "#
|
| 47 |
-
|
| 48 |
-
IMPACT_HIGH_BG = "#
|
| 49 |
-
IMPACT_HIGH_TEXT = "#
|
| 50 |
-
IMPACT_MED_BG = "#
|
| 51 |
-
IMPACT_MED_TEXT = "#
|
| 52 |
IMPACT_LOW_BG = "transparent"
|
| 53 |
-
IMPACT_LOW_TEXT = "#
|
| 54 |
-
IMPACT_LOW_BORDER = "#
|
| 55 |
|
| 56 |
# ── Plotly rgba aliases ───────────────────────────────────────────────────────
|
| 57 |
-
GREEN_A53 = "rgba(
|
| 58 |
-
GREEN_A40 = "rgba(
|
| 59 |
-
RED_A40 = "rgba(
|
| 60 |
-
PURPLE_A53 = "rgba(139,
|
| 61 |
-
BLUE_A53 = "rgba(96,165,250,0.
|
| 62 |
|
| 63 |
# ── Radius ────────────────────────────────────────────────────────────────────
|
| 64 |
RADIUS_CARD = "12px"
|
|
@@ -89,15 +89,52 @@ def _lazy_nav_groups(): # noqa: F401 — accessed via dashboard.nav.NAV_GROUPS
|
|
| 89 |
return NAV_GROUPS
|
| 90 |
|
| 91 |
# ── Logo SVG — geometric P in emerald rounded square ─────────────────────────
|
|
|
|
|
|
|
| 92 |
LOGO_SVG = """<svg width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg">
|
| 93 |
-
<rect width="36" height="36" rx="9" fill="#
|
| 94 |
-
<path d="M12 26V11H19.5C20.9 11 22.1 11.5 23.1 12.5C24.1 13.5 24.6 14.7 24.6 16.2C24.6 17.7 24.1 18.9 23.1 19.9C22.1 20.9 20.9 21.4 19.5 21.4H15.5V26H12Z" fill="
|
| 95 |
-
<path d="M15.5 18.2H19C19.8 18.2 20.4 17.9 20.9 17.4C21.4 16.9 21.6 16.2 21.6 15.4C21.6 14.6 21.4 14 20.9 13.5C20.4 13 19.8 12.7 19 12.7H15.5V18.2Z" fill="#
|
| 96 |
</svg>"""
|
| 97 |
|
| 98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
def inject_global_css() -> None:
|
| 100 |
"""Inject Inter font + global Amplegest styles. Call once from app.py."""
|
|
|
|
| 101 |
st.html(
|
| 102 |
"""
|
| 103 |
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
@@ -120,13 +157,13 @@ def inject_global_css() -> None:
|
|
| 120 |
|
| 121 |
/* ── Canvas background ──────────────────────────────────────────────────── */
|
| 122 |
.stApp, [data-testid="stAppViewContainer"] {
|
| 123 |
-
background: #
|
| 124 |
}
|
| 125 |
|
| 126 |
/* ── Sidebar ────────────────────────────────────────────────────────── */
|
| 127 |
[data-testid="stSidebar"] {
|
| 128 |
-
background-color: #
|
| 129 |
-
border-right: 1px solid #
|
| 130 |
}
|
| 131 |
|
| 132 |
/* ── Logo row (custom div) ──────────────────────────────────────────── */
|
|
@@ -135,19 +172,19 @@ def inject_global_css() -> None:
|
|
| 135 |
align-items: center;
|
| 136 |
gap: 10px;
|
| 137 |
padding: 20px 16px 16px;
|
| 138 |
-
border-bottom: 1px solid #
|
| 139 |
margin-bottom: 12px;
|
| 140 |
}
|
| 141 |
.primer-logo-wordmark {
|
| 142 |
font-size: 1rem;
|
| 143 |
font-weight: 700;
|
| 144 |
-
color: #
|
| 145 |
letter-spacing: -0.02em;
|
| 146 |
line-height: 1.2;
|
| 147 |
}
|
| 148 |
.primer-logo-tagline {
|
| 149 |
font-size: 0.65rem;
|
| 150 |
-
color: #
|
| 151 |
font-weight: 400;
|
| 152 |
margin-top: 1px;
|
| 153 |
}
|
|
@@ -155,20 +192,22 @@ def inject_global_css() -> None:
|
|
| 155 |
/* ── Text inputs ────────────────────────────────────────────────────── */
|
| 156 |
[data-testid="stTextInput"] input {
|
| 157 |
border-radius: 8px !important;
|
| 158 |
-
border: 1px solid #
|
| 159 |
font-size: 0.9rem !important;
|
| 160 |
-
background: #
|
| 161 |
-
color: #
|
| 162 |
}
|
| 163 |
[data-testid="stTextInput"] input:focus {
|
| 164 |
-
border-color: #
|
| 165 |
-
box-shadow: 0 0 0
|
| 166 |
}
|
| 167 |
|
| 168 |
-
/* ── Primary button —
|
|
|
|
|
|
|
| 169 |
[data-testid="stBaseButton-primary"] {
|
| 170 |
-
background: #
|
| 171 |
-
color: #
|
| 172 |
border-radius: 8px !important;
|
| 173 |
border: none !important;
|
| 174 |
font-weight: 500 !important;
|
|
@@ -176,62 +215,68 @@ def inject_global_css() -> None:
|
|
| 176 |
letter-spacing: 0.01em !important;
|
| 177 |
}
|
| 178 |
[data-testid="stBaseButton-primary"]:hover {
|
| 179 |
-
background: #
|
| 180 |
border: none !important;
|
| 181 |
}
|
| 182 |
|
| 183 |
/* ── Secondary / default buttons ────────────────────────────────────── */
|
| 184 |
[data-testid="stBaseButton-secondary"] {
|
| 185 |
border-radius: 8px !important;
|
| 186 |
-
border: 1px solid #
|
|
|
|
| 187 |
font-weight: 500 !important;
|
| 188 |
-
color: #
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
}
|
| 190 |
|
| 191 |
/* ── Download button ────────────────────────────────────────────────── */
|
| 192 |
[data-testid="stDownloadButton"] button {
|
| 193 |
border-radius: 8px !important;
|
| 194 |
-
border: 1px solid #
|
|
|
|
| 195 |
font-weight: 500 !important;
|
| 196 |
-
color: #
|
| 197 |
}
|
| 198 |
|
| 199 |
/* ── Bordered containers ────────────────────────────────────────────── */
|
| 200 |
[data-testid="stVerticalBlockBorderWrapper"] {
|
| 201 |
border-radius: 12px !important;
|
| 202 |
-
border: 1px solid #
|
| 203 |
-
box-shadow: 0 1px
|
| 204 |
-
background: #
|
| 205 |
padding: 20px 24px !important;
|
| 206 |
}
|
| 207 |
|
| 208 |
/* ── Custom card shadow class ───────────────────────────────────────── */
|
| 209 |
.primer-card {
|
| 210 |
-
box-shadow: 0 1px
|
| 211 |
}
|
| 212 |
|
| 213 |
/* ── Section cards (HTML-rendered sections) ─────────────────────────────── */
|
| 214 |
.primer-section-card {
|
| 215 |
-
background: #
|
| 216 |
-
border: 1px solid #
|
| 217 |
border-radius: 12px;
|
| 218 |
padding: 22px 26px;
|
| 219 |
margin: 0 0 18px;
|
| 220 |
-
box-shadow: 0 1px
|
| 221 |
}
|
| 222 |
|
| 223 |
/* ── Dividers ───────────────────────────────────────────────────────── */
|
| 224 |
-
hr { border-color: #
|
| 225 |
|
| 226 |
/* ── Status box ─────────────────────────────────────────────────────── */
|
| 227 |
[data-testid="stStatus"] {
|
| 228 |
border-radius: 8px !important;
|
| 229 |
-
border: 1px solid #
|
| 230 |
}
|
| 231 |
|
| 232 |
/* ── Expanders ──────────────────────────────────────────────────────── */
|
| 233 |
[data-testid="stExpander"] {
|
| 234 |
-
border: 1px solid #
|
| 235 |
border-radius: 8px !important;
|
| 236 |
box-shadow: none !important;
|
| 237 |
}
|
|
@@ -240,17 +285,17 @@ def inject_global_css() -> None:
|
|
| 240 |
[data-testid="stTabs"] [role="tab"] {
|
| 241 |
font-size: 0.82rem !important;
|
| 242 |
font-weight: 500 !important;
|
| 243 |
-
color: #
|
| 244 |
}
|
| 245 |
[data-testid="stTabs"] [role="tab"][aria-selected="true"] {
|
| 246 |
-
color: #
|
| 247 |
}
|
| 248 |
[data-testid="stTabs"] [role="tablist"] {
|
| 249 |
-
border-bottom: 1px solid #
|
| 250 |
}
|
| 251 |
|
| 252 |
/* ── Captions ───────────────────────────────────────────────────────── */
|
| 253 |
-
.stCaption { color: #
|
| 254 |
|
| 255 |
/* ── Alerts / info boxes ────────────────────────────────────────────── */
|
| 256 |
[data-testid="stAlert"] {
|
|
@@ -260,7 +305,7 @@ def inject_global_css() -> None:
|
|
| 260 |
/* ── Sidebar nav group expanders (deep-dive accordion) ──────────────── */
|
| 261 |
[data-testid="stSidebar"] [data-testid="stExpander"] {
|
| 262 |
border: none !important;
|
| 263 |
-
border-top: 1px solid #
|
| 264 |
border-radius: 0 !important;
|
| 265 |
box-shadow: none !important;
|
| 266 |
background: transparent !important;
|
|
@@ -271,16 +316,16 @@ def inject_global_css() -> None:
|
|
| 271 |
font-weight: 700 !important;
|
| 272 |
text-transform: uppercase !important;
|
| 273 |
letter-spacing: 0.1em !important;
|
| 274 |
-
color: #
|
| 275 |
padding: 6px 2px !important;
|
| 276 |
}
|
| 277 |
[data-testid="stSidebar"] [data-testid="stExpander"] summary:hover {
|
| 278 |
-
color: #
|
| 279 |
}
|
| 280 |
[data-testid="stSidebar"] [data-testid="stExpander"] summary svg {
|
| 281 |
width: 12px !important;
|
| 282 |
height: 12px !important;
|
| 283 |
-
color: #
|
| 284 |
}
|
| 285 |
|
| 286 |
/* ── Content max-width ──────────────────────────────────────────────── */
|
|
@@ -299,10 +344,10 @@ def inject_global_css() -> None:
|
|
| 299 |
position: sticky;
|
| 300 |
top: 0;
|
| 301 |
z-index: 50;
|
| 302 |
-
background: rgba(
|
| 303 |
backdrop-filter: blur(6px);
|
| 304 |
-webkit-backdrop-filter: blur(6px);
|
| 305 |
-
border-bottom: 1px solid #
|
| 306 |
padding: 10px 0;
|
| 307 |
margin: 0 0 16px;
|
| 308 |
}
|
|
@@ -310,36 +355,115 @@ def inject_global_css() -> None:
|
|
| 310 |
/* ── Chat messages ──────────────────────────────────────────────────── */
|
| 311 |
[data-testid="stChatMessage"] {
|
| 312 |
border-radius: 10px !important;
|
| 313 |
-
border: 1px solid #
|
| 314 |
-
background: #
|
| 315 |
padding: 12px 14px !important;
|
| 316 |
margin-bottom: 8px !important;
|
| 317 |
-
box-shadow: 0 1px 2px rgba(0,0,0,0.
|
| 318 |
}
|
| 319 |
[data-testid="stChatMessage"][data-message-author-role="user"] {
|
| 320 |
-
background: #
|
| 321 |
-
border-color: #
|
| 322 |
}
|
| 323 |
[data-testid="stChatMessage"][data-message-author-role="assistant"] {
|
| 324 |
-
background: #
|
| 325 |
-
border-color: #
|
| 326 |
}
|
| 327 |
|
| 328 |
/* ── Chat input ─────────────────────────────────────────────────────── */
|
| 329 |
[data-testid="stChatInput"] {
|
| 330 |
border-radius: 10px !important;
|
| 331 |
-
border: 1px solid #
|
| 332 |
-
box-shadow: 0 1px 3px rgba(0,0,0,0.
|
| 333 |
}
|
| 334 |
[data-testid="stChatInput"]:focus-within {
|
| 335 |
-
border-color: #
|
| 336 |
-
box-shadow: 0 0 0
|
| 337 |
}
|
| 338 |
[data-testid="stChatInput"] textarea {
|
| 339 |
font-family: Inter, ui-sans-serif, -apple-system, "Segoe UI", sans-serif !important;
|
| 340 |
font-size: 0.9rem !important;
|
| 341 |
-
color: #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
</style>
|
| 344 |
""",
|
| 345 |
)
|
|
|
|
| 3 |
import streamlit as st
|
| 4 |
|
| 5 |
# ── Brand ─────────────────────────────────────────────────────────────────────
|
| 6 |
+
BRAND_GREEN = "#34d399"
|
| 7 |
+
BRAND_GREEN_DARK = "#10b981"
|
| 8 |
|
| 9 |
# ── Surfaces ──────────────────────────────────────────────────────────────────
|
| 10 |
+
BG = "#151a21"
|
| 11 |
+
BG_MUTED = "#0e1217"
|
| 12 |
+
BORDER = "#2b323c"
|
| 13 |
+
BORDER_STRONG = "#3a424e"
|
| 14 |
|
| 15 |
# ── Text ──────────────────────────────────────────────────────────────────────
|
| 16 |
+
TEXT = "#e8eef5"
|
| 17 |
+
TEXT_MUTED = "#8a95a3"
|
| 18 |
+
TEXT_FAINT = "#707b8a"
|
| 19 |
+
|
| 20 |
+
# ── Semantic palette (dark tints + lifted accents) ────────────────────────────
|
| 21 |
+
GREEN = "#34d399"
|
| 22 |
+
BULL = "#34d399"
|
| 23 |
+
BULL_BG = "#10251d"
|
| 24 |
+
BULL_BORDER = "#1f5b45"
|
| 25 |
+
|
| 26 |
+
RED = "#f87171"
|
| 27 |
+
BEAR = "#f87171"
|
| 28 |
+
BEAR_BG = "#2a1416"
|
| 29 |
+
BEAR_BORDER = "#6b2b2f"
|
| 30 |
+
|
| 31 |
+
AMBER = "#fbbf24"
|
| 32 |
+
WARN = "#fbbf24"
|
| 33 |
+
WARN_BG = "#2a2113"
|
| 34 |
+
WARN_BORDER = "#6b5320"
|
| 35 |
+
|
| 36 |
+
BLUE = "#60a5fa"
|
| 37 |
+
INFO = "#60a5fa"
|
| 38 |
+
INFO_BG = "#111f33"
|
| 39 |
+
INFO_BORDER = "#1e3a5f"
|
| 40 |
+
|
| 41 |
+
GRAY = "#8a95a3"
|
| 42 |
+
PURPLE = "#a78bfa"
|
| 43 |
+
AI_BG = "#1e1633"
|
| 44 |
+
AI_BORDER = "#432d7a"
|
| 45 |
+
AI_COLOR = "#a78bfa"
|
| 46 |
+
AI_BADGE_BG = "#2a1f52"
|
| 47 |
+
|
| 48 |
+
IMPACT_HIGH_BG = "#e8eef5" # near-white chip — highest contrast on dark
|
| 49 |
+
IMPACT_HIGH_TEXT = "#151a21"
|
| 50 |
+
IMPACT_MED_BG = "#7b8593" # slate-400
|
| 51 |
+
IMPACT_MED_TEXT = "#151a21"
|
| 52 |
IMPACT_LOW_BG = "transparent"
|
| 53 |
+
IMPACT_LOW_TEXT = "#7b8593" # slate-400
|
| 54 |
+
IMPACT_LOW_BORDER = "#49525f" # slate-600
|
| 55 |
|
| 56 |
# ── Plotly rgba aliases ───────────────────────────────────────────────────────
|
| 57 |
+
GREEN_A53 = "rgba(52,211,153,0.55)"
|
| 58 |
+
GREEN_A40 = "rgba(52,211,153,0.42)"
|
| 59 |
+
RED_A40 = "rgba(248,113,113,0.42)"
|
| 60 |
+
PURPLE_A53 = "rgba(167,139,250,0.55)"
|
| 61 |
+
BLUE_A53 = "rgba(96,165,250,0.55)"
|
| 62 |
|
| 63 |
# ── Radius ────────────────────────────────────────────────────────────────────
|
| 64 |
RADIUS_CARD = "12px"
|
|
|
|
| 89 |
return NAV_GROUPS
|
| 90 |
|
| 91 |
# ── Logo SVG — geometric P in emerald rounded square ─────────────────────────
|
| 92 |
+
# The counter of the P is punched out in the canvas colour so the mark reads
|
| 93 |
+
# correctly on the dark sidebar (it used to be punched out in white).
|
| 94 |
LOGO_SVG = """<svg width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg">
|
| 95 |
+
<rect width="36" height="36" rx="9" fill="#34d399"/>
|
| 96 |
+
<path d="M12 26V11H19.5C20.9 11 22.1 11.5 23.1 12.5C24.1 13.5 24.6 14.7 24.6 16.2C24.6 17.7 24.1 18.9 23.1 19.9C22.1 20.9 20.9 21.4 19.5 21.4H15.5V26H12Z" fill="#08111a"/>
|
| 97 |
+
<path d="M15.5 18.2H19C19.8 18.2 20.4 17.9 20.9 17.4C21.4 16.9 21.6 16.2 21.6 15.4C21.6 14.6 21.4 14 20.9 13.5C20.4 13 19.8 12.7 19 12.7H15.5V18.2Z" fill="#34d399"/>
|
| 98 |
</svg>"""
|
| 99 |
|
| 100 |
|
| 101 |
+
def _register_plotly_dark_template() -> None:
|
| 102 |
+
"""Make dark the plotly default so charts inherit it without per-figure work.
|
| 103 |
+
|
| 104 |
+
Individual figures still override plot/paper background and font colour;
|
| 105 |
+
what this template actually buys is the styling nothing sets by hand —
|
| 106 |
+
hover labels and the modebar, which otherwise render light-on-light.
|
| 107 |
+
"""
|
| 108 |
+
try:
|
| 109 |
+
import plotly.graph_objects as go
|
| 110 |
+
import plotly.io as pio
|
| 111 |
+
except Exception: # plotly missing — charts are optional, styling is not fatal
|
| 112 |
+
return
|
| 113 |
+
|
| 114 |
+
if "amplegest_dark" not in pio.templates:
|
| 115 |
+
pio.templates["amplegest_dark"] = go.layout.Template(
|
| 116 |
+
layout=dict(
|
| 117 |
+
paper_bgcolor=BG,
|
| 118 |
+
plot_bgcolor=BG,
|
| 119 |
+
font=dict(family="Inter", color=TEXT_MUTED, size=11),
|
| 120 |
+
hoverlabel=dict(
|
| 121 |
+
bgcolor="#1a2029",
|
| 122 |
+
bordercolor=BORDER_STRONG,
|
| 123 |
+
font=dict(family="Inter", color=TEXT, size=12),
|
| 124 |
+
),
|
| 125 |
+
xaxis=dict(gridcolor="#232a34", zerolinecolor="#2b323c",
|
| 126 |
+
linecolor=BORDER, tickfont=dict(color=TEXT_MUTED)),
|
| 127 |
+
yaxis=dict(gridcolor="#232a34", zerolinecolor="#2b323c",
|
| 128 |
+
linecolor=BORDER, tickfont=dict(color=TEXT_MUTED)),
|
| 129 |
+
colorway=[BRAND_GREEN, BLUE, PURPLE, AMBER, RED, "#7b8593"],
|
| 130 |
+
)
|
| 131 |
+
)
|
| 132 |
+
pio.templates.default = "amplegest_dark"
|
| 133 |
+
|
| 134 |
+
|
| 135 |
def inject_global_css() -> None:
|
| 136 |
"""Inject Inter font + global Amplegest styles. Call once from app.py."""
|
| 137 |
+
_register_plotly_dark_template()
|
| 138 |
st.html(
|
| 139 |
"""
|
| 140 |
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
|
|
| 157 |
|
| 158 |
/* ── Canvas background ──────────────────────────────────────────────────── */
|
| 159 |
.stApp, [data-testid="stAppViewContainer"] {
|
| 160 |
+
background: #0e1217 !important;
|
| 161 |
}
|
| 162 |
|
| 163 |
/* ── Sidebar ────────────────────────────────────────────────────────── */
|
| 164 |
[data-testid="stSidebar"] {
|
| 165 |
+
background-color: #151a21 !important;
|
| 166 |
+
border-right: 1px solid #2b323c !important;
|
| 167 |
}
|
| 168 |
|
| 169 |
/* ── Logo row (custom div) ──────────────────────────────────────────── */
|
|
|
|
| 172 |
align-items: center;
|
| 173 |
gap: 10px;
|
| 174 |
padding: 20px 16px 16px;
|
| 175 |
+
border-bottom: 1px solid #2b323c;
|
| 176 |
margin-bottom: 12px;
|
| 177 |
}
|
| 178 |
.primer-logo-wordmark {
|
| 179 |
font-size: 1rem;
|
| 180 |
font-weight: 700;
|
| 181 |
+
color: #e8eef5;
|
| 182 |
letter-spacing: -0.02em;
|
| 183 |
line-height: 1.2;
|
| 184 |
}
|
| 185 |
.primer-logo-tagline {
|
| 186 |
font-size: 0.65rem;
|
| 187 |
+
color: #707b8a;
|
| 188 |
font-weight: 400;
|
| 189 |
margin-top: 1px;
|
| 190 |
}
|
|
|
|
| 192 |
/* ── Text inputs ────────────────────────────────────────────────────── */
|
| 193 |
[data-testid="stTextInput"] input {
|
| 194 |
border-radius: 8px !important;
|
| 195 |
+
border: 1px solid #2b323c !important;
|
| 196 |
font-size: 0.9rem !important;
|
| 197 |
+
background: #151a21 !important;
|
| 198 |
+
color: #e8eef5 !important;
|
| 199 |
}
|
| 200 |
[data-testid="stTextInput"] input:focus {
|
| 201 |
+
border-color: #34d399 !important;
|
| 202 |
+
box-shadow: 0 0 0 3px rgba(52,211,153,0.22) !important;
|
| 203 |
}
|
| 204 |
|
| 205 |
+
/* ── Primary button — inverted (near-white), not green.
|
| 206 |
+
Emerald stays reserved for active-nav and positive semantics, so the
|
| 207 |
+
CTA must not compete with it. ────────────────────────────────────── */
|
| 208 |
[data-testid="stBaseButton-primary"] {
|
| 209 |
+
background: #e8eef5 !important;
|
| 210 |
+
color: #151a21 !important;
|
| 211 |
border-radius: 8px !important;
|
| 212 |
border: none !important;
|
| 213 |
font-weight: 500 !important;
|
|
|
|
| 215 |
letter-spacing: 0.01em !important;
|
| 216 |
}
|
| 217 |
[data-testid="stBaseButton-primary"]:hover {
|
| 218 |
+
background: #f2f6fb !important;
|
| 219 |
border: none !important;
|
| 220 |
}
|
| 221 |
|
| 222 |
/* ── Secondary / default buttons ────────────────────────────────────── */
|
| 223 |
[data-testid="stBaseButton-secondary"] {
|
| 224 |
border-radius: 8px !important;
|
| 225 |
+
border: 1px solid #2b323c !important;
|
| 226 |
+
background: #1a2029 !important;
|
| 227 |
font-weight: 500 !important;
|
| 228 |
+
color: #e8eef5 !important;
|
| 229 |
+
}
|
| 230 |
+
[data-testid="stBaseButton-secondary"]:hover {
|
| 231 |
+
background: #232a34 !important;
|
| 232 |
+
border-color: #3a424e !important;
|
| 233 |
}
|
| 234 |
|
| 235 |
/* ── Download button ────────────────────────────────────────────────── */
|
| 236 |
[data-testid="stDownloadButton"] button {
|
| 237 |
border-radius: 8px !important;
|
| 238 |
+
border: 1px solid #2b323c !important;
|
| 239 |
+
background: #1a2029 !important;
|
| 240 |
font-weight: 500 !important;
|
| 241 |
+
color: #e8eef5 !important;
|
| 242 |
}
|
| 243 |
|
| 244 |
/* ── Bordered containers ────────────────────────────────────────────── */
|
| 245 |
[data-testid="stVerticalBlockBorderWrapper"] {
|
| 246 |
border-radius: 12px !important;
|
| 247 |
+
border: 1px solid #2b323c !important;
|
| 248 |
+
box-shadow: 0 1px 2px rgba(0,0,0,0.45), 0 4px 12px rgba(0,0,0,0.30) !important;
|
| 249 |
+
background: #151a21 !important;
|
| 250 |
padding: 20px 24px !important;
|
| 251 |
}
|
| 252 |
|
| 253 |
/* ── Custom card shadow class ───────────────────────────────────────── */
|
| 254 |
.primer-card {
|
| 255 |
+
box-shadow: 0 1px 2px rgba(0,0,0,0.45), 0 4px 12px rgba(0,0,0,0.30);
|
| 256 |
}
|
| 257 |
|
| 258 |
/* ── Section cards (HTML-rendered sections) ─────────────────────────────── */
|
| 259 |
.primer-section-card {
|
| 260 |
+
background: #151a21;
|
| 261 |
+
border: 1px solid #2b323c;
|
| 262 |
border-radius: 12px;
|
| 263 |
padding: 22px 26px;
|
| 264 |
margin: 0 0 18px;
|
| 265 |
+
box-shadow: 0 1px 2px rgba(0,0,0,0.45), 0 4px 12px rgba(0,0,0,0.30);
|
| 266 |
}
|
| 267 |
|
| 268 |
/* ── Dividers ───────────────────────────────────────────────────────── */
|
| 269 |
+
hr { border-color: #2b323c !important; }
|
| 270 |
|
| 271 |
/* ── Status box ─────────────────────────────────────────────────────── */
|
| 272 |
[data-testid="stStatus"] {
|
| 273 |
border-radius: 8px !important;
|
| 274 |
+
border: 1px solid #2b323c !important;
|
| 275 |
}
|
| 276 |
|
| 277 |
/* ── Expanders ──────────────────────────────────────────────────────── */
|
| 278 |
[data-testid="stExpander"] {
|
| 279 |
+
border: 1px solid #2b323c !important;
|
| 280 |
border-radius: 8px !important;
|
| 281 |
box-shadow: none !important;
|
| 282 |
}
|
|
|
|
| 285 |
[data-testid="stTabs"] [role="tab"] {
|
| 286 |
font-size: 0.82rem !important;
|
| 287 |
font-weight: 500 !important;
|
| 288 |
+
color: #8a95a3 !important;
|
| 289 |
}
|
| 290 |
[data-testid="stTabs"] [role="tab"][aria-selected="true"] {
|
| 291 |
+
color: #e8eef5 !important;
|
| 292 |
}
|
| 293 |
[data-testid="stTabs"] [role="tablist"] {
|
| 294 |
+
border-bottom: 1px solid #2b323c !important;
|
| 295 |
}
|
| 296 |
|
| 297 |
/* ── Captions ───────────────────────────────────────────────────────── */
|
| 298 |
+
.stCaption { color: #707b8a !important; font-size: 0.78rem !important; }
|
| 299 |
|
| 300 |
/* ── Alerts / info boxes ────────────────────────────────────────────── */
|
| 301 |
[data-testid="stAlert"] {
|
|
|
|
| 305 |
/* ── Sidebar nav group expanders (deep-dive accordion) ──────────────── */
|
| 306 |
[data-testid="stSidebar"] [data-testid="stExpander"] {
|
| 307 |
border: none !important;
|
| 308 |
+
border-top: 1px solid #1e242d !important;
|
| 309 |
border-radius: 0 !important;
|
| 310 |
box-shadow: none !important;
|
| 311 |
background: transparent !important;
|
|
|
|
| 316 |
font-weight: 700 !important;
|
| 317 |
text-transform: uppercase !important;
|
| 318 |
letter-spacing: 0.1em !important;
|
| 319 |
+
color: #707b8a !important;
|
| 320 |
padding: 6px 2px !important;
|
| 321 |
}
|
| 322 |
[data-testid="stSidebar"] [data-testid="stExpander"] summary:hover {
|
| 323 |
+
color: #8a95a3 !important;
|
| 324 |
}
|
| 325 |
[data-testid="stSidebar"] [data-testid="stExpander"] summary svg {
|
| 326 |
width: 12px !important;
|
| 327 |
height: 12px !important;
|
| 328 |
+
color: #707b8a !important;
|
| 329 |
}
|
| 330 |
|
| 331 |
/* ── Content max-width ──────────────────────────────────────────────── */
|
|
|
|
| 344 |
position: sticky;
|
| 345 |
top: 0;
|
| 346 |
z-index: 50;
|
| 347 |
+
background: rgba(14, 18, 23, 0.88);
|
| 348 |
backdrop-filter: blur(6px);
|
| 349 |
-webkit-backdrop-filter: blur(6px);
|
| 350 |
+
border-bottom: 1px solid #2b323c;
|
| 351 |
padding: 10px 0;
|
| 352 |
margin: 0 0 16px;
|
| 353 |
}
|
|
|
|
| 355 |
/* ── Chat messages ──────────────────────────────────────────────────── */
|
| 356 |
[data-testid="stChatMessage"] {
|
| 357 |
border-radius: 10px !important;
|
| 358 |
+
border: 1px solid #2b323c !important;
|
| 359 |
+
background: #151a21 !important;
|
| 360 |
padding: 12px 14px !important;
|
| 361 |
margin-bottom: 8px !important;
|
| 362 |
+
box-shadow: 0 1px 2px rgba(0,0,0,0.40) !important;
|
| 363 |
}
|
| 364 |
[data-testid="stChatMessage"][data-message-author-role="user"] {
|
| 365 |
+
background: #151a21 !important;
|
| 366 |
+
border-color: #2b323c !important;
|
| 367 |
}
|
| 368 |
[data-testid="stChatMessage"][data-message-author-role="assistant"] {
|
| 369 |
+
background: #1e1633 !important;
|
| 370 |
+
border-color: #432d7a !important;
|
| 371 |
}
|
| 372 |
|
| 373 |
/* ── Chat input ─────────────────────────────────────────────────────── */
|
| 374 |
[data-testid="stChatInput"] {
|
| 375 |
border-radius: 10px !important;
|
| 376 |
+
border: 1px solid #2b323c !important;
|
| 377 |
+
box-shadow: 0 1px 3px rgba(0,0,0,0.45) !important;
|
| 378 |
}
|
| 379 |
[data-testid="stChatInput"]:focus-within {
|
| 380 |
+
border-color: #34d399 !important;
|
| 381 |
+
box-shadow: 0 0 0 3px rgba(52,211,153,0.22) !important;
|
| 382 |
}
|
| 383 |
[data-testid="stChatInput"] textarea {
|
| 384 |
font-family: Inter, ui-sans-serif, -apple-system, "Segoe UI", sans-serif !important;
|
| 385 |
font-size: 0.9rem !important;
|
| 386 |
+
color: #e8eef5 !important;
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
/* ══ Dark-mode chrome ═══════════════════════════════════════════════════
|
| 390 |
+
Streamlit paints a handful of widgets from its own theme rather than
|
| 391 |
+
from our tokens. Those are pinned here so a stray light surface can
|
| 392 |
+
never punch a white hole in the dark canvas. */
|
| 393 |
+
|
| 394 |
+
/* Select / multiselect / number inputs */
|
| 395 |
+
[data-baseweb="select"] > div,
|
| 396 |
+
[data-testid="stSelectbox"] div[role="combobox"],
|
| 397 |
+
[data-testid="stNumberInput"] input {
|
| 398 |
+
background-color: #1a2029 !important;
|
| 399 |
+
border-color: #2b323c !important;
|
| 400 |
+
color: #e8eef5 !important;
|
| 401 |
+
}
|
| 402 |
+
[data-baseweb="popover"] [role="listbox"],
|
| 403 |
+
[data-baseweb="menu"] {
|
| 404 |
+
background-color: #1a2029 !important;
|
| 405 |
+
border: 1px solid #2b323c !important;
|
| 406 |
+
}
|
| 407 |
+
[data-baseweb="menu"] li:hover { background-color: #232a34 !important; }
|
| 408 |
+
|
| 409 |
+
/* Text input placeholders */
|
| 410 |
+
[data-testid="stTextInput"] input::placeholder,
|
| 411 |
+
[data-testid="stChatInput"] textarea::placeholder {
|
| 412 |
+
color: #5c6675 !important;
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
/* Inline code + code blocks */
|
| 416 |
+
code, [data-testid="stCode"], pre {
|
| 417 |
+
background-color: #1a2029 !important;
|
| 418 |
+
color: #c4b5fd !important;
|
| 419 |
}
|
| 420 |
+
|
| 421 |
+
/* Links — emerald, never the browser default blue */
|
| 422 |
+
a, a:visited { color: #34d399 !important; }
|
| 423 |
+
a:hover { color: #6ee7b7 !important; }
|
| 424 |
+
|
| 425 |
+
/* Tables / dataframes */
|
| 426 |
+
[data-testid="stDataFrame"], [data-testid="stTable"] {
|
| 427 |
+
background-color: #151a21 !important;
|
| 428 |
+
}
|
| 429 |
+
[data-testid="stDataFrame"] * { border-color: #2b323c !important; }
|
| 430 |
+
|
| 431 |
+
/* Alerts — Streamlit ships pastel tints; restate them as dark tints */
|
| 432 |
+
[data-testid="stAlert"] { border: 1px solid #2b323c !important; }
|
| 433 |
+
[data-testid="stAlertContentInfo"] { background-color: #111f33 !important; color: #93c5fd !important; }
|
| 434 |
+
[data-testid="stAlertContentSuccess"] { background-color: #10251d !important; color: #6ee7b7 !important; }
|
| 435 |
+
[data-testid="stAlertContentWarning"] { background-color: #2a2113 !important; color: #fcd34d !important; }
|
| 436 |
+
[data-testid="stAlertContentError"] { background-color: #2a1416 !important; color: #fca5a5 !important; }
|
| 437 |
+
|
| 438 |
+
/* Active tab underline — Streamlit draws it in primaryColor */
|
| 439 |
+
[data-testid="stTabs"] [role="tab"][aria-selected="true"]::after,
|
| 440 |
+
[data-testid="stTabs"] [data-baseweb="tab-highlight"] {
|
| 441 |
+
background-color: #34d399 !important;
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
/* Spinner + progress use primaryColor too */
|
| 445 |
+
[data-testid="stSpinner"] i { border-top-color: #34d399 !important; }
|
| 446 |
+
|
| 447 |
+
/* Scrollbars — a light scrollbar on a dark page is the loudest tell */
|
| 448 |
+
* { scrollbar-color: #3a424e #0e1217; scrollbar-width: thin; }
|
| 449 |
+
::-webkit-scrollbar { width: 10px; height: 10px; }
|
| 450 |
+
::-webkit-scrollbar-track { background: #0e1217; }
|
| 451 |
+
::-webkit-scrollbar-thumb {
|
| 452 |
+
background: #3a424e; border-radius: 6px; border: 2px solid #0e1217;
|
| 453 |
+
}
|
| 454 |
+
::-webkit-scrollbar-thumb:hover { background: #49525f; }
|
| 455 |
+
|
| 456 |
+
/* ── Inline "show the rest" disclosures (redline passages) ────────── */
|
| 457 |
+
details > summary { list-style: none; }
|
| 458 |
+
details > summary::-webkit-details-marker { display: none; }
|
| 459 |
+
details > summary::marker { content: ""; }
|
| 460 |
+
details[open] > summary .primer-more { display: none; }
|
| 461 |
+
details > summary:hover .primer-more { color: #34d399 !important; }
|
| 462 |
+
|
| 463 |
+
/* Tell the UA the page is dark so form controls, selection and
|
| 464 |
+
autofill render with dark-native styling. */
|
| 465 |
+
:root { color-scheme: dark; }
|
| 466 |
+
::selection { background: rgba(52,211,153,0.30); color: #e8eef5; }
|
| 467 |
</style>
|
| 468 |
""",
|
| 469 |
)
|
|
@@ -1,22 +1,22 @@
|
|
| 1 |
-
"""
|
| 2 |
|
| 3 |
The screen is deliberately fail-closed: unaligned market expectations, event
|
| 4 |
returns, aggregate sentiment and aggregate reliability do not appear here.
|
| 5 |
Interpretive output is labelled as an experimental AI hypothesis and points the
|
| 6 |
-
reader to
|
| 7 |
"""
|
| 8 |
from __future__ import annotations
|
| 9 |
|
| 10 |
import streamlit as st
|
| 11 |
|
| 12 |
from dashboard.theme import (
|
| 13 |
-
GREEN, RED, AMBER, AI_COLOR, GRAY,
|
| 14 |
BORDER, TEXT, TEXT_MUTED, TEXT_FAINT,
|
| 15 |
FS_PAGE, FS_BODY, FS_META, FS_EYEBROW,
|
| 16 |
)
|
| 17 |
from dashboard.components import (
|
| 18 |
ai_badge, eyebrow_label, section_header, sort_by_impact,
|
| 19 |
-
importance_marker, _pill,
|
| 20 |
)
|
| 21 |
from dashboard.signal_feed import top_tell
|
| 22 |
from dashboard.chat import _watch_to_question
|
|
@@ -49,13 +49,13 @@ def _render_ask_cta(brief: dict) -> None:
|
|
| 49 |
st.markdown(
|
| 50 |
f"""<style>
|
| 51 |
.st-key-verdict_ask_cta [data-testid="stBaseButton-secondary"] {{
|
| 52 |
-
background: #
|
| 53 |
-
border: 1px solid #
|
| 54 |
color: {AI_COLOR} !important;
|
| 55 |
font-weight: 600 !important;
|
| 56 |
}}
|
| 57 |
.st-key-verdict_ask_cta [data-testid="stBaseButton-secondary"]:hover {{
|
| 58 |
-
background: #
|
| 59 |
}}
|
| 60 |
</style>""",
|
| 61 |
unsafe_allow_html=True,
|
|
@@ -204,7 +204,7 @@ def _render_status_strip(brief: dict) -> None:
|
|
| 204 |
)
|
| 205 |
st.markdown(
|
| 206 |
f'<div style="display:flex;align-items:center;gap:10px;flex-wrap:wrap;'
|
| 207 |
-
f'background:#
|
| 208 |
f'padding:9px 12px;margin:0 0 18px;">'
|
| 209 |
f'<span style="font-size:{FS_META};color:{TEXT_MUTED};">'
|
| 210 |
f'{t("data_through_label").format(date=filing_date)}</span>'
|
|
@@ -220,14 +220,84 @@ def _render_status_strip(brief: dict) -> None:
|
|
| 220 |
)
|
| 221 |
|
| 222 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
def _render_partial_notice(brief: dict) -> None:
|
| 224 |
evidence_coverage = brief.get("evidence_coverage") or {}
|
| 225 |
if brief.get("status") == "PARTIAL" and evidence_coverage.get("verified", 0) == 0:
|
| 226 |
st.warning(t("partial_brief_notice_zero"))
|
| 227 |
|
| 228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
def _render_thesis(brief: dict) -> None:
|
| 230 |
-
"""Render the concise
|
| 231 |
what_matters = brief.get("what_matters_most", "")
|
| 232 |
if not what_matters:
|
| 233 |
return
|
|
@@ -235,7 +305,7 @@ def _render_thesis(brief: dict) -> None:
|
|
| 235 |
f'<div class="primer-section-card" style="max-width:760px;margin:18px 0 24px;">'
|
| 236 |
f'<div style="display:flex;align-items:center;gap:8px;margin-bottom:10px;">'
|
| 237 |
f'<span style="font-size:{FS_EYEBROW};font-weight:700;letter-spacing:0.1em;'
|
| 238 |
-
f'text-transform:uppercase;color:{TEXT_MUTED};">
|
| 239 |
f'{ai_badge("AI · experimental")}</div>'
|
| 240 |
f'<div style="font-size:1.15rem;line-height:1.65;color:{TEXT};font-weight:500;">'
|
| 241 |
f'{what_matters}</div></div>',
|
|
@@ -243,6 +313,216 @@ def _render_thesis(brief: dict) -> None:
|
|
| 243 |
)
|
| 244 |
|
| 245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
def _asym_line(item: dict, marker: str, color: str) -> str:
|
| 247 |
meta_bits = [bit for bit in (
|
| 248 |
importance_marker((item.get("impact") or "").upper()),
|
|
@@ -263,34 +543,54 @@ def _asym_line(item: dict, marker: str, color: str) -> str:
|
|
| 263 |
)
|
| 264 |
|
| 265 |
|
| 266 |
-
def
|
| 267 |
confirming = sort_by_impact([
|
| 268 |
item for item in (brief.get("bull_points") or []) if isinstance(item, dict)
|
| 269 |
])[:2]
|
| 270 |
challenging = sort_by_impact([
|
| 271 |
item for item in (brief.get("bear_points") or []) if isinstance(item, dict)
|
| 272 |
])[:2]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
if not confirming and not challenging:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
return
|
| 275 |
|
| 276 |
-
st.markdown(section_header("Thesis test", accent="#475569"), unsafe_allow_html=True)
|
| 277 |
with st.container(border=True):
|
| 278 |
confirm_col, challenge_col = st.columns(2)
|
| 279 |
with confirm_col:
|
| 280 |
st.markdown(
|
| 281 |
f'<div style="margin-bottom:4px;">'
|
| 282 |
-
f'{eyebrow_label("
|
| 283 |
+ "".join(_asym_line(item, "▲", GREEN) for item in confirming),
|
| 284 |
unsafe_allow_html=True,
|
| 285 |
)
|
| 286 |
with challenge_col:
|
| 287 |
st.markdown(
|
| 288 |
f'<div style="margin-bottom:4px;">'
|
| 289 |
-
f'{eyebrow_label("
|
| 290 |
+ "".join(_asym_line(item, "▼", RED) for item in challenging),
|
| 291 |
unsafe_allow_html=True,
|
| 292 |
)
|
| 293 |
-
if st.button("
|
| 294 |
_go_to_signals()
|
| 295 |
|
| 296 |
|
|
@@ -300,22 +600,29 @@ def _evidence_source(evidence: object) -> str:
|
|
| 300 |
return ""
|
| 301 |
|
| 302 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
def _render_swing_factor(brief: dict) -> None:
|
| 304 |
factor = _select_swing_factor(brief)
|
| 305 |
if factor is None:
|
| 306 |
return
|
| 307 |
|
| 308 |
-
st.markdown(
|
|
|
|
|
|
|
|
|
|
| 309 |
st.markdown(
|
| 310 |
f'<div style="display:flex;align-items:center;gap:8px;margin-bottom:8px;">'
|
| 311 |
f'{ai_badge("AI · experimental")}'
|
| 312 |
f'<span style="font-size:{FS_META};color:{TEXT_MUTED};">'
|
| 313 |
-
f'
|
| 314 |
unsafe_allow_html=True,
|
| 315 |
)
|
| 316 |
|
| 317 |
with st.container(border=True):
|
| 318 |
-
headline = factor.get("headline") or "
|
| 319 |
st.markdown(
|
| 320 |
f'<div style="font-size:{FS_BODY};font-weight:650;color:{TEXT};'
|
| 321 |
f'line-height:1.5;margin-bottom:10px;">{headline}</div>',
|
|
@@ -326,7 +633,7 @@ def _render_swing_factor(brief: dict) -> None:
|
|
| 326 |
with bull_col:
|
| 327 |
source = _evidence_source(factor.get("bullish_evidence"))
|
| 328 |
st.markdown(
|
| 329 |
-
eyebrow_label("
|
| 330 |
+ f'<div style="font-size:{FS_BODY};line-height:1.55;color:{TEXT};margin-top:6px;">'
|
| 331 |
f'{factor.get("bullish_reading", "")}</div>'
|
| 332 |
+ (f'<div style="font-size:{FS_META};color:{TEXT_MUTED};margin-top:6px;">{source}</div>' if source else ""),
|
|
@@ -335,7 +642,7 @@ def _render_swing_factor(brief: dict) -> None:
|
|
| 335 |
with bear_col:
|
| 336 |
source = _evidence_source(factor.get("bearish_evidence"))
|
| 337 |
st.markdown(
|
| 338 |
-
eyebrow_label("
|
| 339 |
+ f'<div style="font-size:{FS_BODY};line-height:1.55;color:{TEXT};margin-top:6px;">'
|
| 340 |
f'{factor.get("bearish_reading", "")}</div>'
|
| 341 |
+ (f'<div style="font-size:{FS_META};color:{TEXT_MUTED};margin-top:6px;">{source}</div>' if source else ""),
|
|
@@ -347,46 +654,68 @@ def _render_swing_factor(brief: dict) -> None:
|
|
| 347 |
st.markdown(
|
| 348 |
f'<div style="font-size:{FS_BODY};line-height:1.55;color:{TEXT};">{reading}</div>'
|
| 349 |
+ (f'<div style="font-size:{FS_META};line-height:1.5;color:{AI_COLOR};margin-top:8px;">'
|
| 350 |
-
f'
|
| 351 |
unsafe_allow_html=True,
|
| 352 |
)
|
| 353 |
-
if st.button("
|
| 354 |
_go_to_signals()
|
| 355 |
|
| 356 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
def _render_watch(brief: dict) -> None:
|
| 358 |
items = _normalize_watch_items(brief.get("what_to_watch") or [])
|
| 359 |
if not items:
|
| 360 |
return
|
| 361 |
-
st.markdown(
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
chips = [
|
| 365 |
-
_pill(value, GRAY, "#f8fafc")
|
| 366 |
-
for value in (item["metric"], item["threshold"], item["period"], item["status"])
|
| 367 |
-
if value
|
| 368 |
-
]
|
| 369 |
-
source = (
|
| 370 |
-
f'<span style="font-size:{FS_META};color:{TEXT_MUTED};">{item["source"]}</span>'
|
| 371 |
-
if item["source"] else ""
|
| 372 |
-
)
|
| 373 |
-
primary = item["text"] or item["metric"] or "Watch item"
|
| 374 |
-
rows.append(
|
| 375 |
-
f'<div style="display:flex;gap:10px;padding:10px 0;border-bottom:1px solid {BORDER};">'
|
| 376 |
-
f'<span style="font-size:{FS_META};font-weight:700;color:{AMBER};">{index:02d}</span>'
|
| 377 |
-
f'<div><div style="font-size:{FS_BODY};line-height:1.5;color:{TEXT};">{primary}</div>'
|
| 378 |
-
f'<div style="display:flex;gap:6px;align-items:center;flex-wrap:wrap;margin-top:6px;">'
|
| 379 |
-
f'{"".join(chips)}{source}</div></div></div>'
|
| 380 |
-
)
|
| 381 |
-
more = (
|
| 382 |
-
f'<div style="font-size:{FS_META};color:{TEXT_FAINT};margin-top:7px;">'
|
| 383 |
-
f'+ {len(items) - 3} additional watch items</div>'
|
| 384 |
-
if len(items) > 3 else ""
|
| 385 |
)
|
|
|
|
|
|
|
|
|
|
| 386 |
st.markdown(
|
| 387 |
-
|
| 388 |
unsafe_allow_html=True,
|
| 389 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 390 |
|
| 391 |
|
| 392 |
def _render_brief_diff(brief: dict, ticker: str) -> None:
|
|
@@ -529,27 +858,44 @@ def render(brief: dict) -> None:
|
|
| 529 |
st.markdown(
|
| 530 |
f'<div style="margin-bottom:12px;padding-bottom:12px;border-bottom:1px solid {BORDER};">'
|
| 531 |
f'<div style="font-size:{FS_PAGE};font-weight:700;color:{TEXT};letter-spacing:-0.02em;">'
|
| 532 |
-
f'
|
| 533 |
f'<div style="font-size:{FS_META};color:{TEXT_FAINT};margin-top:4px;">{subtitle}</div>'
|
| 534 |
f'</div>',
|
| 535 |
unsafe_allow_html=True,
|
| 536 |
)
|
| 537 |
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 541 |
_render_partial_notice(brief)
|
| 542 |
-
|
| 543 |
_render_thesis(brief)
|
|
|
|
|
|
|
| 544 |
_render_ask_cta(brief)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 545 |
|
| 546 |
-
#
|
| 547 |
-
#
|
| 548 |
-
#
|
| 549 |
-
|
| 550 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 551 |
_render_asymmetry(brief)
|
| 552 |
-
with right:
|
| 553 |
_render_swing_factor(brief)
|
| 554 |
|
| 555 |
_render_watch(brief)
|
|
@@ -560,3 +906,10 @@ def render(brief: dict) -> None:
|
|
| 560 |
_render_valuation_strip(ticker)
|
| 561 |
with cat_col:
|
| 562 |
_render_catalysts(ticker)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The Brief — a one-screen, post-earnings research memo.
|
| 2 |
|
| 3 |
The screen is deliberately fail-closed: unaligned market expectations, event
|
| 4 |
returns, aggregate sentiment and aggregate reliability do not appear here.
|
| 5 |
Interpretive output is labelled as an experimental AI hypothesis and points the
|
| 6 |
+
reader to the What Changed screen for source validation.
|
| 7 |
"""
|
| 8 |
from __future__ import annotations
|
| 9 |
|
| 10 |
import streamlit as st
|
| 11 |
|
| 12 |
from dashboard.theme import (
|
| 13 |
+
GREEN, RED, AMBER, BLUE, AI_COLOR, GRAY,
|
| 14 |
BORDER, TEXT, TEXT_MUTED, TEXT_FAINT,
|
| 15 |
FS_PAGE, FS_BODY, FS_META, FS_EYEBROW,
|
| 16 |
)
|
| 17 |
from dashboard.components import (
|
| 18 |
ai_badge, eyebrow_label, section_header, sort_by_impact,
|
| 19 |
+
importance_marker, _pill, meta_row, evidence_quote,
|
| 20 |
)
|
| 21 |
from dashboard.signal_feed import top_tell
|
| 22 |
from dashboard.chat import _watch_to_question
|
|
|
|
| 49 |
st.markdown(
|
| 50 |
f"""<style>
|
| 51 |
.st-key-verdict_ask_cta [data-testid="stBaseButton-secondary"] {{
|
| 52 |
+
background: #1e1633 !important;
|
| 53 |
+
border: 1px solid #432d7a !important;
|
| 54 |
color: {AI_COLOR} !important;
|
| 55 |
font-weight: 600 !important;
|
| 56 |
}}
|
| 57 |
.st-key-verdict_ask_cta [data-testid="stBaseButton-secondary"]:hover {{
|
| 58 |
+
background: #2a1f52 !important;
|
| 59 |
}}
|
| 60 |
</style>""",
|
| 61 |
unsafe_allow_html=True,
|
|
|
|
| 204 |
)
|
| 205 |
st.markdown(
|
| 206 |
f'<div style="display:flex;align-items:center;gap:10px;flex-wrap:wrap;'
|
| 207 |
+
f'background:#1a2029;border:1px solid {BORDER};border-radius:8px;'
|
| 208 |
f'padding:9px 12px;margin:0 0 18px;">'
|
| 209 |
f'<span style="font-size:{FS_META};color:{TEXT_MUTED};">'
|
| 210 |
f'{t("data_through_label").format(date=filing_date)}</span>'
|
|
|
|
| 220 |
)
|
| 221 |
|
| 222 |
|
| 223 |
+
def _render_evidence_warning(brief: dict) -> None:
|
| 224 |
+
"""Surface weak source verification as an alert.
|
| 225 |
+
|
| 226 |
+
The count already appears in the status strip, but at meta size next to
|
| 227 |
+
four other fragments — "1/51 verified" is the single most important caveat
|
| 228 |
+
on the screen and was the easiest thing on it to miss.
|
| 229 |
+
"""
|
| 230 |
+
coverage = brief.get("evidence_coverage")
|
| 231 |
+
if not isinstance(coverage, dict) or not coverage:
|
| 232 |
+
return
|
| 233 |
+
try:
|
| 234 |
+
verified = max(0, int(coverage.get("verified") or 0))
|
| 235 |
+
total = max(0, int(coverage.get("total") or 0))
|
| 236 |
+
except (TypeError, ValueError):
|
| 237 |
+
return
|
| 238 |
+
if total <= 0 or verified >= total:
|
| 239 |
+
return
|
| 240 |
+
# Only shout when verification is genuinely thin; a near-complete brief
|
| 241 |
+
# already says "Incomplete · 49/51" in the strip and needs no banner.
|
| 242 |
+
if verified / total >= 0.5:
|
| 243 |
+
return
|
| 244 |
+
body = t("evidence_weak_body").format(
|
| 245 |
+
verified=verified, total=total, section=t("nav_signals")
|
| 246 |
+
)
|
| 247 |
+
# Two trailing spaces before the newline force a markdown line break.
|
| 248 |
+
st.warning(f'**{t("evidence_weak_title")}** \n{body}')
|
| 249 |
+
|
| 250 |
+
|
| 251 |
def _render_partial_notice(brief: dict) -> None:
|
| 252 |
evidence_coverage = brief.get("evidence_coverage") or {}
|
| 253 |
if brief.get("status") == "PARTIAL" and evidence_coverage.get("verified", 0) == 0:
|
| 254 |
st.warning(t("partial_brief_notice_zero"))
|
| 255 |
|
| 256 |
|
| 257 |
+
def _render_standout_number(brief: dict) -> None:
|
| 258 |
+
"""The single headline figure the model flagged as most consequential
|
| 259 |
+
this period — a grounded SourcedFact (not an AI interpretation), same
|
| 260 |
+
verification path as bull/bear points. Computed every run but was never
|
| 261 |
+
rendered anywhere in the dashboard."""
|
| 262 |
+
sn = brief.get("standout_number")
|
| 263 |
+
if not isinstance(sn, dict) or not sn.get("text"):
|
| 264 |
+
return
|
| 265 |
+
st.markdown(
|
| 266 |
+
f'<div class="primer-section-card" style="max-width:760px;margin:18px 0 0;">'
|
| 267 |
+
f'<div style="font-size:{FS_EYEBROW};font-weight:700;letter-spacing:0.1em;'
|
| 268 |
+
f'text-transform:uppercase;color:{TEXT_MUTED};margin-bottom:8px;">{t("standout_number_label")}</div>'
|
| 269 |
+
f'<div style="font-size:1.1rem;line-height:1.6;color:{TEXT};font-weight:650;">'
|
| 270 |
+
f'{sn.get("text", "")}</div>'
|
| 271 |
+
f'{meta_row(sn.get("reliability", ""), sn.get("source", ""), sn.get("impact", ""))}'
|
| 272 |
+
f'{evidence_quote(sn.get("evidence_snippet", ""))}'
|
| 273 |
+
f'</div>',
|
| 274 |
+
unsafe_allow_html=True,
|
| 275 |
+
)
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
def _render_non_obvious_takeaway(brief: dict) -> None:
|
| 279 |
+
"""The one thing most readers will miss this quarter — LLM-synthesized
|
| 280 |
+
and cross-referenced from 2+ already-verified facts elsewhere in the
|
| 281 |
+
brief (see agent/evidence.py). Computed every run but was never rendered
|
| 282 |
+
anywhere in the dashboard."""
|
| 283 |
+
takeaway = (brief.get("non_obvious_takeaway") or "").strip()
|
| 284 |
+
if not takeaway:
|
| 285 |
+
return
|
| 286 |
+
st.markdown(
|
| 287 |
+
f'<div class="primer-section-card" style="max-width:760px;margin:14px 0 24px;'
|
| 288 |
+
f'background:#1e1633;border:1px solid #432d7a;">'
|
| 289 |
+
f'<div style="display:flex;align-items:center;gap:8px;margin-bottom:8px;">'
|
| 290 |
+
f'<span style="font-size:{FS_EYEBROW};font-weight:700;letter-spacing:0.1em;'
|
| 291 |
+
f'text-transform:uppercase;color:{AI_COLOR};">{t("non_obvious_takeaway_label")}</span>'
|
| 292 |
+
f'{ai_badge("AI · experimental")}</div>'
|
| 293 |
+
f'<div style="font-size:1rem;line-height:1.6;color:{TEXT};">{takeaway}</div>'
|
| 294 |
+
f'</div>',
|
| 295 |
+
unsafe_allow_html=True,
|
| 296 |
+
)
|
| 297 |
+
|
| 298 |
+
|
| 299 |
def _render_thesis(brief: dict) -> None:
|
| 300 |
+
"""Render the concise read-through without an unsupported second take."""
|
| 301 |
what_matters = brief.get("what_matters_most", "")
|
| 302 |
if not what_matters:
|
| 303 |
return
|
|
|
|
| 305 |
f'<div class="primer-section-card" style="max-width:760px;margin:18px 0 24px;">'
|
| 306 |
f'<div style="display:flex;align-items:center;gap:8px;margin-bottom:10px;">'
|
| 307 |
f'<span style="font-size:{FS_EYEBROW};font-weight:700;letter-spacing:0.1em;'
|
| 308 |
+
f'text-transform:uppercase;color:{TEXT_MUTED};">{t("read_through_label")}</span>'
|
| 309 |
f'{ai_badge("AI · experimental")}</div>'
|
| 310 |
f'<div style="font-size:1.15rem;line-height:1.65;color:{TEXT};font-weight:500;">'
|
| 311 |
f'{what_matters}</div></div>',
|
|
|
|
| 313 |
)
|
| 314 |
|
| 315 |
|
| 316 |
+
def _fmt_big(value: float, currency: str = "$") -> str:
|
| 317 |
+
"""Format a large money figure as T / B / M."""
|
| 318 |
+
for cutoff, unit in ((1e12, "T"), (1e9, "B"), (1e6, "M")):
|
| 319 |
+
if abs(value) >= cutoff:
|
| 320 |
+
return f"{currency}{value / cutoff:.2f}{unit}"
|
| 321 |
+
return f"{currency}{value:,.0f}"
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
def _stat_cell(label: str, value: str, sub: str = "", color: str = "") -> str:
|
| 325 |
+
sub_html = (
|
| 326 |
+
f'<div style="font-size:0.7rem;color:{TEXT_MUTED};margin-top:3px;">{sub}</div>'
|
| 327 |
+
if sub else ""
|
| 328 |
+
)
|
| 329 |
+
return (
|
| 330 |
+
f'<div style="flex:1 1 130px;min-width:0;padding:12px 16px;">'
|
| 331 |
+
f'<div style="font-size:0.62rem;font-weight:700;text-transform:uppercase;'
|
| 332 |
+
f'letter-spacing:0.08em;color:{TEXT_FAINT};margin-bottom:5px;">{label}</div>'
|
| 333 |
+
f'<div style="font-size:1.15rem;font-weight:700;line-height:1.2;'
|
| 334 |
+
f'color:{color or TEXT};">{value}</div>'
|
| 335 |
+
f'{sub_html}</div>'
|
| 336 |
+
)
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
def _render_market_band(ticker: str) -> None:
|
| 340 |
+
"""Where the stock is trading right now.
|
| 341 |
+
|
| 342 |
+
A one-screen memo about a listed company that never showed its price forced
|
| 343 |
+
the reader out of the app for the most basic piece of context. Market
|
| 344 |
+
context only -- never a valuation, never a target.
|
| 345 |
+
"""
|
| 346 |
+
try:
|
| 347 |
+
from analytics.valuation import fetch_multiples
|
| 348 |
+
data, _err = fetch_multiples(ticker)
|
| 349 |
+
except Exception:
|
| 350 |
+
return
|
| 351 |
+
if not data:
|
| 352 |
+
return
|
| 353 |
+
|
| 354 |
+
currency_code = str(data.get("currency") or "USD")
|
| 355 |
+
symbol = {"USD": "$", "EUR": "€", "GBP": "£"}.get(
|
| 356 |
+
currency_code, f"{currency_code} "
|
| 357 |
+
)
|
| 358 |
+
|
| 359 |
+
cells: list[str] = []
|
| 360 |
+
price = data.get("price")
|
| 361 |
+
if price is not None:
|
| 362 |
+
prev = data.get("previous_close")
|
| 363 |
+
sub, color = "", ""
|
| 364 |
+
if prev:
|
| 365 |
+
change = (price - prev) / abs(prev) * 100
|
| 366 |
+
color = GREEN if change >= 0 else RED
|
| 367 |
+
sign = "+" if change >= 0 else ""
|
| 368 |
+
sub = f'<span style="color:{color};">{sign}{change:.2f}% today</span>'
|
| 369 |
+
cells.append(_stat_cell(t("brief_price_label"), f"{symbol}{price:,.2f}", sub))
|
| 370 |
+
|
| 371 |
+
market_cap = data.get("market_cap")
|
| 372 |
+
if market_cap:
|
| 373 |
+
cells.append(_stat_cell(t("brief_market_cap_label"), _fmt_big(market_cap, symbol)))
|
| 374 |
+
|
| 375 |
+
low, high = data.get("week52_low"), data.get("week52_high")
|
| 376 |
+
if low and high and high > low:
|
| 377 |
+
sub = ""
|
| 378 |
+
if price is not None:
|
| 379 |
+
position = max(0.0, min(1.0, (price - low) / (high - low))) * 100
|
| 380 |
+
# A thin track with a marker reads faster than "38% of range".
|
| 381 |
+
sub = (
|
| 382 |
+
f'<span style="display:inline-block;position:relative;width:96px;'
|
| 383 |
+
f'height:4px;border-radius:2px;background:{BORDER};'
|
| 384 |
+
f'vertical-align:middle;">'
|
| 385 |
+
f'<span style="position:absolute;left:{position:.0f}%;top:-3px;'
|
| 386 |
+
f'width:2px;height:10px;background:{GREEN};"></span></span>'
|
| 387 |
+
)
|
| 388 |
+
cells.append(_stat_cell(
|
| 389 |
+
t("brief_52w_label"), f"{symbol}{low:,.0f} – {symbol}{high:,.0f}", sub
|
| 390 |
+
))
|
| 391 |
+
|
| 392 |
+
dividend_yield = data.get("dividend_yield_pct")
|
| 393 |
+
if dividend_yield:
|
| 394 |
+
cells.append(_stat_cell(t("brief_div_yield_label"), f"{dividend_yield:.2f}%"))
|
| 395 |
+
|
| 396 |
+
if not cells:
|
| 397 |
+
return
|
| 398 |
+
st.markdown(
|
| 399 |
+
f'<div style="display:flex;flex-wrap:wrap;border:1px solid {BORDER};'
|
| 400 |
+
f'border-radius:10px;background:#151a21;margin:4px 0 6px;">'
|
| 401 |
+
f'{"".join(cells)}</div>'
|
| 402 |
+
f'<div style="font-size:0.64rem;color:{TEXT_FAINT};margin-bottom:18px;">'
|
| 403 |
+
f'{t("brief_quote_note")}</div>',
|
| 404 |
+
unsafe_allow_html=True,
|
| 405 |
+
)
|
| 406 |
+
|
| 407 |
+
|
| 408 |
+
def _render_quarter_kpis(ticker: str) -> None:
|
| 409 |
+
"""Reported figures for the quarter this brief covers.
|
| 410 |
+
|
| 411 |
+
The read-through quotes growth rates in prose, but the memo carried no
|
| 412 |
+
numbers of its own -- the reader had to open Financials to see what the
|
| 413 |
+
company actually reported. Rows come from the same masked view Financials
|
| 414 |
+
uses, so a figure hidden there stays hidden here.
|
| 415 |
+
"""
|
| 416 |
+
try:
|
| 417 |
+
from storage.metrics_db import get_all_metrics
|
| 418 |
+
from dashboard.financials import _display_rows, _comparable_prior, _safe
|
| 419 |
+
rows = _display_rows(get_all_metrics(ticker))
|
| 420 |
+
except Exception:
|
| 421 |
+
return
|
| 422 |
+
if not rows:
|
| 423 |
+
return
|
| 424 |
+
latest = rows[0]
|
| 425 |
+
prior = _comparable_prior(rows, latest)
|
| 426 |
+
|
| 427 |
+
specs = [
|
| 428 |
+
("brief_metric_revenue", "revenue", "money"),
|
| 429 |
+
("brief_metric_eps", "eps", "unit"),
|
| 430 |
+
("brief_metric_gross_margin", "gross_margin", "pct"),
|
| 431 |
+
("brief_metric_op_margin", "operating_margin", "pct"),
|
| 432 |
+
("brief_metric_fcf", "free_cash_flow", "money"),
|
| 433 |
+
]
|
| 434 |
+
|
| 435 |
+
def _format(value, kind: str) -> str:
|
| 436 |
+
if value is None:
|
| 437 |
+
return "—"
|
| 438 |
+
if kind == "money":
|
| 439 |
+
return _fmt_big(value)
|
| 440 |
+
if kind == "pct":
|
| 441 |
+
return f"{value * 100:.1f}%"
|
| 442 |
+
return f"${value:.2f}"
|
| 443 |
+
|
| 444 |
+
cells: list[str] = []
|
| 445 |
+
for label_key, field, kind in specs:
|
| 446 |
+
current = _safe(latest.get(field))
|
| 447 |
+
if current is None:
|
| 448 |
+
continue
|
| 449 |
+
previous = _safe(prior.get(field)) if prior else None
|
| 450 |
+
sub, color = "", ""
|
| 451 |
+
if previous is not None and previous != 0:
|
| 452 |
+
change = (current - previous) / abs(previous) * 100
|
| 453 |
+
color = GREEN if change >= 0 else RED
|
| 454 |
+
arrow = "▲" if change >= 0 else "▼"
|
| 455 |
+
sub = (
|
| 456 |
+
f'<span style="color:{color};">{arrow} {abs(change):.1f}%</span>'
|
| 457 |
+
f' vs {_format(previous, kind)}'
|
| 458 |
+
)
|
| 459 |
+
cells.append(_stat_cell(t(label_key), _format(current, kind), sub, color))
|
| 460 |
+
|
| 461 |
+
if not cells:
|
| 462 |
+
return
|
| 463 |
+
|
| 464 |
+
from dashboard import fmt_period
|
| 465 |
+
|
| 466 |
+
period = fmt_period(str(latest.get("period") or ""))
|
| 467 |
+
form = str(latest.get("form_type") or "")
|
| 468 |
+
prior_period = fmt_period(str(prior.get("period") or "")) if prior else ""
|
| 469 |
+
heading = " · ".join(part for part in (form, period) if part)
|
| 470 |
+
comparison = f" vs {prior_period}" if prior_period else ""
|
| 471 |
+
|
| 472 |
+
st.markdown(
|
| 473 |
+
section_header(t("brief_quarter_title"), accent=GREEN),
|
| 474 |
+
unsafe_allow_html=True,
|
| 475 |
+
)
|
| 476 |
+
st.markdown(
|
| 477 |
+
f'<div style="font-size:{FS_META};color:{TEXT_MUTED};margin:-6px 0 8px;">'
|
| 478 |
+
f'{heading}{comparison}</div>'
|
| 479 |
+
f'<div style="display:flex;flex-wrap:wrap;border:1px solid {BORDER};'
|
| 480 |
+
f'border-radius:10px;background:#151a21;">{"".join(cells)}</div>'
|
| 481 |
+
f'<div style="font-size:0.64rem;color:{TEXT_FAINT};margin-top:6px;">'
|
| 482 |
+
f'{t("brief_quarter_note").format(section=t("nav_financials"))}</div>',
|
| 483 |
+
unsafe_allow_html=True,
|
| 484 |
+
)
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
def _render_what_changed(brief: dict) -> None:
|
| 488 |
+
"""The quarter's concrete changes -- the first thing the brief promises.
|
| 489 |
+
|
| 490 |
+
These were only reachable on the What Changed screen, so the memo jumped
|
| 491 |
+
straight from the AI read-through to the bull and bear case.
|
| 492 |
+
"""
|
| 493 |
+
items = sort_by_impact([
|
| 494 |
+
item for item in (brief.get("what_changed") or [])
|
| 495 |
+
if isinstance(item, dict) and str(item.get("text") or "").strip()
|
| 496 |
+
])
|
| 497 |
+
if not items:
|
| 498 |
+
return
|
| 499 |
+
|
| 500 |
+
st.markdown(
|
| 501 |
+
section_header(t("brief_what_changed_title"), accent=BLUE),
|
| 502 |
+
unsafe_allow_html=True,
|
| 503 |
+
)
|
| 504 |
+
rows: list[str] = []
|
| 505 |
+
for item in items[:4]:
|
| 506 |
+
meta_bits = [bit for bit in (
|
| 507 |
+
importance_marker((item.get("impact") or "").upper()),
|
| 508 |
+
f'<span style="font-size:{FS_META};color:{TEXT_MUTED};">{item.get("source", "")}</span>'
|
| 509 |
+
if item.get("source") else "",
|
| 510 |
+
) if bit]
|
| 511 |
+
rows.append(
|
| 512 |
+
f'<div style="display:flex;gap:10px;align-items:flex-start;padding:11px 0;'
|
| 513 |
+
f'border-bottom:1px solid {BORDER};">'
|
| 514 |
+
f'<span style="color:{BLUE};flex-shrink:0;margin-top:2px;">→</span>'
|
| 515 |
+
f'<div style="flex:1;min-width:0;">'
|
| 516 |
+
f'<div style="font-size:{FS_BODY};line-height:1.55;color:{TEXT};">'
|
| 517 |
+
f'{item["text"]}</div>'
|
| 518 |
+
f'<div style="display:flex;gap:8px;align-items:center;margin-top:4px;">'
|
| 519 |
+
f'{"".join(meta_bits)}</div>'
|
| 520 |
+
f'{evidence_quote(item.get("evidence_snippet", ""), bg="#1a2029", border_color=BORDER)}'
|
| 521 |
+
f'</div></div>'
|
| 522 |
+
)
|
| 523 |
+
st.markdown("".join(rows), unsafe_allow_html=True)
|
| 524 |
+
|
| 525 |
+
|
| 526 |
def _asym_line(item: dict, marker: str, color: str) -> str:
|
| 527 |
meta_bits = [bit for bit in (
|
| 528 |
importance_marker((item.get("impact") or "").upper()),
|
|
|
|
| 543 |
)
|
| 544 |
|
| 545 |
|
| 546 |
+
def _asymmetry_points(brief: dict) -> tuple[list[dict], list[dict]]:
|
| 547 |
confirming = sort_by_impact([
|
| 548 |
item for item in (brief.get("bull_points") or []) if isinstance(item, dict)
|
| 549 |
])[:2]
|
| 550 |
challenging = sort_by_impact([
|
| 551 |
item for item in (brief.get("bear_points") or []) if isinstance(item, dict)
|
| 552 |
])[:2]
|
| 553 |
+
return confirming, challenging
|
| 554 |
+
|
| 555 |
+
|
| 556 |
+
def has_asymmetry(brief: dict) -> bool:
|
| 557 |
+
confirming, challenging = _asymmetry_points(brief)
|
| 558 |
+
return bool(confirming or challenging)
|
| 559 |
+
|
| 560 |
+
|
| 561 |
+
def _render_asymmetry(brief: dict) -> None:
|
| 562 |
+
confirming, challenging = _asymmetry_points(brief)
|
| 563 |
+
|
| 564 |
+
st.markdown(
|
| 565 |
+
section_header(t("thesis_test_title"), accent="#94a3b8"),
|
| 566 |
+
unsafe_allow_html=True,
|
| 567 |
+
)
|
| 568 |
if not confirming and not challenging:
|
| 569 |
+
# The brief promises a bull and bear case, so an empty section has to
|
| 570 |
+
# explain itself. Disappearing silently reads as a missing feature and
|
| 571 |
+
# is what left the left-hand column blank.
|
| 572 |
+
st.info(t("thesis_unavailable").format(section=t("nav_signals")))
|
| 573 |
+
if st.button(t("open_evidence_cta"), key="verdict_all_signals_empty"):
|
| 574 |
+
_go_to_signals()
|
| 575 |
return
|
| 576 |
|
|
|
|
| 577 |
with st.container(border=True):
|
| 578 |
confirm_col, challenge_col = st.columns(2)
|
| 579 |
with confirm_col:
|
| 580 |
st.markdown(
|
| 581 |
f'<div style="margin-bottom:4px;">'
|
| 582 |
+
f'{eyebrow_label(t("thesis_confirming"), GREEN)}</div>'
|
| 583 |
+ "".join(_asym_line(item, "▲", GREEN) for item in confirming),
|
| 584 |
unsafe_allow_html=True,
|
| 585 |
)
|
| 586 |
with challenge_col:
|
| 587 |
st.markdown(
|
| 588 |
f'<div style="margin-bottom:4px;">'
|
| 589 |
+
f'{eyebrow_label(t("thesis_challenging"), RED)}</div>'
|
| 590 |
+ "".join(_asym_line(item, "▼", RED) for item in challenging),
|
| 591 |
unsafe_allow_html=True,
|
| 592 |
)
|
| 593 |
+
if st.button(t("open_evidence_cta"), key="verdict_all_signals"):
|
| 594 |
_go_to_signals()
|
| 595 |
|
| 596 |
|
|
|
|
| 600 |
return ""
|
| 601 |
|
| 602 |
|
| 603 |
+
def has_swing_factor(brief: dict) -> bool:
|
| 604 |
+
return _select_swing_factor(brief) is not None
|
| 605 |
+
|
| 606 |
+
|
| 607 |
def _render_swing_factor(brief: dict) -> None:
|
| 608 |
factor = _select_swing_factor(brief)
|
| 609 |
if factor is None:
|
| 610 |
return
|
| 611 |
|
| 612 |
+
st.markdown(
|
| 613 |
+
section_header(t("swing_factor_title"), accent=AI_COLOR),
|
| 614 |
+
unsafe_allow_html=True,
|
| 615 |
+
)
|
| 616 |
st.markdown(
|
| 617 |
f'<div style="display:flex;align-items:center;gap:8px;margin-bottom:8px;">'
|
| 618 |
f'{ai_badge("AI · experimental")}'
|
| 619 |
f'<span style="font-size:{FS_META};color:{TEXT_MUTED};">'
|
| 620 |
+
f'{t("swing_hypothesis_note")}</span></div>',
|
| 621 |
unsafe_allow_html=True,
|
| 622 |
)
|
| 623 |
|
| 624 |
with st.container(border=True):
|
| 625 |
+
headline = factor.get("headline") or t("swing_default_headline")
|
| 626 |
st.markdown(
|
| 627 |
f'<div style="font-size:{FS_BODY};font-weight:650;color:{TEXT};'
|
| 628 |
f'line-height:1.5;margin-bottom:10px;">{headline}</div>',
|
|
|
|
| 633 |
with bull_col:
|
| 634 |
source = _evidence_source(factor.get("bullish_evidence"))
|
| 635 |
st.markdown(
|
| 636 |
+
eyebrow_label(t("swing_if_confirmed"), GREEN)
|
| 637 |
+ f'<div style="font-size:{FS_BODY};line-height:1.55;color:{TEXT};margin-top:6px;">'
|
| 638 |
f'{factor.get("bullish_reading", "")}</div>'
|
| 639 |
+ (f'<div style="font-size:{FS_META};color:{TEXT_MUTED};margin-top:6px;">{source}</div>' if source else ""),
|
|
|
|
| 642 |
with bear_col:
|
| 643 |
source = _evidence_source(factor.get("bearish_evidence"))
|
| 644 |
st.markdown(
|
| 645 |
+
eyebrow_label(t("swing_if_challenged"), RED)
|
| 646 |
+ f'<div style="font-size:{FS_BODY};line-height:1.55;color:{TEXT};margin-top:6px;">'
|
| 647 |
f'{factor.get("bearish_reading", "")}</div>'
|
| 648 |
+ (f'<div style="font-size:{FS_META};color:{TEXT_MUTED};margin-top:6px;">{source}</div>' if source else ""),
|
|
|
|
| 654 |
st.markdown(
|
| 655 |
f'<div style="font-size:{FS_BODY};line-height:1.55;color:{TEXT};">{reading}</div>'
|
| 656 |
+ (f'<div style="font-size:{FS_META};line-height:1.5;color:{AI_COLOR};margin-top:8px;">'
|
| 657 |
+
f'{t("swing_implication")} {implication}</div>' if implication else ""),
|
| 658 |
unsafe_allow_html=True,
|
| 659 |
)
|
| 660 |
+
if st.button(t("validate_evidence_cta"), key="verdict_swing_signals"):
|
| 661 |
_go_to_signals()
|
| 662 |
|
| 663 |
|
| 664 |
+
def _watch_row(index: int, item: dict) -> str:
|
| 665 |
+
chips = [
|
| 666 |
+
_pill(value, GRAY, "#1a2029")
|
| 667 |
+
for value in (item["metric"], item["threshold"], item["period"], item["status"])
|
| 668 |
+
if value
|
| 669 |
+
]
|
| 670 |
+
source = (
|
| 671 |
+
f'<span style="font-size:{FS_META};color:{TEXT_MUTED};">{item["source"]}</span>'
|
| 672 |
+
if item["source"] else ""
|
| 673 |
+
)
|
| 674 |
+
primary = item["text"] or item["metric"] or "Watch item"
|
| 675 |
+
meta = (
|
| 676 |
+
f'<div style="display:flex;gap:6px;align-items:center;flex-wrap:wrap;margin-top:6px;">'
|
| 677 |
+
f'{"".join(chips)}{source}</div>' if (chips or source) else ""
|
| 678 |
+
)
|
| 679 |
+
return (
|
| 680 |
+
f'<div style="display:flex;gap:12px;align-items:flex-start;padding:11px 0;'
|
| 681 |
+
f'border-bottom:1px solid {BORDER};">'
|
| 682 |
+
f'<span style="font-size:{FS_META};font-weight:700;color:{AMBER};'
|
| 683 |
+
f'flex-shrink:0;margin-top:2px;">{index:02d}</span>'
|
| 684 |
+
f'<div style="flex:1;min-width:0;">'
|
| 685 |
+
f'<div style="font-size:{FS_BODY};line-height:1.55;color:{TEXT};">{primary}</div>'
|
| 686 |
+
f'{meta}</div></div>'
|
| 687 |
+
)
|
| 688 |
+
|
| 689 |
+
|
| 690 |
def _render_watch(brief: dict) -> None:
|
| 691 |
items = _normalize_watch_items(brief.get("what_to_watch") or [])
|
| 692 |
if not items:
|
| 693 |
return
|
| 694 |
+
st.markdown(
|
| 695 |
+
section_header(t("brief_watch_title"), accent=AMBER),
|
| 696 |
+
unsafe_allow_html=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 697 |
)
|
| 698 |
+
# The list used to be capped at 760px on a 1280px column, and the overflow
|
| 699 |
+
# was announced as dead text ("+ 1 additional watch items") with no way to
|
| 700 |
+
# read it. Full width now, and the remainder opens.
|
| 701 |
st.markdown(
|
| 702 |
+
"".join(_watch_row(i, item) for i, item in enumerate(items[:3], start=1)),
|
| 703 |
unsafe_allow_html=True,
|
| 704 |
)
|
| 705 |
+
remainder = items[3:]
|
| 706 |
+
if remainder:
|
| 707 |
+
label = (
|
| 708 |
+
t("brief_watch_more_one") if len(remainder) == 1
|
| 709 |
+
else t("brief_watch_more").format(count=len(remainder))
|
| 710 |
+
)
|
| 711 |
+
with st.expander(label):
|
| 712 |
+
st.markdown(
|
| 713 |
+
"".join(
|
| 714 |
+
_watch_row(i, item)
|
| 715 |
+
for i, item in enumerate(remainder, start=4)
|
| 716 |
+
),
|
| 717 |
+
unsafe_allow_html=True,
|
| 718 |
+
)
|
| 719 |
|
| 720 |
|
| 721 |
def _render_brief_diff(brief: dict, ticker: str) -> None:
|
|
|
|
| 858 |
st.markdown(
|
| 859 |
f'<div style="margin-bottom:12px;padding-bottom:12px;border-bottom:1px solid {BORDER};">'
|
| 860 |
f'<div style="font-size:{FS_PAGE};font-weight:700;color:{TEXT};letter-spacing:-0.02em;">'
|
| 861 |
+
f'{t("nav_verdict")}</div>'
|
| 862 |
f'<div style="font-size:{FS_META};color:{TEXT_FAINT};margin-top:4px;">{subtitle}</div>'
|
| 863 |
f'</div>',
|
| 864 |
unsafe_allow_html=True,
|
| 865 |
)
|
| 866 |
|
| 867 |
+
# Order matters: a reader opening this screen wants the read-through, not
|
| 868 |
+
# the provenance expander, the PDF button and the status strip that used to
|
| 869 |
+
# sit above it. Caveats that change how the text should be read come first;
|
| 870 |
+
# everything else is pushed below the synthesis.
|
| 871 |
+
# Market context first: a memo about a listed company that never shows its
|
| 872 |
+
# price makes the reader leave the app for the most basic fact about it.
|
| 873 |
+
_render_market_band(ticker)
|
| 874 |
_render_partial_notice(brief)
|
| 875 |
+
_render_evidence_warning(brief)
|
| 876 |
_render_thesis(brief)
|
| 877 |
+
_render_standout_number(brief)
|
| 878 |
+
_render_non_obvious_takeaway(brief)
|
| 879 |
_render_ask_cta(brief)
|
| 880 |
+
# The reported numbers and the concrete changes are the sourced backbone of
|
| 881 |
+
# the memo; they sit directly under the interpretation they support.
|
| 882 |
+
_render_quarter_kpis(ticker)
|
| 883 |
+
_render_what_changed(brief)
|
| 884 |
+
_render_status_strip(brief)
|
| 885 |
+
_render_brief_diff(brief, ticker)
|
| 886 |
|
| 887 |
+
# Pair the two cards side by side only when both have content. Either one
|
| 888 |
+
# can be filtered out by the fail-closed policy, and when that happened the
|
| 889 |
+
# survivor was stranded in one half of a two-column row with the other half
|
| 890 |
+
# blank — on a wide screen that read as a rendering fault.
|
| 891 |
+
if has_asymmetry(brief) and has_swing_factor(brief):
|
| 892 |
+
left, right = st.columns(2, gap="large")
|
| 893 |
+
with left:
|
| 894 |
+
_render_asymmetry(brief)
|
| 895 |
+
with right:
|
| 896 |
+
_render_swing_factor(brief)
|
| 897 |
+
else:
|
| 898 |
_render_asymmetry(brief)
|
|
|
|
| 899 |
_render_swing_factor(brief)
|
| 900 |
|
| 901 |
_render_watch(brief)
|
|
|
|
| 906 |
_render_valuation_strip(ticker)
|
| 907 |
with cat_col:
|
| 908 |
_render_catalysts(ticker)
|
| 909 |
+
|
| 910 |
+
# Sources and export are reference material, not the headline — they close
|
| 911 |
+
# the page instead of gating it.
|
| 912 |
+
st.markdown("<div style='height:26px'></div>", unsafe_allow_html=True)
|
| 913 |
+
with st.expander(t("verdict_tools_label"), expanded=False):
|
| 914 |
+
provenance.render_card(ticker, brief)
|
| 915 |
+
_render_pdf_export(brief, ticker)
|
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Read-only deployment preflight for the Amplegest Hugging Face Space."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import sqlite3
|
| 6 |
+
import subprocess
|
| 7 |
+
import tempfile
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
from typing import Callable, Iterable
|
| 10 |
+
|
| 11 |
+
from agent.company_profile import profile_source_coverage
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
REPO_ROOT = Path(__file__).resolve().parent
|
| 15 |
+
METRICS_DB = REPO_ROOT / "data" / "metrics.db"
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class GitCommandError(RuntimeError):
|
| 19 |
+
"""A local, read-only git inspection command failed."""
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _run_git(args: list[str]) -> subprocess.CompletedProcess[str]:
|
| 23 |
+
return subprocess.run(
|
| 24 |
+
["git", *args],
|
| 25 |
+
cwd=REPO_ROOT,
|
| 26 |
+
check=False,
|
| 27 |
+
capture_output=True,
|
| 28 |
+
text=True,
|
| 29 |
+
encoding="utf-8",
|
| 30 |
+
errors="replace",
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def git_status_data() -> str:
|
| 35 |
+
"""Return porcelain status for data/ without writing LFS objects to .git/."""
|
| 36 |
+
with tempfile.TemporaryDirectory(prefix="amplegest-deploy-check-lfs-") as tmp:
|
| 37 |
+
lfs_storage = Path(tmp)
|
| 38 |
+
(lfs_storage / "tmp").mkdir()
|
| 39 |
+
result = _run_git(
|
| 40 |
+
[
|
| 41 |
+
"-c",
|
| 42 |
+
f"lfs.storage={lfs_storage}",
|
| 43 |
+
"status",
|
| 44 |
+
"--porcelain",
|
| 45 |
+
"--",
|
| 46 |
+
"data/",
|
| 47 |
+
]
|
| 48 |
+
)
|
| 49 |
+
if result.returncode != 0:
|
| 50 |
+
detail = result.stderr.strip() or result.stdout.strip() or "unknown git error"
|
| 51 |
+
raise GitCommandError(f"git status --porcelain -- data/ failed: {detail}")
|
| 52 |
+
return result.stdout
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def parse_data_status(porcelain_output: str) -> list[str]:
|
| 56 |
+
"""Extract changed paths from simulated or real porcelain-v1 output."""
|
| 57 |
+
paths: list[str] = []
|
| 58 |
+
for line in porcelain_output.splitlines():
|
| 59 |
+
if len(line) < 4 or line[2] != " ":
|
| 60 |
+
continue
|
| 61 |
+
path = line[3:]
|
| 62 |
+
if " -> " in path:
|
| 63 |
+
path = path.rsplit(" -> ", 1)[1]
|
| 64 |
+
paths.append(path.strip('"'))
|
| 65 |
+
return paths
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def load_metric_tickers(db_path: Path = METRICS_DB) -> list[str]:
|
| 69 |
+
"""Read distinct metric tickers without allowing SQLite writes."""
|
| 70 |
+
database_uri = f"{db_path.resolve().as_uri()}?mode=ro"
|
| 71 |
+
with sqlite3.connect(database_uri, uri=True) as conn:
|
| 72 |
+
rows = conn.execute(
|
| 73 |
+
"""
|
| 74 |
+
SELECT DISTINCT UPPER(TRIM(ticker))
|
| 75 |
+
FROM metrics
|
| 76 |
+
WHERE ticker IS NOT NULL AND TRIM(ticker) <> ''
|
| 77 |
+
ORDER BY 1
|
| 78 |
+
"""
|
| 79 |
+
).fetchall()
|
| 80 |
+
return [row[0] for row in rows]
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def collect_coverage(
|
| 84 |
+
tickers: Iterable[str],
|
| 85 |
+
coverage_fn: Callable[[str], dict] | None = None,
|
| 86 |
+
) -> tuple[list[dict], list[str]]:
|
| 87 |
+
"""Collect coverage rows and tickers that would show the backfill banner."""
|
| 88 |
+
check = coverage_fn or profile_source_coverage
|
| 89 |
+
rows: list[dict] = []
|
| 90 |
+
incomplete: list[str] = []
|
| 91 |
+
for ticker in tickers:
|
| 92 |
+
coverage = check(ticker)
|
| 93 |
+
row = {
|
| 94 |
+
"ticker": ticker,
|
| 95 |
+
"status": coverage.get("status", "UNKNOWN"),
|
| 96 |
+
"business_sections": coverage.get("business_sections", 0),
|
| 97 |
+
"segments_geography_sections": coverage.get(
|
| 98 |
+
"segments_geography_sections", 0
|
| 99 |
+
),
|
| 100 |
+
"recent_transcripts": coverage.get("recent_transcripts", 0),
|
| 101 |
+
}
|
| 102 |
+
rows.append(row)
|
| 103 |
+
if (
|
| 104 |
+
coverage.get("business_sections_attempted", 0) == 0
|
| 105 |
+
or coverage.get("segments_geography_sections_attempted", 0) == 0
|
| 106 |
+
):
|
| 107 |
+
incomplete.append(ticker)
|
| 108 |
+
return rows, incomplete
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def format_coverage_table(rows: list[dict]) -> str:
|
| 112 |
+
headers = (
|
| 113 |
+
"ticker",
|
| 114 |
+
"status",
|
| 115 |
+
"business_sections",
|
| 116 |
+
"segments_geography_sections",
|
| 117 |
+
"recent_transcripts",
|
| 118 |
+
)
|
| 119 |
+
text_rows = [[str(row.get(header, "")) for header in headers] for row in rows]
|
| 120 |
+
widths = [
|
| 121 |
+
max(len(header), *(len(row[index]) for row in text_rows))
|
| 122 |
+
for index, header in enumerate(headers)
|
| 123 |
+
]
|
| 124 |
+
|
| 125 |
+
def render(values: Iterable[str]) -> str:
|
| 126 |
+
return " ".join(value.ljust(width) for value, width in zip(values, widths))
|
| 127 |
+
|
| 128 |
+
separator = " ".join("-" * width for width in widths)
|
| 129 |
+
return "\n".join([render(headers), separator, *(render(row) for row in text_rows)])
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def resolve_ref(ref: str, *, optional: bool = False) -> str | None:
|
| 133 |
+
result = _run_git(["rev-parse", "--verify", ref])
|
| 134 |
+
if result.returncode == 0:
|
| 135 |
+
return result.stdout.strip()
|
| 136 |
+
if optional:
|
| 137 |
+
return None
|
| 138 |
+
detail = result.stderr.strip() or result.stdout.strip() or "ref not found"
|
| 139 |
+
raise GitCommandError(f"cannot resolve {ref}: {detail}")
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def main() -> int:
|
| 143 |
+
failed = False
|
| 144 |
+
print("Amplegest Hugging Face deployment preflight")
|
| 145 |
+
print("============================================")
|
| 146 |
+
|
| 147 |
+
try:
|
| 148 |
+
changes = parse_data_status(git_status_data())
|
| 149 |
+
except GitCommandError as exc:
|
| 150 |
+
print(f"\nERROR: {exc}")
|
| 151 |
+
changes = []
|
| 152 |
+
failed = True
|
| 153 |
+
else:
|
| 154 |
+
if changes:
|
| 155 |
+
failed = True
|
| 156 |
+
print("\nERROR: uncommitted data/ changes detected:")
|
| 157 |
+
for path in changes:
|
| 158 |
+
print(f" - {path}")
|
| 159 |
+
print(
|
| 160 |
+
"The Space will serve the committed data snapshot, not this local "
|
| 161 |
+
"working-tree state."
|
| 162 |
+
)
|
| 163 |
+
else:
|
| 164 |
+
print("\nOK: no uncommitted data/ changes.")
|
| 165 |
+
|
| 166 |
+
try:
|
| 167 |
+
tickers = load_metric_tickers()
|
| 168 |
+
coverage_rows, incomplete = collect_coverage(tickers)
|
| 169 |
+
except (OSError, sqlite3.Error) as exc:
|
| 170 |
+
print(f"\nERROR: could not read coverage inputs: {exc}")
|
| 171 |
+
failed = True
|
| 172 |
+
else:
|
| 173 |
+
print("\nCompany Primer source coverage:")
|
| 174 |
+
print(format_coverage_table(coverage_rows))
|
| 175 |
+
if incomplete:
|
| 176 |
+
failed = True
|
| 177 |
+
joined = ", ".join(incomplete)
|
| 178 |
+
print(f"\nERROR: Company Primer coverage incomplete for: {joined}")
|
| 179 |
+
print(
|
| 180 |
+
'Once deployed, the Company Primer will show the "coverage incomplete" '
|
| 181 |
+
"banner for these tickers."
|
| 182 |
+
)
|
| 183 |
+
else:
|
| 184 |
+
print("\nOK: required Company Primer sections were attempted for every ticker.")
|
| 185 |
+
|
| 186 |
+
try:
|
| 187 |
+
local_main = resolve_ref("main")
|
| 188 |
+
hf_main = resolve_ref("hf/main", optional=True)
|
| 189 |
+
except GitCommandError as exc:
|
| 190 |
+
print(f"\nERROR: {exc}")
|
| 191 |
+
failed = True
|
| 192 |
+
else:
|
| 193 |
+
print("\nLocal refs (no network fetch):")
|
| 194 |
+
print(f" main: {local_main}")
|
| 195 |
+
if hf_main is None:
|
| 196 |
+
print(" hf/main: not available locally (non-blocking)")
|
| 197 |
+
else:
|
| 198 |
+
print(f" hf/main: {hf_main}")
|
| 199 |
+
if local_main == hf_main:
|
| 200 |
+
print(" refs: identical")
|
| 201 |
+
else:
|
| 202 |
+
print(" refs: different (the local hf/main ref may be stale)")
|
| 203 |
+
|
| 204 |
+
if failed:
|
| 205 |
+
print("\nVERDICT: deployment preflight failed; do not push yet.")
|
| 206 |
+
return 1
|
| 207 |
+
|
| 208 |
+
print("\nVERDICT: deployment preflight passed.")
|
| 209 |
+
print("Deploy manually with: git push hf main:main")
|
| 210 |
+
return 0
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
if __name__ == "__main__":
|
| 214 |
+
raise SystemExit(main())
|
|
@@ -17,10 +17,29 @@ DB_PATH = Path("data/briefs.db")
|
|
| 17 |
BRIEF_SCHEMA_VERSION = "brief.v2"
|
| 18 |
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
def init_db() -> None:
|
| 21 |
"""Create the briefs table if it doesn't exist. Safe to call multiple times."""
|
| 22 |
DB_PATH.parent.mkdir(parents=True, exist_ok=True)
|
| 23 |
-
with
|
| 24 |
conn.execute("""
|
| 25 |
CREATE TABLE IF NOT EXISTS briefs (
|
| 26 |
ticker TEXT PRIMARY KEY,
|
|
@@ -85,7 +104,7 @@ def save_brief(ticker: str, brief_dict: dict) -> None:
|
|
| 85 |
"\x1f".join((ticker, filing_date, generated_at, schema_version, language)).encode("utf-8")
|
| 86 |
).hexdigest()[:32]
|
| 87 |
payload = json.dumps(brief_dict)
|
| 88 |
-
with
|
| 89 |
conn.execute(
|
| 90 |
"""
|
| 91 |
INSERT OR IGNORE INTO brief_snapshots (
|
|
@@ -132,7 +151,7 @@ def get_brief(
|
|
| 132 |
if not DB_PATH.exists():
|
| 133 |
return None
|
| 134 |
init_db()
|
| 135 |
-
with
|
| 136 |
clauses = ["ticker = ?"]
|
| 137 |
params: list[str] = [ticker.upper()]
|
| 138 |
if filing_date is not None:
|
|
@@ -206,7 +225,7 @@ def list_tickers() -> list[str]:
|
|
| 206 |
if not DB_PATH.exists():
|
| 207 |
return []
|
| 208 |
init_db()
|
| 209 |
-
with
|
| 210 |
rows = conn.execute(
|
| 211 |
"SELECT ticker FROM briefs UNION SELECT ticker FROM brief_snapshots ORDER BY ticker ASC"
|
| 212 |
).fetchall()
|
|
@@ -218,7 +237,7 @@ def delete_brief(ticker: str) -> int:
|
|
| 218 |
init_db()
|
| 219 |
ticker = ticker.upper()
|
| 220 |
deleted = 0
|
| 221 |
-
with
|
| 222 |
for table in ("briefs", "brief_snapshots", "brief_translations"):
|
| 223 |
cursor = conn.execute(f"DELETE FROM {table} WHERE ticker = ?", (ticker,))
|
| 224 |
deleted += cursor.rowcount
|
|
@@ -233,7 +252,7 @@ def list_briefs() -> list[dict]:
|
|
| 233 |
if not DB_PATH.exists():
|
| 234 |
return []
|
| 235 |
init_db()
|
| 236 |
-
with
|
| 237 |
rows = conn.execute("""
|
| 238 |
SELECT ticker, filing_date, generated_at
|
| 239 |
FROM brief_snapshots AS s
|
|
@@ -260,7 +279,7 @@ def list_snapshots(ticker: str) -> list[dict]:
|
|
| 260 |
if not DB_PATH.exists():
|
| 261 |
return []
|
| 262 |
init_db()
|
| 263 |
-
with
|
| 264 |
rows = conn.execute(
|
| 265 |
"""
|
| 266 |
SELECT snapshot_id, filing_date, data_as_of, generated_at,
|
|
@@ -302,7 +321,7 @@ def get_translation(ticker: str, language: str) -> Optional[dict]:
|
|
| 302 |
if not DB_PATH.exists():
|
| 303 |
return None
|
| 304 |
init_db()
|
| 305 |
-
with
|
| 306 |
row = conn.execute(
|
| 307 |
"SELECT brief_json FROM brief_translations WHERE ticker = ? AND language = ?",
|
| 308 |
(ticker.upper(), language),
|
|
@@ -324,7 +343,7 @@ def save_translation(ticker: str, language: str, brief_dict: dict) -> None:
|
|
| 324 |
"""Persist translated brief_dict for ticker/language, overwriting any previous translation."""
|
| 325 |
from datetime import datetime, timezone
|
| 326 |
init_db()
|
| 327 |
-
with
|
| 328 |
conn.execute(
|
| 329 |
"""
|
| 330 |
INSERT OR REPLACE INTO brief_translations
|
|
|
|
| 17 |
BRIEF_SCHEMA_VERSION = "brief.v2"
|
| 18 |
|
| 19 |
|
| 20 |
+
def _connect() -> sqlite3.Connection:
|
| 21 |
+
"""Open a connection tolerant of concurrent readers/writers.
|
| 22 |
+
|
| 23 |
+
Streamlit runs one script execution per visitor session; on a shared
|
| 24 |
+
deployment (HF Space), two sessions can hit this DB at the same moment
|
| 25 |
+
(one saving a just-generated brief while another loads the sidebar).
|
| 26 |
+
SQLite's default connect() has a near-zero busy timeout, so that
|
| 27 |
+
collision raises "database is locked" immediately — callers that swallow
|
| 28 |
+
exceptions then silently show an empty state instead of the brief that
|
| 29 |
+
was actually persisted. A busy_timeout lets SQLite retry instead of
|
| 30 |
+
failing instantly, and WAL mode lets readers proceed while a write is
|
| 31 |
+
in-flight.
|
| 32 |
+
"""
|
| 33 |
+
conn = sqlite3.connect(DB_PATH, timeout=10)
|
| 34 |
+
conn.execute("PRAGMA journal_mode=WAL")
|
| 35 |
+
conn.execute("PRAGMA busy_timeout=10000")
|
| 36 |
+
return conn
|
| 37 |
+
|
| 38 |
+
|
| 39 |
def init_db() -> None:
|
| 40 |
"""Create the briefs table if it doesn't exist. Safe to call multiple times."""
|
| 41 |
DB_PATH.parent.mkdir(parents=True, exist_ok=True)
|
| 42 |
+
with _connect() as conn:
|
| 43 |
conn.execute("""
|
| 44 |
CREATE TABLE IF NOT EXISTS briefs (
|
| 45 |
ticker TEXT PRIMARY KEY,
|
|
|
|
| 104 |
"\x1f".join((ticker, filing_date, generated_at, schema_version, language)).encode("utf-8")
|
| 105 |
).hexdigest()[:32]
|
| 106 |
payload = json.dumps(brief_dict)
|
| 107 |
+
with _connect() as conn:
|
| 108 |
conn.execute(
|
| 109 |
"""
|
| 110 |
INSERT OR IGNORE INTO brief_snapshots (
|
|
|
|
| 151 |
if not DB_PATH.exists():
|
| 152 |
return None
|
| 153 |
init_db()
|
| 154 |
+
with _connect() as conn:
|
| 155 |
clauses = ["ticker = ?"]
|
| 156 |
params: list[str] = [ticker.upper()]
|
| 157 |
if filing_date is not None:
|
|
|
|
| 225 |
if not DB_PATH.exists():
|
| 226 |
return []
|
| 227 |
init_db()
|
| 228 |
+
with _connect() as conn:
|
| 229 |
rows = conn.execute(
|
| 230 |
"SELECT ticker FROM briefs UNION SELECT ticker FROM brief_snapshots ORDER BY ticker ASC"
|
| 231 |
).fetchall()
|
|
|
|
| 237 |
init_db()
|
| 238 |
ticker = ticker.upper()
|
| 239 |
deleted = 0
|
| 240 |
+
with _connect() as conn:
|
| 241 |
for table in ("briefs", "brief_snapshots", "brief_translations"):
|
| 242 |
cursor = conn.execute(f"DELETE FROM {table} WHERE ticker = ?", (ticker,))
|
| 243 |
deleted += cursor.rowcount
|
|
|
|
| 252 |
if not DB_PATH.exists():
|
| 253 |
return []
|
| 254 |
init_db()
|
| 255 |
+
with _connect() as conn:
|
| 256 |
rows = conn.execute("""
|
| 257 |
SELECT ticker, filing_date, generated_at
|
| 258 |
FROM brief_snapshots AS s
|
|
|
|
| 279 |
if not DB_PATH.exists():
|
| 280 |
return []
|
| 281 |
init_db()
|
| 282 |
+
with _connect() as conn:
|
| 283 |
rows = conn.execute(
|
| 284 |
"""
|
| 285 |
SELECT snapshot_id, filing_date, data_as_of, generated_at,
|
|
|
|
| 321 |
if not DB_PATH.exists():
|
| 322 |
return None
|
| 323 |
init_db()
|
| 324 |
+
with _connect() as conn:
|
| 325 |
row = conn.execute(
|
| 326 |
"SELECT brief_json FROM brief_translations WHERE ticker = ? AND language = ?",
|
| 327 |
(ticker.upper(), language),
|
|
|
|
| 343 |
"""Persist translated brief_dict for ticker/language, overwriting any previous translation."""
|
| 344 |
from datetime import datetime, timezone
|
| 345 |
init_db()
|
| 346 |
+
with _connect() as conn:
|
| 347 |
conn.execute(
|
| 348 |
"""
|
| 349 |
INSERT OR REPLACE INTO brief_translations
|
|
@@ -8,23 +8,31 @@ Used by storage/vector_store.search to re-rank Chroma's top-k candidates.
|
|
| 8 |
"""
|
| 9 |
from __future__ import annotations
|
| 10 |
|
|
|
|
| 11 |
from typing import Optional
|
| 12 |
|
| 13 |
_MODEL_NAME = "BAAI/bge-reranker-base"
|
| 14 |
_model = None # type: ignore[var-annotated]
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
def _get_model():
|
| 18 |
"""Lazy-load the cross-encoder. Returns None on import or load failure."""
|
| 19 |
global _model
|
| 20 |
if _model is None:
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
return _model if _model is not False else None
|
| 29 |
|
| 30 |
|
|
@@ -56,11 +64,32 @@ def rerank(query: str, candidates: list[dict], top_k: int = 3) -> list[dict]:
|
|
| 56 |
|
| 57 |
|
| 58 |
def warmup() -> None:
|
| 59 |
-
"""Eagerly load the cross-encoder model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
_get_model()
|
| 61 |
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
def reset_for_test() -> None:
|
| 64 |
"""Reset the cached model — used by unit tests that monkeypatch the loader."""
|
| 65 |
-
global _model
|
| 66 |
_model = None
|
|
|
|
|
|
| 8 |
"""
|
| 9 |
from __future__ import annotations
|
| 10 |
|
| 11 |
+
import threading
|
| 12 |
from typing import Optional
|
| 13 |
|
| 14 |
_MODEL_NAME = "BAAI/bge-reranker-base"
|
| 15 |
_model = None # type: ignore[var-annotated]
|
| 16 |
|
| 17 |
+
# Guards _model against two threads loading it at once — the background warmup
|
| 18 |
+
# and a search that arrives before the warmup finished.
|
| 19 |
+
_load_lock = threading.Lock()
|
| 20 |
+
_warmup_thread: threading.Thread | None = None
|
| 21 |
+
|
| 22 |
|
| 23 |
def _get_model():
|
| 24 |
"""Lazy-load the cross-encoder. Returns None on import or load failure."""
|
| 25 |
global _model
|
| 26 |
if _model is None:
|
| 27 |
+
with _load_lock:
|
| 28 |
+
if _model is None: # re-check: another thread may have loaded it
|
| 29 |
+
try:
|
| 30 |
+
from sentence_transformers import CrossEncoder
|
| 31 |
+
_model = CrossEncoder(_MODEL_NAME)
|
| 32 |
+
except Exception as exc: # pragma: no cover — defensive, not testable
|
| 33 |
+
import sys
|
| 34 |
+
print(f"[reranker] failed to load {_MODEL_NAME}: {exc}", file=sys.stderr)
|
| 35 |
+
_model = False # sentinel: tried and failed
|
| 36 |
return _model if _model is not False else None
|
| 37 |
|
| 38 |
|
|
|
|
| 64 |
|
| 65 |
|
| 66 |
def warmup() -> None:
|
| 67 |
+
"""Eagerly load the cross-encoder model, blocking until it is resident.
|
| 68 |
+
|
| 69 |
+
Prefer :func:`warmup_async` from anything that renders a UI — importing
|
| 70 |
+
torch and sentence-transformers takes tens of seconds on a cold process,
|
| 71 |
+
and doing it inline means the user stares at an empty page for all of it.
|
| 72 |
+
"""
|
| 73 |
_get_model()
|
| 74 |
|
| 75 |
|
| 76 |
+
def warmup_async() -> None:
|
| 77 |
+
"""Start loading the cross-encoder on a background thread; return at once.
|
| 78 |
+
|
| 79 |
+
Idempotent per process. A search issued before the load completes simply
|
| 80 |
+
blocks on the same lock, so correctness never depends on the race.
|
| 81 |
+
"""
|
| 82 |
+
global _warmup_thread
|
| 83 |
+
if _model is not None or _warmup_thread is not None:
|
| 84 |
+
return
|
| 85 |
+
_warmup_thread = threading.Thread(
|
| 86 |
+
target=_get_model, name="reranker-warmup", daemon=True
|
| 87 |
+
)
|
| 88 |
+
_warmup_thread.start()
|
| 89 |
+
|
| 90 |
+
|
| 91 |
def reset_for_test() -> None:
|
| 92 |
"""Reset the cached model — used by unit tests that monkeypatch the loader."""
|
| 93 |
+
global _model, _warmup_thread
|
| 94 |
_model = None
|
| 95 |
+
_warmup_thread = None
|
|
@@ -3,28 +3,57 @@ from __future__ import annotations
|
|
| 3 |
import pytest
|
| 4 |
from unittest.mock import patch, MagicMock
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def test_ai_badge_default_label():
|
| 8 |
from dashboard.components import ai_badge
|
| 9 |
html = ai_badge()
|
| 10 |
assert "✦ AI Synthesis" in html
|
| 11 |
-
assert
|
| 12 |
-
assert
|
| 13 |
|
| 14 |
|
| 15 |
def test_ai_badge_custom_label():
|
| 16 |
from dashboard.components import ai_badge
|
| 17 |
html = ai_badge("AI")
|
| 18 |
assert "✦ AI" in html
|
| 19 |
-
assert
|
| 20 |
|
| 21 |
|
| 22 |
def test_interpretation_card_contains_badge_and_content():
|
| 23 |
from dashboard.components import interpretation_card
|
| 24 |
html = interpretation_card("What matters most", "<p>Some insight</p>")
|
| 25 |
assert "✦ AI Synthesis" in html
|
| 26 |
-
assert
|
| 27 |
-
# card background is
|
| 28 |
assert "What matters most" in html
|
| 29 |
assert "<p>Some insight</p>" in html
|
| 30 |
|
|
@@ -71,7 +100,7 @@ def test_signal_card_tension_variant():
|
|
| 71 |
assert "Deeper reading" in html
|
| 72 |
assert "Material" in html # priority label, not raw HIGH/MED/LOW
|
| 73 |
# mixed stance → amber accent, never bull green or bear red on the frame
|
| 74 |
-
assert
|
| 75 |
|
| 76 |
|
| 77 |
def test_signal_card_quality_variant():
|
|
@@ -93,7 +122,7 @@ def test_signal_card_quality_variant():
|
|
| 93 |
assert "▲" in html
|
| 94 |
assert "Positive" in html
|
| 95 |
assert "✦ AI · experimental" in html # quality assessments are experimental AI
|
| 96 |
-
assert
|
| 97 |
|
| 98 |
|
| 99 |
def test_signal_card_delta_variant_redline():
|
|
@@ -137,7 +166,7 @@ def test_signal_card_risk_new_badge():
|
|
| 137 |
|
| 138 |
assert "Geopolitical" in html
|
| 139 |
assert "NEW" in html
|
| 140 |
-
assert
|
| 141 |
|
| 142 |
|
| 143 |
# ── New helper tests ──────────────────────────────────────────────────────────
|
|
@@ -159,20 +188,20 @@ def test_importance_marker_levels():
|
|
| 159 |
|
| 160 |
high = importance_marker("HIGH")
|
| 161 |
assert "Critical" in high
|
| 162 |
-
assert
|
| 163 |
assert "●" in high
|
| 164 |
# monochrome only — no green or red signal colors
|
| 165 |
-
assert
|
| 166 |
-
assert
|
| 167 |
|
| 168 |
medium = importance_marker("MEDIUM")
|
| 169 |
assert "Important" in medium
|
| 170 |
-
assert
|
| 171 |
assert "●" in medium
|
| 172 |
|
| 173 |
low = importance_marker("LOW")
|
| 174 |
assert "Context" in low
|
| 175 |
-
assert
|
| 176 |
assert "●" in low
|
| 177 |
|
| 178 |
# Unknown / empty returns empty string
|
|
|
|
| 3 |
import pytest
|
| 4 |
from unittest.mock import patch, MagicMock
|
| 5 |
|
| 6 |
+
from dashboard.theme import (
|
| 7 |
+
AI_COLOR, AI_BADGE_BG, PURPLE, AMBER, GREEN, RED,
|
| 8 |
+
IMPACT_HIGH_BG, IMPACT_MED_BG, IMPACT_LOW_TEXT,
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@pytest.mark.parametrize(
|
| 13 |
+
("text", "expected"),
|
| 14 |
+
[
|
| 15 |
+
("$25.1B YTD vs. Q2's $37.0B YTD", r"\$25.1B YTD vs. Q2's \$37.0B YTD"),
|
| 16 |
+
("$ 25.1B", r"\$ 25.1B"),
|
| 17 |
+
("$AAPL vs $MSFT", r"\$AAPL vs \$MSFT"),
|
| 18 |
+
("err: `ValueError: $x` at $9", r"err: `ValueError: $x` at \$9"),
|
| 19 |
+
("``foo ` bar $25``", "``foo ` bar $25``"),
|
| 20 |
+
("``a`b $7``", "``a`b $7``"),
|
| 21 |
+
("`a``b`", "`a``b`"),
|
| 22 |
+
("`oops $5", r"`oops \$5"),
|
| 23 |
+
(r"\$already", r"\$already"),
|
| 24 |
+
("no dollars here", "no dollars here"),
|
| 25 |
+
("", ""),
|
| 26 |
+
],
|
| 27 |
+
)
|
| 28 |
+
def test_escape_dollars(text: str, expected: str):
|
| 29 |
+
from dashboard.components import escape_dollars
|
| 30 |
+
|
| 31 |
+
escaped = escape_dollars(text)
|
| 32 |
+
assert escaped == expected
|
| 33 |
+
assert escape_dollars(escaped) == escaped
|
| 34 |
+
|
| 35 |
|
| 36 |
def test_ai_badge_default_label():
|
| 37 |
from dashboard.components import ai_badge
|
| 38 |
html = ai_badge()
|
| 39 |
assert "✦ AI Synthesis" in html
|
| 40 |
+
assert AI_COLOR in html
|
| 41 |
+
assert AI_BADGE_BG in html
|
| 42 |
|
| 43 |
|
| 44 |
def test_ai_badge_custom_label():
|
| 45 |
from dashboard.components import ai_badge
|
| 46 |
html = ai_badge("AI")
|
| 47 |
assert "✦ AI" in html
|
| 48 |
+
assert AI_COLOR in html
|
| 49 |
|
| 50 |
|
| 51 |
def test_interpretation_card_contains_badge_and_content():
|
| 52 |
from dashboard.components import interpretation_card
|
| 53 |
html = interpretation_card("What matters most", "<p>Some insight</p>")
|
| 54 |
assert "✦ AI Synthesis" in html
|
| 55 |
+
assert PURPLE in html # purple border (PURPLE token value)
|
| 56 |
+
# card background is the standard surface, not the lavender AI_BG tint
|
| 57 |
assert "What matters most" in html
|
| 58 |
assert "<p>Some insight</p>" in html
|
| 59 |
|
|
|
|
| 100 |
assert "Deeper reading" in html
|
| 101 |
assert "Material" in html # priority label, not raw HIGH/MED/LOW
|
| 102 |
# mixed stance → amber accent, never bull green or bear red on the frame
|
| 103 |
+
assert AMBER in html
|
| 104 |
|
| 105 |
|
| 106 |
def test_signal_card_quality_variant():
|
|
|
|
| 122 |
assert "▲" in html
|
| 123 |
assert "Positive" in html
|
| 124 |
assert "✦ AI · experimental" in html # quality assessments are experimental AI
|
| 125 |
+
assert GREEN in html # bull stance → green accent
|
| 126 |
|
| 127 |
|
| 128 |
def test_signal_card_delta_variant_redline():
|
|
|
|
| 166 |
|
| 167 |
assert "Geopolitical" in html
|
| 168 |
assert "NEW" in html
|
| 169 |
+
assert RED in html # bear stance → red accent
|
| 170 |
|
| 171 |
|
| 172 |
# ── New helper tests ──────────────────────────────────────────────────────────
|
|
|
|
| 188 |
|
| 189 |
high = importance_marker("HIGH")
|
| 190 |
assert "Critical" in high
|
| 191 |
+
assert IMPACT_HIGH_BG in high
|
| 192 |
assert "●" in high
|
| 193 |
# monochrome only — no green or red signal colors
|
| 194 |
+
assert GREEN not in high
|
| 195 |
+
assert RED not in high
|
| 196 |
|
| 197 |
medium = importance_marker("MEDIUM")
|
| 198 |
assert "Important" in medium
|
| 199 |
+
assert IMPACT_MED_BG in medium
|
| 200 |
assert "●" in medium
|
| 201 |
|
| 202 |
low = importance_marker("LOW")
|
| 203 |
assert "Context" in low
|
| 204 |
+
assert IMPACT_LOW_TEXT in low
|
| 205 |
assert "●" in low
|
| 206 |
|
| 207 |
# Unknown / empty returns empty string
|
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import deploy_check
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def test_parse_data_status_detects_dirty_data_paths():
|
| 5 |
+
porcelain = (
|
| 6 |
+
" M data/sections.db\n"
|
| 7 |
+
"M data/metrics.db\n"
|
| 8 |
+
"?? data/chroma/new-index.bin\n"
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
assert deploy_check.parse_data_status(porcelain) == [
|
| 12 |
+
"data/sections.db",
|
| 13 |
+
"data/metrics.db",
|
| 14 |
+
"data/chroma/new-index.bin",
|
| 15 |
+
]
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def test_collect_coverage_flags_unattempted_required_sections(monkeypatch):
|
| 19 |
+
coverage_by_ticker = {
|
| 20 |
+
"AAPL": {
|
| 21 |
+
"status": "PARTIAL",
|
| 22 |
+
"business_sections": 0,
|
| 23 |
+
"business_sections_attempted": 0,
|
| 24 |
+
"segments_geography_sections": 0,
|
| 25 |
+
"segments_geography_sections_attempted": 0,
|
| 26 |
+
"recent_transcripts": 2,
|
| 27 |
+
},
|
| 28 |
+
"NVDA": {
|
| 29 |
+
"status": "COMPLETE",
|
| 30 |
+
"business_sections": 1,
|
| 31 |
+
"business_sections_attempted": 1,
|
| 32 |
+
"segments_geography_sections": 1,
|
| 33 |
+
"segments_geography_sections_attempted": 1,
|
| 34 |
+
"recent_transcripts": 4,
|
| 35 |
+
},
|
| 36 |
+
}
|
| 37 |
+
monkeypatch.setattr(
|
| 38 |
+
deploy_check,
|
| 39 |
+
"profile_source_coverage",
|
| 40 |
+
lambda ticker: coverage_by_ticker[ticker],
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
rows, incomplete = deploy_check.collect_coverage(["AAPL", "NVDA"])
|
| 44 |
+
|
| 45 |
+
assert incomplete == ["AAPL"]
|
| 46 |
+
assert rows == [
|
| 47 |
+
{
|
| 48 |
+
"ticker": "AAPL",
|
| 49 |
+
"status": "PARTIAL",
|
| 50 |
+
"business_sections": 0,
|
| 51 |
+
"segments_geography_sections": 0,
|
| 52 |
+
"recent_transcripts": 2,
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"ticker": "NVDA",
|
| 56 |
+
"status": "COMPLETE",
|
| 57 |
+
"business_sections": 1,
|
| 58 |
+
"segments_geography_sections": 1,
|
| 59 |
+
"recent_transcripts": 4,
|
| 60 |
+
},
|
| 61 |
+
]
|