Spaces:
Running
Running
[FIX] tab2: new resource batches now cover named standard resources, not only hidden "Other" ones
Browse files- tabs/tab2_constraints.py +18 -15
tabs/tab2_constraints.py
CHANGED
|
@@ -44,8 +44,11 @@ def get_hidden_resources_for_method(m, method_to_primary_resources, cost_sliders
|
|
| 44 |
def get_all_missing_required(m, cost_sliders_norm):
|
| 45 |
"""Return all required resources for method m that are not yet available.
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
| 49 |
Secondary resources and resources with median <= 0 are excluded.
|
| 50 |
|
| 51 |
Returns:
|
|
@@ -53,7 +56,7 @@ def get_all_missing_required(m, cost_sliders_norm):
|
|
| 53 |
"""
|
| 54 |
resource_caps = st.session_state.get("resource_caps", {})
|
| 55 |
custom_resources = st.session_state.get("custom_resources", [])
|
| 56 |
-
|
| 57 |
b["group"] for b in custom_resources
|
| 58 |
if m in b.get("methods", {})
|
| 59 |
}
|
|
@@ -63,12 +66,10 @@ def get_all_missing_required(m, cost_sliders_norm):
|
|
| 63 |
continue
|
| 64 |
if coeff_dict.get("median", 0.0) <= 0:
|
| 65 |
continue
|
| 66 |
-
if r in
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
if resource_caps.get(r, 0.0) <= 0:
|
| 71 |
-
missing.append(r)
|
| 72 |
return missing
|
| 73 |
|
| 74 |
|
|
@@ -120,11 +121,13 @@ def _render_resource_status(m, cost_sliders_norm):
|
|
| 120 |
"""
|
| 121 |
resource_caps = st.session_state.get("resource_caps", {})
|
| 122 |
custom_resources = st.session_state.get("custom_resources", [])
|
| 123 |
-
# Map
|
| 124 |
-
|
|
|
|
|
|
|
| 125 |
for b in custom_resources:
|
| 126 |
if m in b.get("methods", {}):
|
| 127 |
-
|
| 128 |
|
| 129 |
all_res = cost_sliders_norm.get(m, {})
|
| 130 |
required_rows = []
|
|
@@ -133,15 +136,15 @@ def _render_resource_status(m, cost_sliders_norm):
|
|
| 133 |
for r, coeff_dict in all_res.items():
|
| 134 |
if coeff_dict.get("median", 0.0) <= 0:
|
| 135 |
continue
|
|
|
|
| 136 |
if r in hidden_resource_names:
|
| 137 |
-
batch_names = covered_hidden.get(r)
|
| 138 |
available = bool(batch_names)
|
| 139 |
# Show actual batch name(s) instead of the generic "Other X" group
|
| 140 |
display_r = ", ".join(batch_names) if batch_names else r
|
| 141 |
source = "Add as new resource in Resource inputs"
|
| 142 |
else:
|
| 143 |
-
available = resource_caps.get(r, 0.0) > 0
|
| 144 |
-
display_r = r
|
| 145 |
source = "Set quantity in Resource inputs"
|
| 146 |
|
| 147 |
icon = "✅" if available else "❌"
|
|
|
|
| 44 |
def get_all_missing_required(m, cost_sliders_norm):
|
| 45 |
"""Return all required resources for method m that are not yet available.
|
| 46 |
|
| 47 |
+
A resource (standard or hidden) is available if resource_caps.get(r, 0.0) > 0
|
| 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 |
"""
|
| 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", {})
|
| 62 |
}
|
|
|
|
| 66 |
continue
|
| 67 |
if coeff_dict.get("median", 0.0) <= 0:
|
| 68 |
continue
|
| 69 |
+
if r in covered_by_batch:
|
| 70 |
+
continue
|
| 71 |
+
if resource_caps.get(r, 0.0) <= 0:
|
| 72 |
+
missing.append(r)
|
|
|
|
|
|
|
| 73 |
return missing
|
| 74 |
|
| 75 |
|
|
|
|
| 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).
|
| 127 |
+
covered_by_batch: dict[str, list[str]] = {}
|
| 128 |
for b in custom_resources:
|
| 129 |
if m in b.get("methods", {}):
|
| 130 |
+
covered_by_batch.setdefault(b["group"], []).append(b["name"])
|
| 131 |
|
| 132 |
all_res = cost_sliders_norm.get(m, {})
|
| 133 |
required_rows = []
|
|
|
|
| 136 |
for r, coeff_dict in all_res.items():
|
| 137 |
if coeff_dict.get("median", 0.0) <= 0:
|
| 138 |
continue
|
| 139 |
+
batch_names = covered_by_batch.get(r)
|
| 140 |
if r in hidden_resource_names:
|
|
|
|
| 141 |
available = bool(batch_names)
|
| 142 |
# Show actual batch name(s) instead of the generic "Other X" group
|
| 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 "❌"
|