import os _db_path = "data/experiments.db" if not os.path.exists(_db_path) or os.path.getsize(_db_path) < 1000: os.makedirs("data", exist_ok=True) from huggingface_hub import hf_hub_download import shutil _dl = hf_hub_download(repo_id="a-lems/db", filename="experiments.db", repo_type="dataset", local_dir="/tmp") shutil.copy(_dl, _db_path) """ A-LEMS Energy Measurement Dashboard ===================================== Entry point — 3-layer navigation dispatcher. nav_section=None → Overview (default) nav_section set, nav_page=None → Section landing card grid nav_section set, nav_page set → Actual page """ import sys import importlib from pathlib import Path import streamlit as st import pandas as pd _ROOT = Path(__file__).parent if str(_ROOT) not in sys.path: sys.path.insert(0, str(_ROOT)) st.set_page_config( page_title="A-LEMS · Energy Measurement", page_icon="⚡", layout="wide", initial_sidebar_state="expanded", ) st.markdown(""" """, unsafe_allow_html=True) from gui.sidebar import render_sidebar from gui.db import load_overview, load_runs, load_tax from gui.config import PAGES_BLOCKED, PAGE_TO_SECTION, SECTION_PAGES, PAGE_META, SECTION_ACCENTS # ── Shared data ─────────────────────────────────────────────────────────────── ov = load_overview() runs = load_runs() tax = load_tax() lin = runs[runs.workflow_type == "linear"] if not runs.empty else pd.DataFrame() age = runs[runs.workflow_type == "agentic"] if not runs.empty else pd.DataFrame() avg_lin_j = lin.energy_j.mean() if not lin.empty and "energy_j" in lin.columns else 0.0 avg_age_j = age.energy_j.mean() if not age.empty and "energy_j" in age.columns else 0.0 tax_mult = avg_age_j / avg_lin_j if avg_lin_j > 0 else 0.0 plan_ms = float(ov.get("avg_planning_ms", 0) or 0) exec_ms = float(ov.get("avg_execution_ms", 0) or 0) synth_ms = float(ov.get("avg_synthesis_ms", 0) or 0) phase_total = plan_ms + exec_ms + synth_ms or 1 CTX = dict( ov=ov, runs=runs, tax=tax, lin=lin, age=age, avg_lin_j=avg_lin_j, avg_age_j=avg_age_j, tax_mult=tax_mult, plan_ms=plan_ms, exec_ms=exec_ms, synth_ms=synth_ms, plan_pct=plan_ms / phase_total * 100, exec_pct=exec_ms / phase_total * 100, synth_pct=synth_ms / phase_total * 100, ) # ── Page modules ────────────────────────────────────────────────────────────── _PAGE_MODULES = { "overview": "gui.pages.overview", "execute": "gui.pages.execute", "experiments": "gui.pages.experiments", "settings": "gui.pages.settings", "explorer": "gui.pages.explorer", "energy": "gui.pages.energy", "domains": "gui.pages.domains", "sustainability": "gui.pages.sustainability", "tax": "gui.pages.tax", "agentic_linear": "gui.pages.agentic_linear", "query_analysis": "gui.pages.query_analysis", "cpu": "gui.pages.cpu", "scheduler": "gui.pages.scheduler", "anomalies": "gui.pages.anomalies", "research_insights": "gui.pages.research_insights", "live": "gui.pages.live", "schema_docs": "gui.pages.schema_docs", "sql_query": "gui.pages.sql_query", "designer": "gui.pages.designer", "sessions": "gui.pages.sessions", "session_analysis": "gui.pages.session_analysis", "models": "gui.pages.models", # Data Quality # Energy & Silicon "thermal": "gui.pages.thermal", "baseline": "gui.pages.baseline", # Agentic Intelligence "phase_drilldown": "gui.pages.phase_drilldown", # Sessions & Runs "run_drilldown": "gui.pages.run_drilldown", # Research & Insights "efficiency": "gui.pages.efficiency", "ml_features": "gui.pages.ml_features_page", "hypotheses": "gui.pages.hypotheses", # Environment "carbon_country": "gui.pages.carbon_country", "water_methane": "gui.pages.water_methane", # Developer Tools "env_config": "gui.pages.env_config", "llm_log": "gui.pages.llm_log", "ml_export": "gui.pages.ml_export", # Silicon Lab "hw_registry": "gui.pages.hw_registry", "silicon_compare": "gui.pages.silicon_compare", "silicon_journey": "gui.pages.silicon_journey", # Data Movement "data_cache": "gui.pages.data_cache", "data_tokens": "gui.pages.data_tokens", "data_network": "gui.pages.data_network", "data_swap": "gui.pages.data_swap", "data_interrupts": "gui.pages.data_interrupts", # Data Quality "dq_validity": "gui.pages.dq_validity", "dq_coverage": "gui.pages.dq_coverage", "dq_sufficiency": "gui.pages.dq_sufficiency", "dq_integrity": "gui.pages.dq_integrity", "dq_schema": "gui.pages.dq_schema", } # ── Sidebar ─────────────────────────────────────────────────────────────────── render_sidebar() nav_section = st.session_state.get("nav_section") nav_page = st.session_state.get("nav_page") nav_last = st.session_state.get("nav_last", {}) # ── Helpers ─────────────────────────────────────────────────────────────────── def _render_stub(page_id: str, section: str) -> None: meta = PAGE_META.get(page_id, {}) label = meta.get("label", page_id) icon = meta.get("icon", "◈") desc = meta.get("desc", "") accent = SECTION_ACCENTS.get(section, "#3b82f6") st.markdown( f"
" f"
{icon}
" f"
{label}
" f"
{desc}
" f"
COMING SOON
" f"
", unsafe_allow_html=True) # ── 3-layer dispatcher ──────────────────────────────────────────────────────── # Layer 1 — No section → Overview if nav_section is None: importlib.import_module("gui.pages.overview").render(CTX) # Layer 2 — Section, no page → Section landing elif nav_page is None: from gui.components.section_landing import render as _landing _landing(nav_section, last_page=nav_last.get(nav_section)) # Layer 3 — Section + page → Page else: # Breadcrumb (not on overview) if nav_page != "overview": from gui.components.breadcrumb import render as _bc _bc(nav_page) # Update last-visited memory if nav_section: st.session_state.setdefault("nav_last", {})[nav_section] = nav_page # Blocked if nav_page in PAGES_BLOCKED: reason = PAGES_BLOCKED[nav_page] st.markdown( f"
" f"
" f"⊘ Data gap — page blocked
" f"
{reason}
" f"
", unsafe_allow_html=True) # Stub elif nav_page not in _PAGE_MODULES: _render_stub(nav_page, nav_section or "") # Real page else: importlib.import_module(_PAGE_MODULES[nav_page]).render(CTX)