Spaces:
Sleeping
Sleeping
[FEAT/FIX] Add Other-method helpers and fix coefficient display precision
Browse files- utils/data_utils.py +30 -1
- utils/ui_helpers.py +12 -14
utils/data_utils.py
CHANGED
|
@@ -232,4 +232,33 @@ def neutralize_zero_coefficient_methods(method_costs: dict, method_constraints:
|
|
| 232 |
if all_zero:
|
| 233 |
constraint["active"] = False
|
| 234 |
|
| 235 |
-
return safe_constraints
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
if all_zero:
|
| 233 |
constraint["active"] = False
|
| 234 |
|
| 235 |
+
return safe_constraints
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
# ---------------------------------------------------------------------------
|
| 239 |
+
# "Other" method expansion helpers
|
| 240 |
+
# ---------------------------------------------------------------------------
|
| 241 |
+
|
| 242 |
+
def is_other_method(method_name: str) -> bool:
|
| 243 |
+
"""True when the method name contains 'other' (case-insensitive).
|
| 244 |
+
|
| 245 |
+
These methods accept any resource from a generic 'Other X' pool and are
|
| 246 |
+
expanded into one variant per custom batch assigned by the user.
|
| 247 |
+
"""
|
| 248 |
+
return "other" in method_name.lower()
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
def get_other_method_variants(method_name: str, custom_resources: list) -> list:
|
| 252 |
+
"""Return the custom batch dicts assigned to an 'Other' method.
|
| 253 |
+
|
| 254 |
+
Returns an empty list when the method is not an 'Other' method or has no
|
| 255 |
+
custom batches assigned to it.
|
| 256 |
+
"""
|
| 257 |
+
if not is_other_method(method_name):
|
| 258 |
+
return []
|
| 259 |
+
return [b for b in custom_resources if method_name in b.get("methods", {})]
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
def make_variant_name(method_name: str, batch_name: str) -> str:
|
| 263 |
+
"""Build the display/LP name for a method variant: '<Method> - <Batch>'."""
|
| 264 |
+
return f"{method_name}: {batch_name}"
|
utils/ui_helpers.py
CHANGED
|
@@ -64,10 +64,13 @@ def show_bar():
|
|
| 64 |
|
| 65 |
|
| 66 |
def smart_display_format(val):
|
| 67 |
-
"""Format a numeric value
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
Args:
|
| 73 |
val (float): numeric value to format.
|
|
@@ -75,18 +78,13 @@ def smart_display_format(val):
|
|
| 75 |
Returns:
|
| 76 |
str: formatted string, or "" for near-zero values.
|
| 77 |
"""
|
| 78 |
-
if abs(val) < 1e-
|
| 79 |
return ""
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
return f"{val:,.3f}"
|
| 86 |
-
elif abs(val) < 100:
|
| 87 |
-
return f"{val:,.2f}"
|
| 88 |
-
else:
|
| 89 |
-
return f"{val:,.0f}"
|
| 90 |
|
| 91 |
|
| 92 |
def format_efficiency_summary(df: pd.DataFrame, df_default: pd.DataFrame):
|
|
|
|
| 64 |
|
| 65 |
|
| 66 |
def smart_display_format(val):
|
| 67 |
+
"""Format a numeric value showing all significant digits, no rounding.
|
| 68 |
|
| 69 |
+
Uses repr() which gives the shortest decimal string that round-trips
|
| 70 |
+
exactly to the same float — avoids floating-point noise like
|
| 71 |
+
462961.099999999976717 when the value is actually 462961.1.
|
| 72 |
+
Falls back to fixed-decimal notation when repr() produces scientific
|
| 73 |
+
notation (very small numbers such as 1e-11).
|
| 74 |
|
| 75 |
Args:
|
| 76 |
val (float): numeric value to format.
|
|
|
|
| 78 |
Returns:
|
| 79 |
str: formatted string, or "" for near-zero values.
|
| 80 |
"""
|
| 81 |
+
if abs(val) < 1e-14:
|
| 82 |
return ""
|
| 83 |
+
s = repr(val)
|
| 84 |
+
if "e" not in s.lower():
|
| 85 |
+
return s
|
| 86 |
+
# Scientific notation → convert to fixed decimal (e.g. 1e-11 → 0.00000000001)
|
| 87 |
+
return f"{val:.15f}".rstrip("0").rstrip(".")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
|
| 90 |
def format_efficiency_summary(df: pd.DataFrame, df_default: pd.DataFrame):
|