Spaces:
Sleeping
Sleeping
[FIX] Tab3: adapt zero-cap warning based on resource type
Browse files- tabs/tab3_coefficients.py +38 -17
tabs/tab3_coefficients.py
CHANGED
|
@@ -143,7 +143,7 @@ def build_custom_slider_index(cost_sliders_norm, custom_resources):
|
|
| 143 |
return custom_sliders_by_method, custom_resource_names, custom_resource_to_sub_group, custom_resource_to_group
|
| 144 |
|
| 145 |
|
| 146 |
-
def render_standard_resource_row(method, r, conf, display_label, enabled_methods):
|
| 147 |
"""Render the slider row for a single standard resource coefficient.
|
| 148 |
|
| 149 |
Handles the secondary-resource toggle, fixed-value display, and the
|
|
@@ -156,6 +156,7 @@ def render_standard_resource_row(method, r, conf, display_label, enabled_methods
|
|
| 156 |
conf (dict): {min, median, max} for this (method, resource) pair.
|
| 157 |
display_label (str): human-readable resource label with unit.
|
| 158 |
enabled_methods (dict): {resource: {method: bool}} from session state.
|
|
|
|
| 159 |
|
| 160 |
Returns:
|
| 161 |
None
|
|
@@ -189,11 +190,17 @@ def render_standard_resource_row(method, r, conf, display_label, enabled_methods
|
|
| 189 |
)
|
| 190 |
st.session_state.costs[method][r] = conf["median"]
|
| 191 |
if st.session_state.get("resource_caps", {}).get(r, 0) <= 0:
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
return
|
| 198 |
|
| 199 |
if slider_key not in st.session_state:
|
|
@@ -201,11 +208,17 @@ def render_standard_resource_row(method, r, conf, display_label, enabled_methods
|
|
| 201 |
if manual_key not in st.session_state:
|
| 202 |
st.session_state[manual_key] = st.session_state[slider_key]
|
| 203 |
if st.session_state.get("resource_caps", {}).get(r, 0) <= 0:
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
|
| 210 |
col1, col2 = st.columns([3, 1])
|
| 211 |
with col1:
|
|
@@ -270,11 +283,17 @@ def render_custom_resource_row(method, r, conf, enabled_methods, custom_resource
|
|
| 270 |
|
| 271 |
batch_amount = next((float(b.get("amount", 0)) for b in custom_resources if b["name"] == r), 0.0)
|
| 272 |
if batch_amount <= 0:
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
|
| 279 |
col1, col2 = st.columns([3, 1])
|
| 280 |
with col1:
|
|
@@ -335,10 +354,12 @@ def panel_method_editor(
|
|
| 335 |
|
| 336 |
st.markdown(f'<p class="crra-group-name">{group_name}</p>', unsafe_allow_html=True)
|
| 337 |
|
|
|
|
| 338 |
for r in used:
|
| 339 |
conf = method_sliders[r]
|
| 340 |
render_standard_resource_row(
|
| 341 |
-
method, r, conf, resource_display.get(r, r), enabled_methods
|
|
|
|
| 342 |
)
|
| 343 |
|
| 344 |
for r in custom_in_group:
|
|
|
|
| 143 |
return custom_sliders_by_method, custom_resource_names, custom_resource_to_sub_group, custom_resource_to_group
|
| 144 |
|
| 145 |
|
| 146 |
+
def render_standard_resource_row(method, r, conf, display_label, enabled_methods, has_custom_batch=False):
|
| 147 |
"""Render the slider row for a single standard resource coefficient.
|
| 148 |
|
| 149 |
Handles the secondary-resource toggle, fixed-value display, and the
|
|
|
|
| 156 |
conf (dict): {min, median, max} for this (method, resource) pair.
|
| 157 |
display_label (str): human-readable resource label with unit.
|
| 158 |
enabled_methods (dict): {resource: {method: bool}} from session state.
|
| 159 |
+
has_custom_batch (bool): True if a custom batch derived from r exists.
|
| 160 |
|
| 161 |
Returns:
|
| 162 |
None
|
|
|
|
| 190 |
)
|
| 191 |
st.session_state.costs[method][r] = conf["median"]
|
| 192 |
if st.session_state.get("resource_caps", {}).get(r, 0) <= 0:
|
| 193 |
+
if has_custom_batch:
|
| 194 |
+
st.info(
|
| 195 |
+
f"No available quantity set for **{r}** in Resource Inputs tab.",
|
| 196 |
+
icon=":material/info:",
|
| 197 |
+
)
|
| 198 |
+
else:
|
| 199 |
+
st.info(
|
| 200 |
+
f"No available quantity set for **{r}** in Resource Inputs tab: "
|
| 201 |
+
f"**{method}** won't be used in the optimization.",
|
| 202 |
+
icon=":material/info:",
|
| 203 |
+
)
|
| 204 |
return
|
| 205 |
|
| 206 |
if slider_key not in st.session_state:
|
|
|
|
| 208 |
if manual_key not in st.session_state:
|
| 209 |
st.session_state[manual_key] = st.session_state[slider_key]
|
| 210 |
if st.session_state.get("resource_caps", {}).get(r, 0) <= 0:
|
| 211 |
+
if has_custom_batch:
|
| 212 |
+
st.info(
|
| 213 |
+
f"No available quantity set for **{r}** in Resource Inputs tab.",
|
| 214 |
+
icon=":material/info:",
|
| 215 |
+
)
|
| 216 |
+
else:
|
| 217 |
+
st.info(
|
| 218 |
+
f"No available quantity set for **{r}** in Resource Inputs tab: "
|
| 219 |
+
f"**{method}** won't be used in the optimization.",
|
| 220 |
+
icon=":material/info:",
|
| 221 |
+
)
|
| 222 |
|
| 223 |
col1, col2 = st.columns([3, 1])
|
| 224 |
with col1:
|
|
|
|
| 283 |
|
| 284 |
batch_amount = next((float(b.get("amount", 0)) for b in custom_resources if b["name"] == r), 0.0)
|
| 285 |
if batch_amount <= 0:
|
| 286 |
+
if is_sec:
|
| 287 |
+
st.info(
|
| 288 |
+
f"No available quantity set for **{r}** in Resource Inputs.",
|
| 289 |
+
icon=":material/info:",
|
| 290 |
+
)
|
| 291 |
+
else:
|
| 292 |
+
st.info(
|
| 293 |
+
f"No available quantity set for **{r}** in Resource Inputs — "
|
| 294 |
+
"this method won't be used in the optimization.",
|
| 295 |
+
icon=":material/info:",
|
| 296 |
+
)
|
| 297 |
|
| 298 |
col1, col2 = st.columns([3, 1])
|
| 299 |
with col1:
|
|
|
|
| 354 |
|
| 355 |
st.markdown(f'<p class="crra-group-name">{group_name}</p>', unsafe_allow_html=True)
|
| 356 |
|
| 357 |
+
resources_with_batches = set(custom_resource_to_sub_group.values())
|
| 358 |
for r in used:
|
| 359 |
conf = method_sliders[r]
|
| 360 |
render_standard_resource_row(
|
| 361 |
+
method, r, conf, resource_display.get(r, r), enabled_methods,
|
| 362 |
+
has_custom_batch=(r in resources_with_batches),
|
| 363 |
)
|
| 364 |
|
| 365 |
for r in custom_in_group:
|