CarlyneB commited on
Commit
d8dcaa3
·
1 Parent(s): 6b18587

[FIX] tab3: add early return for zero-cap resources, simplify availability messages, remove unused has_custom_batch param

Browse files
Files changed (1) hide show
  1. tabs/tab3_coefficients.py +25 -38
tabs/tab3_coefficients.py CHANGED
@@ -5,7 +5,7 @@ from config.config import (method_groups, method_order, resource_groups,
5
  resource_order, secondary_resources, resource_unit_map, CO2_UNIT,
6
  hidden_resource_names)
7
  from utils.ui_helpers import format_efficiency_summary, show_bar
8
- from utils.data_utils import (strip_unit_suffix, get_resource_to_group, normalize_costs,
9
  get_slider_params, is_method_enabled, is_custom_secondary)
10
 
11
 
@@ -90,7 +90,7 @@ def build_custom_slider_index(cost_sliders_norm, custom_resources):
90
  return custom_sliders_by_method, custom_resource_names, custom_resource_to_sub_group, custom_resource_to_group
91
 
92
 
93
- def render_standard_resource_row(method, r, conf, display_label, enabled_methods, has_custom_batch=False):
94
  """Render the slider row for a single standard resource coefficient.
95
 
96
  Handles the secondary-resource toggle, fixed-value display, and the
@@ -103,7 +103,6 @@ def render_standard_resource_row(method, r, conf, display_label, enabled_methods
103
  conf (dict): {min, median, max} for this (method, resource) pair.
104
  display_label (str): human-readable resource label with unit.
105
  enabled_methods (dict): {resource: {method: bool}} from session state.
106
- has_custom_batch (bool): True if a custom batch derived from r exists.
107
 
108
  Returns:
109
  None
@@ -136,17 +135,10 @@ def render_standard_resource_row(method, r, conf, display_label, enabled_methods
136
  )
137
  st.session_state.costs[method][r] = conf["median"]
138
  if st.session_state.get("resource_caps", {}).get(r, 0) <= 0:
139
- if has_custom_batch:
140
- st.warning(
141
- f"No available quantity set for **{r}** in Resource Inputs tab.",
142
- icon=":material/warning:",
143
- )
144
- else:
145
- st.warning(
146
- f"No available quantity set for **{r}** in Resource Inputs tab: "
147
- f"**{method}** won't be used in the optimization.",
148
- icon=":material/warning:",
149
- )
150
  return
151
 
152
  if slider_key not in st.session_state:
@@ -154,17 +146,14 @@ def render_standard_resource_row(method, r, conf, display_label, enabled_methods
154
  if manual_key not in st.session_state:
155
  st.session_state[manual_key] = st.session_state[slider_key]
156
  if st.session_state.get("resource_caps", {}).get(r, 0) <= 0:
157
- if has_custom_batch:
158
- st.warning(
159
- f"No available quantity set for **{r}** in Resource Inputs tab.",
160
- icon=":material/warning:",
161
- )
162
- else:
163
- st.warning(
164
- f"No available quantity set for **{r}** in Resource Inputs tab: "
165
- f"**{method}** won't be used in the optimization.",
166
- icon=":material/warning:",
167
- )
168
 
169
  col1, col2 = st.columns([3, 1])
170
  with col1:
@@ -237,17 +226,17 @@ def render_custom_resource_row(method, r, conf, enabled_methods, custom_resource
237
 
238
  batch_amount = next((float(b.get("amount", 0)) for b in custom_resources if b["name"] == r), 0.0)
239
  if batch_amount <= 0:
240
- if is_sec:
241
- st.info(
242
- f"No available quantity set for **{r}** in Resource Inputs.",
243
- icon=":material/info:",
244
- )
245
- else:
246
- st.info(
247
- f"No available quantity set for **{r}** in Resource Inputs — "
248
- "this method won't be used in the optimization.",
249
- icon=":material/info:",
250
- )
251
 
252
  col1, col2 = st.columns([3, 1])
253
  with col1:
@@ -327,12 +316,10 @@ def panel_method_editor(
327
 
328
  st.markdown(f'<p class="crra-group-name">{group_name}</p>', unsafe_allow_html=True)
329
 
330
- resources_with_batches = set(custom_resource_to_sub_group.values())
331
  for r in used:
332
  conf = method_sliders[r]
333
  render_standard_resource_row(
334
  method, r, conf, resource_display.get(r, r), enabled_methods,
335
- has_custom_batch=(r in resources_with_batches),
336
  )
337
 
338
  for r in custom_in_group:
 
5
  resource_order, secondary_resources, resource_unit_map, CO2_UNIT,
6
  hidden_resource_names)
7
  from utils.ui_helpers import format_efficiency_summary, show_bar
8
+ from utils.data_utils import (get_resource_to_group, normalize_costs,
9
  get_slider_params, is_method_enabled, is_custom_secondary)
10
 
11
 
 
90
  return custom_sliders_by_method, custom_resource_names, custom_resource_to_sub_group, custom_resource_to_group
91
 
92
 
93
+ def render_standard_resource_row(method, r, conf, display_label, enabled_methods):
94
  """Render the slider row for a single standard resource coefficient.
95
 
96
  Handles the secondary-resource toggle, fixed-value display, and the
 
103
  conf (dict): {min, median, max} for this (method, resource) pair.
104
  display_label (str): human-readable resource label with unit.
105
  enabled_methods (dict): {resource: {method: bool}} from session state.
 
106
 
107
  Returns:
108
  None
 
135
  )
136
  st.session_state.costs[method][r] = conf["median"]
137
  if st.session_state.get("resource_caps", {}).get(r, 0) <= 0:
138
+ st.info(
139
+ f"No available quantity set for **{r}** in Resource Inputs tab.",
140
+ icon=":material/info:",
141
+ )
 
 
 
 
 
 
 
142
  return
143
 
144
  if slider_key not in st.session_state:
 
146
  if manual_key not in st.session_state:
147
  st.session_state[manual_key] = st.session_state[slider_key]
148
  if st.session_state.get("resource_caps", {}).get(r, 0) <= 0:
149
+ st.info(
150
+ f"No available quantity set for **{r}** in Resource Inputs tab.",
151
+ icon=":material/info:",
152
+ )
153
+ # Don't render the slider — with zero supply, its coefficient has no
154
+ # effect on the result (mirrors the "fixed value" branch above, which
155
+ # already stops here instead of leaving a live-but-meaningless widget).
156
+ return
 
 
 
157
 
158
  col1, col2 = st.columns([3, 1])
159
  with col1:
 
226
 
227
  batch_amount = next((float(b.get("amount", 0)) for b in custom_resources if b["name"] == r), 0.0)
228
  if batch_amount <= 0:
229
+ # Not necessarily true that the method "won't be used": it may still
230
+ # run via the standard resource this batch complements, or via a
231
+ # sibling batch of the same reference — so just report this specific
232
+ # batch's own availability, same message regardless of is_sec.
233
+ st.info(
234
+ f"No available quantity set for **{r}** in Resource Inputs.",
235
+ icon=":material/info:",
236
+ )
237
+ # Don't render the slider — with zero supply, its coefficient has no
238
+ # effect on the result.
239
+ return
240
 
241
  col1, col2 = st.columns([3, 1])
242
  with col1:
 
316
 
317
  st.markdown(f'<p class="crra-group-name">{group_name}</p>', unsafe_allow_html=True)
318
 
 
319
  for r in used:
320
  conf = method_sliders[r]
321
  render_standard_resource_row(
322
  method, r, conf, resource_display.get(r, r), enabled_methods,
 
323
  )
324
 
325
  for r in custom_in_group: