from __future__ import annotations from typing import Any import streamlit.components.v1 as components def _fmt_odds(value: Any) -> str: if value is None: return "—" try: iv = int(value) return f"+{iv}" if iv > 0 else str(iv) except Exception: return str(value) def _fmt_edge(value: Any) -> str: if value is None: return "" try: edge = float(value) except Exception: return str(value) pct = edge * 100 if pct >= 5: color = "#22c55e" elif pct >= 2: color = "#84cc16" elif pct >= 0: color = "#eab308" elif pct >= -3: color = "#f97316" else: color = "#ef4444" return f'{pct:.1f}%' def render_upcoming_edge_strip(rows: list[dict[str, Any]]) -> None: if not rows: return body_rows = [] for row in rows: ev90 = row.get("ev90") ev90_text = f" | EV90 {float(ev90):.1f}" if ev90 is not None else "" body_rows.append( f"""
{row.get("slot", "")}: {row.get("batter_name", "")}{ev90_text}
{_fmt_odds(row.get("fair_hr_odds"))}
{_fmt_odds(row.get("book_hr_odds"))}
{_fmt_edge(row.get("hr_edge"))}
""" ) html = f"""
UPCOMING BATTER HR EDGES • EV90 SIM MODEL V3
BATTER
FAIR
BOOK
EDGE
{''.join(body_rows)}
""" height = 88 + (len(rows) * 30) components.html(html, height=height, scrolling=False)