File size: 2,377 Bytes
b555842
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
gui/pages/schema_docs.py  —  📋  Schema & Docs
Render function: render(ctx)
ctx keys: ov, runs, tax, lin, age, avg_lin_j, avg_age_j, tax_mult,
          plan_ms, exec_ms, synth_ms, plan_pct, exec_pct, synth_pct
"""
import subprocess
import streamlit as st
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
from plotly.subplots import make_subplots

from gui.config  import PROJECT_ROOT, DB_PATH, LIVE_API, WF_COLORS, PL
from gui.db      import q, q_safe, q1
from gui.helpers import fl, _human_energy, _human_water, _human_carbon, _gauge_html, _bar_gauge_html

try:
    import requests as _req
    _REQUESTS_OK = True
except ImportError:
    _REQUESTS_OK = False
    class _req:
        @staticmethod
        def get(*a, **kw): raise RuntimeError("requests not installed")
try:
    import yaml as _yaml
    _YAML_OK = True
except ImportError:
    _YAML_OK = False


def render(ctx: dict):
    ov        = ctx["ov"]
    runs      = ctx["runs"]
    tax       = ctx["tax"]
    avg_lin_j = ctx["avg_lin_j"]
    avg_age_j = ctx["avg_age_j"]
    tax_mult  = ctx["tax_mult"]
    plan_ms   = ctx["plan_ms"]
    exec_ms   = ctx["exec_ms"]
    synth_ms  = ctx["synth_ms"]
    plan_pct  = ctx["plan_pct"]
    exec_pct  = ctx["exec_pct"]
    synth_pct = ctx["synth_pct"]
    lin       = ctx["lin"]
    age       = ctx["age"]

    st.title("📋 Schema & Docs")
    st.caption("Quick reference — redirect to Research Insights → Schema tab for full detail")
    st.info("Full interactive schema is in **🔬 Research Insights → Schema & Data Model** tab.")
    st.markdown("### DB tables at a glance")
    _db_tbls, _ = q_safe("""
        SELECT name FROM sqlite_master WHERE type='table' ORDER BY name
    """)
    if not _db_tbls.empty:
        for _tbl in _db_tbls.name.tolist():
            _cnt = q1(f"SELECT COUNT(*) AS n FROM {_tbl}").get("n", 0)
            _cols_df, _ = q_safe(f"PRAGMA table_info({_tbl})")
            if not _cols_df.empty:
                _col_names = " · ".join(_cols_df["name"].tolist()[:10])
                with st.expander(f"**{_tbl}** — {_cnt:,} rows"):
                    st.caption(_col_names + (" …" if len(_cols_df) > 10 else ""))
                    st.dataframe(_cols_df[["cid","name","type","notnull","dflt_value","pk"]],
                                 use_container_width=True, hide_index=True)