Files
production-analytics/docs/shift-speed.md
T
2026-10-07 21:58:18 +02:00

69 lines
3.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Shift running-speed KPI
`average_line_speed_m_min` is the arithmetic mean of finite speed samples
strictly above the configured production gate within `[start, end)`. Samples
have equal weight regardless of spacing. Inactive time does not contribute to
this KPI. No interpolation, carry-forward, or time weighting is applied.
The immutable summary includes signal, unit, gate, window, finite sample count,
active/inactive counts, active average/minimum/maximum, and invalid sample count.
`sample_count` counts finite numeric in-window values and equals active plus
inactive counts. Zero, negative, and values equal to or below the gate are
inactive. Null, non-numeric, boolean, NaN, and infinite values are invalid and
excluded from all finite/active statistics. Invalid/missing timestamps are also
counted separately as unavailable because window membership cannot be verified.
Absent source rows are not synthesized or counted. Without active samples,
average, minimum, and maximum are all `None`.
Window timestamps must be timezone aware and have positive elapsed duration.
All boundary comparisons use UTC instants, including DST folds.
## Configuration and service API
Machine-specific UUIDs, signal labels, units, and gates live in
`config/shift-report-machines.yaml`. It also contains the ERP workplace and material source references needed for
report composition; existing material-calculation definitions are not duplicated. The configured gates are
B1: 0.3 m/min; E1: 0.5 m/min; K7: 0.5 m/min. The config loader validates required
fields, non-empty identifiers, unique machine IDs, m/min units, and finite
non-negative gates. It returns frozen report machine configurations by name, each with a nested
`ShiftSpeedConfig` in `.speed`.
```python
from datetime import datetime
from zoneinfo import ZoneInfo
from production_analytics.enlyze.gateway import EnlyzeApiGateway
from production_analytics.service.shift_report_config import load_shift_report_machines
from production_analytics.service.shift_speed import ShiftSpeedService
machines = load_shift_report_machines("config/shift-report-machines.yaml")
service = ShiftSpeedService(EnlyzeApiGateway(client)) # Existing ExplorationClient
summary = service.summarize(
config=machines["K7"].speed,
start=datetime(2026, 10, 7, 6, tzinfo=ZoneInfo("Europe/Berlin")),
end=datetime(2026, 10, 7, 14, tzinfo=ZoneInfo("Europe/Berlin")),
)
```
`aggregate_shift_speed(samples, config=..., start=..., end=...)` is the pure
calculation API, accepting `ShiftSpeedSample(timestamp, value)` objects.
`EnlyzeApiGateway.get_speed_samples(machine_id=..., speed_signal_ref=...,
start=..., end=...)` requests just the configured signal from `/v2/timeseries`,
using the existing client and cursor semantics. It tolerates unavailable sample
values/timestamps; structural response and pagination errors fail the read,
preventing a partial successful summary. No snapshots are persisted.
## Supplied live reference
For 2026-10-07 06:00–14:00 Europe/Berlin:
| Machine | Samples | Active samples | Active average (m/min) |
| --- | ---: | ---: | ---: |
| B1 | 2880 | 1603 | 2.3139663284001912 |
| E1 | 2880 | 2782 | 7.933009468249328 |
| K7 | 2880 | 2667 | 10.078945039942955 |
These are the supplied validation values, not a new live read performed during
implementation. Tests cover filtering, statistics, boundary/DST behavior,
configuration, service composition, and gateway pagination with mocked responses.