CarlyneB commited on
Commit
132dee6
Β·
1 Parent(s): 84fd744

[FIX] tab2: deactivate methods whose resource is unchecked in the Tab 1 popover, fix status display (red) and hint text

Browse files
Files changed (1) hide show
  1. tabs/tab2_constraints.py +20 -4
tabs/tab2_constraints.py CHANGED
@@ -48,7 +48,12 @@ def get_all_missing_required(m, cost_sliders_norm):
48
  OR if a custom batch with group == r is assigned to m β€” a custom batch
49
  substitutes for its reference resource regardless of whether that resource
50
  is a generic "Other X" (hidden) one or a specifically named standard one
51
- (e.g. a "Basalt A" batch referencing "Basalt mineral").
 
 
 
 
 
52
  Secondary resources and resources with median <= 0 are excluded.
53
 
54
  Returns:
@@ -56,6 +61,7 @@ def get_all_missing_required(m, cost_sliders_norm):
56
  """
57
  resource_caps = st.session_state.get("resource_caps", {})
58
  custom_resources = st.session_state.get("custom_resources", [])
 
59
  covered_by_batch = {
60
  b["group"] for b in custom_resources
61
  if m in b.get("methods", {})
@@ -70,6 +76,8 @@ def get_all_missing_required(m, cost_sliders_norm):
70
  continue
71
  if resource_caps.get(r, 0.0) <= 0:
72
  missing.append(r)
 
 
73
  return missing
74
 
75
 
@@ -115,12 +123,15 @@ def get_uncovered_hidden_resources(m, cost_sliders_norm):
115
  def _render_resource_status(m, cost_sliders_norm):
116
  """Render an expander showing all resources of method m with their availability status.
117
 
118
- Standard resources: βœ… if cap > 0, ❌ if = 0.
 
 
119
  Hidden resources: βœ… if covered by a custom batch, ❌ if not.
120
  Secondary resources are shown in a separate section.
121
  """
122
  resource_caps = st.session_state.get("resource_caps", {})
123
  custom_resources = st.session_state.get("custom_resources", [])
 
124
  # Map resource group β†’ list of batch names covering it for method m (any
125
  # named standard resource or hidden "Other X" resource can be substituted
126
  # by a custom batch referencing it).
@@ -143,9 +154,14 @@ def _render_resource_status(m, cost_sliders_norm):
143
  display_r = ", ".join(batch_names) if batch_names else r
144
  source = "Add as new resource in Resource inputs"
145
  else:
146
- available = resource_caps.get(r, 0.0) > 0 or bool(batch_names)
 
147
  display_r = ", ".join(batch_names) if (not resource_caps.get(r, 0.0) > 0 and batch_names) else r
148
- source = "Set quantity in Resource inputs"
 
 
 
 
149
 
150
  icon = "βœ…" if available else "❌"
151
  row = (icon, display_r, "" if available else source)
 
48
  OR if a custom batch with group == r is assigned to m β€” a custom batch
49
  substitutes for its reference resource regardless of whether that resource
50
  is a generic "Other X" (hidden) one or a specifically named standard one
51
+ (e.g. a "Basalt A" batch referencing "Basalt mineral"). A resource the user
52
+ has explicitly disabled for this method via the "Related CDR Methods"
53
+ popover (Tab 1) is treated as missing too, unless a custom batch covers it β€”
54
+ otherwise tab4 silently zeroes its coefficient (via enabled_methods) while
55
+ this tab still reports the method as active, a discrepancy that can lead to
56
+ "No active methods" once every resource of a method is disabled this way.
57
  Secondary resources and resources with median <= 0 are excluded.
58
 
59
  Returns:
 
61
  """
62
  resource_caps = st.session_state.get("resource_caps", {})
63
  custom_resources = st.session_state.get("custom_resources", [])
64
+ enabled_methods = st.session_state.get("enabled_methods", {})
65
  covered_by_batch = {
66
  b["group"] for b in custom_resources
67
  if m in b.get("methods", {})
 
76
  continue
77
  if resource_caps.get(r, 0.0) <= 0:
78
  missing.append(r)
79
+ elif not enabled_methods.get(r, {}).get(m, True):
80
+ missing.append(r)
81
  return missing
82
 
83
 
 
123
  def _render_resource_status(m, cost_sliders_norm):
124
  """Render an expander showing all resources of method m with their availability status.
125
 
126
+ Standard resources: βœ… if cap > 0 and not disabled for this method via the
127
+ "Related CDR Methods" popover (Tab 1), ❌ otherwise β€” unless a custom
128
+ batch covers it.
129
  Hidden resources: βœ… if covered by a custom batch, ❌ if not.
130
  Secondary resources are shown in a separate section.
131
  """
132
  resource_caps = st.session_state.get("resource_caps", {})
133
  custom_resources = st.session_state.get("custom_resources", [])
134
+ enabled_methods = st.session_state.get("enabled_methods", {})
135
  # Map resource group β†’ list of batch names covering it for method m (any
136
  # named standard resource or hidden "Other X" resource can be substituted
137
  # by a custom batch referencing it).
 
154
  display_r = ", ".join(batch_names) if batch_names else r
155
  source = "Add as new resource in Resource inputs"
156
  else:
157
+ disabled_for_method = not enabled_methods.get(r, {}).get(m, True)
158
+ available = (resource_caps.get(r, 0.0) > 0 and not disabled_for_method) or bool(batch_names)
159
  display_r = ", ".join(batch_names) if (not resource_caps.get(r, 0.0) > 0 and batch_names) else r
160
+ source = (
161
+ "Re-enable this method in the Related CDR Methods popover (Resource inputs tab)"
162
+ if disabled_for_method and resource_caps.get(r, 0.0) > 0
163
+ else "Set quantity in Resource inputs"
164
+ )
165
 
166
  icon = "βœ…" if available else "❌"
167
  row = (icon, display_r, "" if available else source)