feat: add setup notebook and update env example for Athena
This commit is contained in:
@@ -27,9 +27,14 @@ def render(client: TEIClient, tool: dict) -> None:
|
||||
st.error(f"Athena API error: {e.detail}")
|
||||
return
|
||||
|
||||
npv = float(summary.get("npv") or 0)
|
||||
roi = float(summary.get("roi") or summary.get("roi_pct") or 0)
|
||||
payback = summary.get("payback_months")
|
||||
npv = float(summary.get("net_present_value") or summary.get("npv") or 0)
|
||||
roi = float(
|
||||
summary.get("roi_percentage")
|
||||
or summary.get("roi")
|
||||
or summary.get("roi_pct")
|
||||
or 0
|
||||
)
|
||||
payback = summary.get("payback_period_months", summary.get("payback_months"))
|
||||
bpv = float(summary.get("total_benefits_pv") or 0)
|
||||
cpv = float(summary.get("total_costs_pv") or 0)
|
||||
|
||||
@@ -45,7 +50,16 @@ def render(client: TEIClient, tool: dict) -> None:
|
||||
|
||||
st.divider()
|
||||
|
||||
# Build the yearly breakdown from the documented per-year summary keys
|
||||
# (benefits_year_N / costs_year_N) when no pre-built breakdown exists.
|
||||
yb = summary.get("yearly_breakdown") or []
|
||||
if not yb:
|
||||
n = 1
|
||||
while f"benefits_year_{n}" in summary or f"costs_year_{n}" in summary:
|
||||
b = float(summary.get(f"benefits_year_{n}") or 0)
|
||||
c = float(summary.get(f"costs_year_{n}") or 0)
|
||||
yb.append({"year": n, "benefits": b, "costs": c, "net": b - c})
|
||||
n += 1
|
||||
initial = float(summary.get("initial_costs") or 0)
|
||||
if yb:
|
||||
charts.cashflow(yb, initial_cost=initial)
|
||||
|
||||
@@ -17,11 +17,24 @@ def _diff_rows(a: dict[str, dict], b: dict[str, dict]) -> list[dict]:
|
||||
"""Return one row per field with side-by-side year values."""
|
||||
keys = sorted(set(a.keys()) | set(b.keys()))
|
||||
rows: list[dict] = []
|
||||
def _years_of(v: dict) -> dict:
|
||||
"""Accept both friendly (year_values) and wire (nested years) shapes."""
|
||||
if isinstance(v.get("year_values"), dict):
|
||||
return {str(k): val for k, val in v["year_values"].items()}
|
||||
if isinstance(v.get("years"), dict):
|
||||
return {
|
||||
str(k): (cell or {}).get("value")
|
||||
for k, cell in v["years"].items()
|
||||
}
|
||||
if v.get("value") is not None:
|
||||
return {"1": v["value"]}
|
||||
return {}
|
||||
|
||||
for k in keys:
|
||||
av = a.get(k, {}) or {}
|
||||
bv = b.get(k, {}) or {}
|
||||
ay = av.get("year_values") or {}
|
||||
by = bv.get("year_values") or {}
|
||||
ay = _years_of(av)
|
||||
by = _years_of(bv)
|
||||
years = sorted(set(ay.keys()) | set(by.keys()), key=lambda x: int(x))
|
||||
for y in years:
|
||||
a_val = float(ay.get(y) or 0)
|
||||
@@ -79,8 +92,13 @@ def render(client: TEIClient, tool: dict) -> None:
|
||||
{
|
||||
"Version": v.get("version_number"),
|
||||
"Date": v.get("created_at") or v.get("date"),
|
||||
"NPV": float(snap.get("npv") or 0),
|
||||
"ROI %": float(snap.get("roi") or snap.get("roi_pct") or 0),
|
||||
"NPV": float(snap.get("net_present_value") or snap.get("npv") or 0),
|
||||
"ROI %": float(
|
||||
snap.get("roi_percentage")
|
||||
or snap.get("roi")
|
||||
or snap.get("roi_pct")
|
||||
or 0
|
||||
),
|
||||
"Note": v.get("note", ""),
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user