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
@@ -1,6 +1,6 @@
|
||||
"""Compose bounded ENLYZE speed reads with the pure running-speed KPI."""
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from typing import Protocol
|
||||
|
||||
from production_analytics.calculations.shift_speed import (
|
||||
@@ -15,6 +15,8 @@ from production_analytics.calculations.shift_speed import (
|
||||
class ShiftSpeedReader(Protocol):
|
||||
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]: ...
|
||||
|
||||
|
||||
@@ -26,8 +28,14 @@ class ShiftSpeedService:
|
||||
self, *, config: ShiftSpeedConfig, start: datetime, end: datetime,
|
||||
) -> ShiftSpeedSummary:
|
||||
validate_speed_window(start, end)
|
||||
samples = self.gateway.get_speed_samples(
|
||||
machine_id=config.machine_id, speed_signal_ref=config.speed_signal_ref,
|
||||
start=start, end=end,
|
||||
)
|
||||
kwargs = {"machine_id": config.machine_id, "speed_signal_ref": config.speed_signal_ref,
|
||||
"start": start, "end": end}
|
||||
if config.running_signal_ref is not None:
|
||||
kwargs["running_signal_ref"] = config.running_signal_ref
|
||||
if config.numeric_dwell_gate is not None:
|
||||
kwargs["numeric_gate_signal_ref"] = config.numeric_dwell_gate.signal_ref
|
||||
dwell = timedelta(seconds=config.numeric_dwell_gate.minimum_duration_seconds)
|
||||
kwargs["start"] = start.astimezone(UTC) - dwell
|
||||
kwargs["end"] = end.astimezone(UTC) + dwell
|
||||
samples = self.gateway.get_speed_samples(**kwargs)
|
||||
return aggregate_shift_speed(samples, config=config, start=start, end=end)
|
||||
Reference in new issue
Block a user