Add machine-aware maximum product length

This commit is contained in:
2026-09-26 12:25:04 +02:00
parent 3e13d24405
commit 90c28fb2f5
11 changed files with 765 additions and 5 deletions
+48
View File
@@ -425,6 +425,54 @@ def calculate_material_weight(
}
def calculate_material_length_for_weight(
*,
target_material_weight_kg: Any,
width_m: Any,
area_weight_g_m2: Any,
) -> dict[str, Any]:
"""Calculate material length for a target material-only roll weight."""
values = {
"target_material_weight_kg": target_material_weight_kg,
"width_m": width_m,
"area_weight_g_m2": area_weight_g_m2,
}
invalid = []
normalized = {}
for field, value in values.items():
if isinstance(value, bool) or not isinstance(value, (int, float)):
invalid.append({"field": field, "message": "must be a number"})
continue
number = float(value)
if not math.isfinite(number) or number <= 0:
invalid.append({"field": field, "message": "must be greater than zero"})
continue
normalized[field] = number
if invalid:
return {"status": "invalid_parameter", "invalid": invalid}
length_m = (
normalized["target_material_weight_kg"]
* 1000
/ normalized["width_m"]
/ normalized["area_weight_g_m2"]
)
if not math.isfinite(length_m) or length_m <= 0:
return {
"status": "invalid_parameter",
"invalid": [{
"field": "request",
"message": "values are outside the supported calculation range",
}],
}
return {
"status": "success",
"weight_scope": "material_only",
"inputs": normalized,
"material_length_m": length_m,
}
def _material_weight_kg(
roll_length_m: float, width_m: float, area_weight_g_m2: float
) -> float: