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
+49
-49
@@ -1,59 +1,61 @@
|
||||
# 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.
|
||||
`average_line_speed_m_min` is the arithmetic mean of active, finite production-speed
|
||||
samples in `[start, end)`. Each active sample has equal weight. The calculation does
|
||||
not interpolate or weight speed by elapsed time.
|
||||
|
||||
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`.
|
||||
## Activity gates
|
||||
|
||||
Window timestamps must be timezone aware and have positive elapsed duration.
|
||||
All boundary comparisons use UTC instants, including DST folds.
|
||||
The `speed` block has exactly one activity method:
|
||||
|
||||
## Configuration and service API
|
||||
- **Simple numeric:** `production_gate_m_min` selects speed samples strictly above
|
||||
the threshold. B1, E1 and K7 retain this behavior.
|
||||
- **Boolean:** `running_signal_ref` and optional `running_when` (default `true`)
|
||||
select samples whose status is exactly that Boolean. K5 uses `running_when: false`
|
||||
because its status signal is true when stopped.
|
||||
- **Numeric dwell:** `numeric_dwell_gate` has `signal_ref`, finite `threshold`,
|
||||
`comparison` (`below` or `above`), and positive integer
|
||||
`minimum_duration_seconds`. Gitter 1–4 use `below` and 150 seconds. Their
|
||||
production-speed signal holds its last value while stopped, and their PLC
|
||||
Boolean status did not reliably indicate downtime. The numeric gate follows
|
||||
the configured ENLYZE threshold and minimum duration concept.
|
||||
|
||||
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`.
|
||||
For `below`, only a gate value strictly less than the threshold satisfies the
|
||||
condition. An equal value ends a below-threshold run. Rows are ordered by their
|
||||
UTC timestamps; a condition reading remains the observed state until the next
|
||||
reading. A continuous below-threshold run qualifies when the elapsed time from
|
||||
its first below-threshold timestamp to the first non-below reading is at least
|
||||
the minimum duration. If it qualifies, **all** speed samples in that run are
|
||||
inactive, including those before the minimum duration elapsed. A short run
|
||||
bracketed by non-below readings stays active. The same rules apply to `above`.
|
||||
The interval ending at the non-satisfying reading excludes that reading.
|
||||
|
||||
```python
|
||||
from datetime import datetime
|
||||
from zoneinfo import ZoneInfo
|
||||
The service requests speed and the gate signal together from `/v2/timeseries`.
|
||||
For a dwell gate it extends the read window by one minimum duration on each side;
|
||||
only production-speed samples in the original report window enter the KPI. This
|
||||
lets a qualifying run crossing a report boundary be classified when the source
|
||||
provides enough surrounding readings. An unclosed short run, or a short run
|
||||
without a preceding non-satisfying reading, has unknown duration and is excluded
|
||||
conservatively. An invalid or non-finite gate reading breaks continuity and its
|
||||
speed row is excluded. A missing required gate column fails the read. No absent
|
||||
rows are synthesized; the result depends on the timestamps returned by ENLYZE,
|
||||
which deserves validation against live boundary cases.
|
||||
|
||||
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
|
||||
Invalid speed values (including Boolean, null, non-numeric, NaN, and infinity)
|
||||
are excluded in every mode. Invalid timestamps are also excluded. In Boolean
|
||||
mode, missing or non-Boolean status is excluded. `sample_count` is the sum of
|
||||
active and inactive valid speed samples; excluded samples increment
|
||||
`invalid_sample_count`. If no active samples remain, average, minimum and maximum
|
||||
are `None`.
|
||||
|
||||
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")),
|
||||
)
|
||||
```
|
||||
Machine UUIDs and gate settings live in `config/shift-report-machines.yaml`.
|
||||
The loader validates the gate fields and rejects overlapping Boolean and dwell
|
||||
gates. `ShiftSpeedService.summarize()` composes the gateway read with the pure
|
||||
`aggregate_shift_speed()` calculation. The calculation accepts
|
||||
`ShiftSpeedSample(timestamp, value, running, gate_value)` records. Structural
|
||||
timeseries and pagination errors fail the read instead of returning a partial KPI.
|
||||
|
||||
`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
|
||||
## Supplied legacy reference
|
||||
|
||||
For 2026-10-07 06:00–14:00 Europe/Berlin:
|
||||
|
||||
@@ -63,6 +65,4 @@ For 2026-10-07 06:00–14:00 Europe/Berlin:
|
||||
| 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.
|
||||
These are supplied validation values, not a new live read.
|
||||
Reference in new issue
Block a user