Extend shift reporting and downtime analytics
This commit is contained in:
1 parent
41a5ae7a63
commit
6e8eb6f50f
74 files changed
+5397
-238
No files matched your search
@@ -156,8 +156,10 @@ class EnlyzeApiGateway:
|
||||
|
||||
def get_speed_samples(
|
||||
self, *, machine_id: str, speed_signal_ref: str, start: datetime, end: datetime,
|
||||
running_signal_ref: str | None = None,
|
||||
numeric_gate_signal_ref: str | None = None,
|
||||
) -> list[ShiftSpeedSample]:
|
||||
"""Retrieve one bounded signal using the existing timeseries cursor contract.
|
||||
"""Retrieve bounded speed and optional status in one timeseries request.
|
||||
|
||||
Invalid/missing sample values remain unavailable for domain aggregation.
|
||||
Malformed timestamps/rows become invalid samples, while structural response
|
||||
@@ -167,11 +169,25 @@ class EnlyzeApiGateway:
|
||||
for name, value in (("machine_id", machine_id), ("speed_signal_ref", speed_signal_ref)):
|
||||
if not isinstance(value, str) or not value.strip() or "\x00" in value:
|
||||
raise ValueError(f"{name} must be a non-empty string without NUL bytes")
|
||||
if running_signal_ref is not None and numeric_gate_signal_ref is not None:
|
||||
raise ValueError("Speed activity gates are mutually exclusive")
|
||||
for name, signal_ref in (("running_signal_ref", running_signal_ref),
|
||||
("numeric_gate_signal_ref", numeric_gate_signal_ref)):
|
||||
if signal_ref is not None and (
|
||||
not isinstance(signal_ref, str) or not signal_ref.strip()
|
||||
or "\x00" in signal_ref or signal_ref == speed_signal_ref
|
||||
):
|
||||
raise ValueError(f"{name} must be a distinct non-empty string")
|
||||
variables = [{"uuid": speed_signal_ref}]
|
||||
if running_signal_ref is not None:
|
||||
variables.append({"uuid": running_signal_ref})
|
||||
if numeric_gate_signal_ref is not None:
|
||||
variables.append({"uuid": numeric_gate_signal_ref})
|
||||
body = {
|
||||
"machine": machine_id,
|
||||
"start": start.astimezone(UTC).isoformat(),
|
||||
"end": end.astimezone(UTC).isoformat(),
|
||||
"variables": [{"uuid": speed_signal_ref}],
|
||||
"variables": variables,
|
||||
}
|
||||
samples = []
|
||||
cursors: set[str] = set()
|
||||
@@ -181,14 +197,22 @@ class EnlyzeApiGateway:
|
||||
try:
|
||||
data = response.body["data"]
|
||||
columns = data["columns"]
|
||||
required = ["time", speed_signal_ref]
|
||||
if running_signal_ref is not None:
|
||||
required.append(running_signal_ref)
|
||||
if numeric_gate_signal_ref is not None:
|
||||
required.append(numeric_gate_signal_ref)
|
||||
if not isinstance(columns, list) or any(
|
||||
columns.count(column) != 1 for column in ("time", speed_signal_ref)
|
||||
columns.count(column) != 1 for column in required
|
||||
):
|
||||
raise ValueError("required columns must occur exactly once")
|
||||
records = data["records"]
|
||||
if not isinstance(records, list):
|
||||
raise ValueError("records must be a list")
|
||||
time_index, speed_index = columns.index("time"), columns.index(speed_signal_ref)
|
||||
running_index = columns.index(running_signal_ref) if running_signal_ref else None
|
||||
numeric_index = (columns.index(numeric_gate_signal_ref)
|
||||
if numeric_gate_signal_ref else None)
|
||||
for record in records:
|
||||
if not isinstance(record, list) or len(record) != len(columns):
|
||||
samples.append(ShiftSpeedSample(None, None))
|
||||
@@ -197,7 +221,11 @@ class EnlyzeApiGateway:
|
||||
timestamp = _parse_timestamp(record[time_index])
|
||||
except (TypeError, ValueError):
|
||||
timestamp = None
|
||||
samples.append(ShiftSpeedSample(timestamp, record[speed_index]))
|
||||
samples.append(ShiftSpeedSample(
|
||||
timestamp, record[speed_index],
|
||||
record[running_index] if running_index is not None else None,
|
||||
record[numeric_index] if numeric_index is not None else None,
|
||||
))
|
||||
cursor = _next_cursor(response.body)
|
||||
if cursor is None:
|
||||
return samples
|
||||
|
||||
Reference in new issue
Block a user