Spaces:
Sleeping
Sleeping
[FIX] Fix cap value precision: show 4 decimal places in absolute cap inputs and displays across tab2, tab4, and data_utils
Browse files- tabs/tab2_constraints.py +3 -3
- tabs/tab4_optimization.py +2 -2
- utils/data_utils.py +1 -1
tabs/tab2_constraints.py
CHANGED
|
@@ -324,9 +324,9 @@ def render_method(m, cols, i, cost_sliders_norm):
|
|
| 324 |
f"Max cap ({CO2_UNIT}/yr)",
|
| 325 |
min_value=0.0,
|
| 326 |
value=None,
|
| 327 |
-
format="%.
|
| 328 |
key=f"manual_{m}",
|
| 329 |
-
placeholder="0.
|
| 330 |
on_change=_make_manual_cb(m),
|
| 331 |
)
|
| 332 |
|
|
@@ -378,7 +378,7 @@ def build_summary_df():
|
|
| 378 |
if c["cap_type"] == "percent":
|
| 379 |
rows[display_m] = {"Cap value": f"{int(c['cap_value'])}%"}
|
| 380 |
elif c["cap_type"] == "absolute":
|
| 381 |
-
rows[display_m] = {"Cap value": f"{c['cap_value']:,
|
| 382 |
else:
|
| 383 |
rows[display_m] = {"Cap value": f"⚠️ Invalid type ({c['cap_type']!r}) — fix in Tab 2"}
|
| 384 |
return pd.DataFrame.from_dict(rows, orient="index") if rows else None
|
|
|
|
| 324 |
f"Max cap ({CO2_UNIT}/yr)",
|
| 325 |
min_value=0.0,
|
| 326 |
value=None,
|
| 327 |
+
format="%.4f",
|
| 328 |
key=f"manual_{m}",
|
| 329 |
+
placeholder="0.0000",
|
| 330 |
on_change=_make_manual_cb(m),
|
| 331 |
)
|
| 332 |
|
|
|
|
| 378 |
if c["cap_type"] == "percent":
|
| 379 |
rows[display_m] = {"Cap value": f"{int(c['cap_value'])}%"}
|
| 380 |
elif c["cap_type"] == "absolute":
|
| 381 |
+
rows[display_m] = {"Cap value": f"{c['cap_value']:,g} {CO2_UNIT}/yr"}
|
| 382 |
else:
|
| 383 |
rows[display_m] = {"Cap value": f"⚠️ Invalid type ({c['cap_type']!r}) — fix in Tab 2"}
|
| 384 |
return pd.DataFrame.from_dict(rows, orient="index") if rows else None
|
tabs/tab4_optimization.py
CHANGED
|
@@ -983,7 +983,7 @@ def export_scenario():
|
|
| 983 |
alloc_df["Total share (%)"] = (alloc_df[f"{CO2_UNIT} removed"] / alloc_total * 100).round(2)
|
| 984 |
method_constraints_export = scenario.get("method_constraints", {})
|
| 985 |
alloc_df["Cap constraint"] = pd.Series({
|
| 986 |
-
m: (f"{c['cap_value']:,
|
| 987 |
else f"{int(c.get('cap_value', 100))}% of potential")
|
| 988 |
for m, c in method_constraints_export.items()
|
| 989 |
})
|
|
@@ -1410,7 +1410,7 @@ def render_tab():
|
|
| 1410 |
)
|
| 1411 |
df_display = df_result.copy()
|
| 1412 |
df_display[f"{CO2_UNIT} removed"] = df_display[f"{CO2_UNIT} removed"].map(
|
| 1413 |
-
lambda x: f"{x:,
|
| 1414 |
)
|
| 1415 |
|
| 1416 |
with tab_results:
|
|
|
|
| 983 |
alloc_df["Total share (%)"] = (alloc_df[f"{CO2_UNIT} removed"] / alloc_total * 100).round(2)
|
| 984 |
method_constraints_export = scenario.get("method_constraints", {})
|
| 985 |
alloc_df["Cap constraint"] = pd.Series({
|
| 986 |
+
m: (f"{c['cap_value']:,g} {CO2_UNIT}/yr" if c.get("cap_type") == "absolute"
|
| 987 |
else f"{int(c.get('cap_value', 100))}% of potential")
|
| 988 |
for m, c in method_constraints_export.items()
|
| 989 |
})
|
|
|
|
| 1410 |
)
|
| 1411 |
df_display = df_result.copy()
|
| 1412 |
df_display[f"{CO2_UNIT} removed"] = df_display[f"{CO2_UNIT} removed"].map(
|
| 1413 |
+
lambda x: f"{x:,g}" if pd.notna(x) else x
|
| 1414 |
)
|
| 1415 |
|
| 1416 |
with tab_results:
|
utils/data_utils.py
CHANGED
|
@@ -596,7 +596,7 @@ def build_results_df(allocations: dict, method_constraints: dict | None = None)
|
|
| 596 |
for m in df.index:
|
| 597 |
c = method_constraints.get(m, {})
|
| 598 |
if c.get("cap_type") == "absolute":
|
| 599 |
-
caps[m] = f"{c['cap_value']:,
|
| 600 |
elif c.get("cap_type") == "percent":
|
| 601 |
caps[m] = f"{int(c.get('cap_value', 100))}% of potential"
|
| 602 |
else:
|
|
|
|
| 596 |
for m in df.index:
|
| 597 |
c = method_constraints.get(m, {})
|
| 598 |
if c.get("cap_type") == "absolute":
|
| 599 |
+
caps[m] = f"{c['cap_value']:,g} {CO2_UNIT}/yr"
|
| 600 |
elif c.get("cap_type") == "percent":
|
| 601 |
caps[m] = f"{int(c.get('cap_value', 100))}% of potential"
|
| 602 |
else:
|