Add generic production context helpers

This commit is contained in:
2026-09-06 05:16:25 +02:00
parent 9fea9cb6ba
commit 0856629e77
3 changed files with 188 additions and 3 deletions
+51 -3
View File
@@ -249,9 +249,57 @@ semantics. `feedback_timestamp` is preserved exactly, including a naive timezone
It represents the latest ERP feedback, and the ERP export is delayed relative to
live process data; the adapter makes no freshness inference.
This milestone adds no kg/m² or material-efficiency calculation, ERP-to-ENLYZE
order mapping, persistence, polling, CLI, or Grafana integration. Automated ERP
tests use mocks and require no live connectivity.
Automated ERP tests use mocks and require no live connectivity.
## ERP context normalization
Two pure helpers in `production_analytics.context` prepare context for later KPIs:
- `build_enlyze_production_order(erp_production_order, format_template) -> str`
uses an explicit template configured by the caller per machine/workplace.
The template requires exactly one literal `{production_order}` placeholder and
no other braces; invalid templates raise `ValueError`.
Outer ERP-order whitespace is stripped and the
remaining order must contain only ASCII digits. Leading zeros are preserved.
Empty/invalid orders raise `ValueError`. There is no default machine rule.
- `extract_nominal_width_m(article_description: str | None) -> float | None`
is generic across machines and conservatively reads a single
`<width> x <length> m` pair, accepting decimal
comma/point and variable whitespace. For example, `Stex R 1501 C (PR) 5,80 x 50 m`
yields `5.8`. Earlier article numbers and trailing descriptive text are ignored.
Missing, malformed, multiple or chained dimension patterns return `None`, as do
non-positive/non-finite dimensions. Signed/scientific notation and other units
are deliberately unsupported; both dimensions must be positive plain numbers.
K7 currently uses the explicit template `K 7-{production_order}`:
```python
k7_order_template = "K 7-{production_order}"
enlyze_order = build_enlyze_production_order("12026000815", k7_order_template)
# "K 7-12026000815"
```
Future machines may supply different verified templates without changing the
generic helper. Template selection belongs to machine/workplace configuration
or adapters; the helper contains no workplace lookup or machine-specific branch.
No other machine rule is introduced here.
ENLYZE production-order identifiers remain opaque everywhere else, with exact
comparison. These helpers never reverse-parse or split ENLYZE orders, including
combined identifiers such as `K 7-12025000074-K 7-12025000075`; passing such an
identifier to the ERP mapping function is rejected.
Nominal finished-product width currently comes from ERP article-description
parsing because neither verified DWH view (`dbo.GRAFANA_WORKPLACE_STATUS` and
`dbo.GRAFANA_PRODUCTION_CONFIRMATION`) has a dedicated width column. ENLYZE
`wLg1MeasuringWidth` (`Produktbreite`) is explicitly not used as K7 nominal
finished-product width:
it belongs to the MAHLO measurement system and observed values differ from nominal
article widths. Structured ERP product master data would be preferred when available.
These helpers are independent of database access and are not yet wired into live
processing. No normalized context model, kg/m² or material-efficiency calculation,
persistence, polling, runner, timeseries, or Grafana changes are introduced here.
## Peak-cycle detection