Use rotational discharge for Bento consumption

This commit is contained in:
admin committed 2026-09-07 07:59:48 +02:00
1 parent be8d76507a
commit 0210ced9e3
10 files changed
+400 -92

No files matched your search

+22 -6
View File
@@ -7,6 +7,7 @@ from math import isfinite
from production_analytics.calculations.material_consumption import (
MaterialSample,
area_application_rate_kg_per_hour,
rotational_discharge_rate_kg_per_hour,
)
from production_analytics.enlyze.exploration import ExplorationClient
@@ -89,19 +90,28 @@ class EnlyzeApiGateway:
*,
machine_id: str,
rate_variable_id: str,
gate_variable_id: str,
gate_variable_id: str | None,
start: datetime,
end: datetime,
application_variable_ids: tuple[str, ...] = (),
nominal_width_m: float | None = None,
rotational_speed_variable_ids: tuple[str, ...] = (),
specific_discharge_kg_per_rev_m: float | None = None,
) -> list[MaterialSample]:
for name, value in (("start", start), ("end", end)):
if value.tzinfo is None or value.utcoffset() is None:
raise ValueError(f"{name} must be timezone-aware")
if end < start:
raise ValueError("end must not precede start")
source_ids = application_variable_ids or (rate_variable_id,)
variable_ids = list(dict.fromkeys((*source_ids, gate_variable_id)))
if application_variable_ids and rotational_speed_variable_ids:
raise ValueError("Material source modes are mutually exclusive")
if gate_variable_id is None and not rotational_speed_variable_ids:
raise ValueError("This source requires a gate signal")
source_ids = (
rotational_speed_variable_ids or application_variable_ids or (rate_variable_id,)
)
gate_ids = (gate_variable_id,) if gate_variable_id else ()
variable_ids = list(dict.fromkeys((*source_ids, *gate_ids)))
request_body = {
"machine": machine_id,
"start": start.astimezone(UTC).isoformat(),
@@ -123,7 +133,7 @@ class EnlyzeApiGateway:
raise ValueError(f"required column {required!r} must occur exactly once")
time_index = columns.index("time")
source_indices = [columns.index(ref) for ref in source_ids]
gate_index = columns.index(gate_variable_id)
gate_index = columns.index(gate_variable_id) if gate_variable_id else None
if not isinstance(data["records"], list):
raise ValueError("records must be a list")
for index, record in enumerate(data["records"]):
@@ -131,13 +141,19 @@ class EnlyzeApiGateway:
if not isinstance(record, list) or len(record) != len(columns):
raise ValueError("record must match columns")
sources = [record[i] for i in source_indices]
gate = record[gate_index]
gate = record[gate_index] if gate_index is not None else 1.0
for value in (*sources, gate):
if isinstance(value, bool) or not isinstance(value, (int, float)):
raise ValueError("rate and gate must be numeric")
if not isfinite(value):
raise ValueError("rate and gate must be finite")
if application_variable_ids:
if rotational_speed_variable_ids:
if nominal_width_m is None or specific_discharge_kg_per_rev_m is None:
raise ValueError("rotational discharge requires width and factor")
rate = rotational_discharge_rate_kg_per_hour(
sources, nominal_width_m, specific_discharge_kg_per_rev_m,
)
elif application_variable_ids:
if nominal_width_m is None:
raise ValueError("area application requires nominal width")
rate = area_application_rate_kg_per_hour(sources, nominal_width_m, gate)