92 lines
4.2 KiB
Markdown
92 lines
4.2 KiB
Markdown
# Unified shift-report composition
|
||
|
||
`ShiftReportService` composes the existing production, downtime, material, and
|
||
speed services sequentially. It performs no database or HTTP reads itself and
|
||
adds no quantity or interval aggregation. Its frozen `ShiftReport` reuses all
|
||
four immutable summary models directly, preserving source metadata and items
|
||
for later PDF or SSR rendering. Neither renderer is implemented here.
|
||
|
||
## Configuration and API
|
||
|
||
`config/shift-report-machines.yaml` is self-contained for composition:
|
||
|
||
```yaml
|
||
machines:
|
||
B1:
|
||
machine_id: 5f42a4f6-9ca0-4f6f-9786-40d50a35b230
|
||
erp_workplace: BENTO 1
|
||
material:
|
||
mode: cumulative
|
||
calculation_ids:
|
||
- bento1-fresh-bentonite-consumption
|
||
- bento1-spreader3-consumption
|
||
speed:
|
||
signal_ref: fef41976-1103-4090-b780-eaeecc02fdfa
|
||
signal: Transport Auszug Geschwindigkeit Istwert
|
||
unit: m/min
|
||
production_gate_m_min: 0.3
|
||
```
|
||
|
||
The loader returns `ShiftReportMachineConfig` values with frozen material and
|
||
speed configurations. Speed-only consumers now use `machines[name].speed`.
|
||
Missing/unknown fields, duplicate YAML keys or machine IDs, unsupported material
|
||
modes, empty/duplicate calculation IDs, and invalid speed metadata are rejected.
|
||
No unrelated YAML configuration is loaded at runtime.
|
||
|
||
Inject already constructed services:
|
||
|
||
```python
|
||
machines = load_shift_report_machines("config/shift-report-machines.yaml")
|
||
service = ShiftReportService(
|
||
machines=machines,
|
||
production=production_service,
|
||
downtime=downtime_service,
|
||
materials=material_service,
|
||
channel_materials=channel_material_service,
|
||
speed=speed_service,
|
||
)
|
||
start, end = shift_report_window(day, "early")
|
||
report = service.build(machine_name="B1", start=start, end=end)
|
||
```
|
||
|
||
`shift_report_window` lives in `calculations.shift_report`; the loader and
|
||
service live in `service.shift_report_config` and `service.shift_report`.
|
||
The day is the shift's start date in Europe/Berlin. Early is 06:00–14:00, late is
|
||
14:00–22:00, and night is 22:00–06:00 on the following day. Night shifts can have
|
||
seven or nine elapsed hours at DST transitions. Explicit windows are validated
|
||
as aware, positive-duration instants and normalized to Berlin for all service
|
||
calls. All source services retain their `[start, end)` semantics.
|
||
|
||
## Source semantics
|
||
|
||
Production uses the existing finished-goods ERP service with workplaces B1:
|
||
`BENTO 1`, E1: `1568705`, and K7: `K7`. Its order/article groups, m², roll counts,
|
||
and first/last confirmation timestamps remain available in `report.production`.
|
||
|
||
`report.downtime.non_downtime_seconds` is the elapsed shift duration minus the
|
||
union of downtime intervals. It is a time complement and does not measure actual
|
||
production time. It is never named `production_time_seconds`. The report exposes
|
||
`downtime_event_count`, all `downtime_reasons`, and `top_downtime_reasons` (at most
|
||
three). Reason views retain the original immutable reason, including duration
|
||
and metadata; null/blank names get `Ohne Stillstandsgrund`. The existing summary
|
||
provides ranking and tie ordering. Overlapping reasons can have durations whose
|
||
sum exceeds total downtime.
|
||
|
||
B1 uses cumulative fresh-bentonite and spreader3 snapshot streams; K7 uses the
|
||
cumulative fiber stream. E1 uses channel snapshots, preserving extruder/channel,
|
||
material number/name/status, calculation ID, and source in each item. Existing
|
||
counter differencing, reset failure behavior, and sample-to-sample attribution
|
||
remain unchanged. Null material names remain null; no carry-forward or report
|
||
label invents an identity. ERP raw-material booking quantities are excluded
|
||
because their timing is not synchronized with physical shift consumption.
|
||
|
||
Speed is the arithmetic sample mean strictly above the configured production
|
||
gate: average speed while running, not average speed over the full shift.
|
||
Counts, gate, and active min/max are preserved in `report.speed`.
|
||
|
||
Every source is mandatory. Exceptions propagate immediately and later services
|
||
are not called. An empty successful summary remains an empty summary; a failed
|
||
read is never replaced with zeros. No cross-source matching of runs or orders is
|
||
introduced, and sequential reads are not a transactionally consistent snapshot
|
||
across ERP, PostgreSQL, and ENLYZE.
|