diff --git a/PROJECT_KNOWLEDGE.md b/PROJECT_KNOWLEDGE.md index be1e278..2adf619 100644 --- a/PROJECT_KNOWLEDGE.md +++ b/PROJECT_KNOWLEDGE.md @@ -99,11 +99,13 @@ an exact per-order yield needs WIP/transport-delay accounting. ## Bento 1 bentonite-powder integration -Bento 1 bentonite-powder consumption is the next planned application of the -same generic integration mechanism. Its ENLYZE source variable and its -validity/gating logic have not yet been selected or validated; both must be -determined from Bento 1 process data before implementation. Bento 1 does not -need a separate subsystem or calculation formula. +Bento 1 uses the generic integration mechanism for fresh-bentonite spreaders +1+2 and a separate Spreader 3 source using `linear_signal_discharge`. Spreader 3 +may carry bentonite or sand; material identity is not inferred, and only its +bentonite calibration is implemented. It is not automatically aggregated into +`bento1-fresh-bentonite-consumption`. Its dedicated service is deployed and +verified. See [Bento 1 material documentation](docs/bento1-fresh-bentonite.md) +for signals, calibration, validation and runtime details. ## Quantity-total interpretation @@ -162,12 +164,29 @@ historical-only calculation path. ## Power-meter pipeline The generic `power_meter` package collects configured ENLYZE meters into -TimescaleDB/PostgreSQL. The B2 example uses only verified UUIDs for machine, -energy total, active power total and grid frequency. Power-outage counting is -supported by schema/repository but remains unset until the real UUID is present -in local raw exploration data. Counter decreases start a new epoch and record -the new counter value as the increment; the first observation establishes a -baseline with zero increment. Optional phase power is stored as JSONB and does -not require L2. `report monthly` reads the database directly, writes +TimescaleDB/PostgreSQL. As of 2026-10-01, the collector is running for B2 with total active power, +L2 active power, total energy, grid frequency, and Power Outages +(operator-confirmed production state; sandbox systemd access cannot independently +confirm live status). Both additional signals are verified and configured. + +| B2 signal | Verified ENLYZE UUID | Register | +| --- | --- | --- | +| L2 active power | `d9ae584e-551b-44b8-a822-3cf9554e77e4` | `3055` | +| Power Outages | `ea1f1f51-1758-4818-8ec3-fbb4b76d1a77` | `1828` | + +The deployed service is `production-analytics-power-meter.service`, running B2 +with `--follow` at a 60-second interval. Systemd loads the repository `.env`; +the CLI explicitly loads `secrets/enlyze.env` then `secrets/postgres.env`, whose +values override the environment in that order. The CLI does not automatically +load `.env`. Effective settings must include ENLYZE base URL/API key and all +five PostgreSQL connection settings. See the [production runbook](README.md#production-service-and-runtime-settings) +for secret-file requirements and start/restart/status/log commands. + +Counter decreases start a new epoch and record the new counter value as the +increment; the first observation establishes a baseline with zero increment. +Optional phase power is stored as JSONB; B2 includes L2. `report monthly` reads +the database directly, writes `///_Powermeter_.pdf`, and persists report -metadata independently of Grafana. +metadata independently of Grafana. **The SMB report mount at +`/mnt/reports/energy` is still pending**, so production report delivery remains +pending; collection is independent of the mount. diff --git a/README.md b/README.md index 4d3ef34..bd9045e 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,8 @@ utility: `Stundenleistung Anlage` is gated by `Geschwindigkeit Gesamtanlage > 0. 2,672 common samples yield **5.205555556 h** and **5,180.127150811 kg** for run 00842, matching the previous manual calculation's rounded results. Synthetic tests verify equivalence to manual interval integration without local captures -or live ENLYZE access. Grafana and Bento 1 remain pending. +or live ENLYZE access. See [Bento 1 documentation](docs/bento1-fresh-bentonite.md) +for its implemented material sources and verified deployment. `MaterialPollingService.poll_once(now=...)` starts at the open run's start or resumes inclusively at its last processed timestamp. Duplicate boundary samples @@ -218,17 +219,68 @@ The primary key deduplicates calculation/machine/order/timestamp (first write wi A short transaction opens and closes one synchronous connection per snapshot, with 10-second connection and statement timeouts. Snapshot timestamps are poll start times, not source-sample timestamps. Schema application is manual. -Bento 1 bentonite source and gate selection remain intentionally undefined pending -process validation; the generic integration core is unchanged and reusable. +Bento 1 uses the generic integration core for spreaders 1+2 and a separate +Spreader 3 source. See [Bento 1 configuration and deployment](docs/bento1-fresh-bentonite.md) +for verified machine-specific details. ## Generic ENLYZE power meters -`config/power-meters.example.yaml` is the configuration-only B2 starting point. -It contains the verified machine, energy, active-power and frequency UUIDs; K1 -and K6 are added as more `meters` entries without new code. Optional phase -channels are a mapping and may omit L2. `power_outages` is intentionally absent -until its real UUID is verified from the raw second `/v2/variables` page/register -1828; sanitized placeholders are never accepted. +As of 2026-10-01, the collector is running for B2 with total active power, +L2 active power, total energy, grid frequency, and Power Outages +(operator-confirmed production state; sandbox systemd access cannot independently +confirm live status). Both additional signals are verified and configured. + +| B2 signal | Verified ENLYZE UUID | Register | +| --- | --- | --- | +| L2 active power | `d9ae584e-551b-44b8-a822-3cf9554e77e4` | `3055` | +| Power Outages | `ea1f1f51-1758-4818-8ec3-fbb4b76d1a77` | `1828` | + +`config/power-meters.example.yaml` contains the verified B2 machine and signals. +K1 and K6 can be added as more `meters` entries without new code. Phase channels +remain optional for other meters; B2 has L2 configured. + +### Production service and runtime settings + +The deployed unit is `/etc/systemd/system/production-analytics-power-meter.service`. +It runs as `mtazl` from `/opt/git-projects/production-analytics`, using the repository +venv and B2 configuration with `--meter B2 --follow` at a 60-second interval. +It sets `PYTHONUNBUFFERED=1`, `Restart=always`, and `RestartSec=10`. + +The unit loads the repository `.env` through an optional systemd +`EnvironmentFile`; the CLI itself does **not** automatically load `.env`. +Required effective settings are `ENLYZE_BASE_URL` (use +`https://app.enlyze.com/api/`), `ENLYZE_API_KEY`, `POSTGRES_HOST`, `POSTGRES_PORT`, +`POSTGRES_DB`, `POSTGRES_USER`, and `POSTGRES_PASSWORD`. +`ENLYZE_HTTP_TIMEOUT_SECONDS` is optional (default 20). +Compose requires `POSTGRES_PASSWORD` in `.env`; optional `POSTGRES_PORT` controls +the published database port. The collector password must match the database. + +Keep credentials in ignored local files. The unit explicitly passes absolute +paths to `secrets/enlyze.env` and `secrets/postgres.env` in the repository. +The CLI merges process environment, ENLYZE secret file, then PostgreSQL secret +file; later file values override earlier ones. Files accept simple `KEY=VALUE` +assignments with optional quotes and are parsed without shell execution. +Do not commit `.env` or secret files or pass credentials as command arguments. + +After dependencies, runtime settings, database, and schema are ready, use these +commands on the production host: + +```bash +sudo systemctl start production-analytics-power-meter.service +sudo systemctl restart production-analytics-power-meter.service +systemctl status production-analytics-power-meter.service --no-pager +journalctl -u production-analytics-power-meter.service -n 100 --no-pager +journalctl -u production-analytics-power-meter.service -f +``` + +Restart after changing runtime settings. For foreground collection from the +repository root, provide settings through exported variables or secret files: + +```bash +.venv/bin/production-analytics run power-meter \ + --config config/power-meters.example.yaml --meter B2 --follow \ + --secrets-file secrets/enlyze.env --db-secrets-file secrets/postgres.env +``` Apply `db/schema.sql`, then run a bounded collection/backfill with ENLYZE and PostgreSQL values from the environment or secret files: @@ -238,7 +290,10 @@ production-analytics run power-meter --config config/power-meters.example.yaml \ --meter B2 --start 2026-09-01T00:00:00Z --end 2026-10-01T00:00:00Z ``` -Generate the independent monthly PDF (under the configured mounted SMB path): +**SMB report mount still pending:** `/mnt/reports/energy` is configured but the +SMB share has not yet been mounted/verified. Production report delivery remains +pending; collection is independent of the mount. Once the mount and PDF renderer +are ready, generate the independent monthly PDF: ```bash production-analytics report monthly --config config/power-meters.example.yaml \ diff --git a/docs/bento1-fresh-bentonite.md b/docs/bento1-fresh-bentonite.md index 5a831dc..df2b67e 100644 --- a/docs/bento1-fresh-bentonite.md +++ b/docs/bento1-fresh-bentonite.md @@ -160,69 +160,91 @@ Spreader 1+2 remains fresh bentonite from actual roll rpm, calibrated at **2.75 kg/(rev*m)**. Spreader 3 is a separate material source: it can contain bentonite or sand depending on the product. No material identity is inferred, and no spreader-3 value is added to fresh-bentonite consumption or efficiency. -No total-bentonite aggregate or sand calibration is implemented. +No total-bentonite aggregate is implemented. Sand calibration is intentionally +not implemented yet. `config/bento1-spreader3-material-consumption.yaml` uses generic `linear_signal_discharge` with central calibration `bento1-spreader-3-bentonite`: **0.4691089108910891 kg/(signal_unit*m)**, gravimetric tray, 2026-09-08. Reference: **3.03 signal @ 2.3 m/min → 618 g/m²**. -The exact factor is `618 * 2.3 / (3.03 * 1000) = 2369/5050`; the supplied -approximation 0.4693069307 differs from this measurement-derived value. +The factor is derived as `factor = 618 * 2.3 / (3.03 * 1000)`. Source `c5611859-275c-44c4-aec0-dfaccc87d478`, display name “Austragsbehälter Austragsschnecke Geschwindigkeit Istwert”, origin `AUFSTREUUNG_2/DischargeHopper_Output_Screw/ACT_Speed`. -ENLYZE's kg/m² metadata is not used as physical truth. Observed values on -2026-09-09 were around 3.0 during operation and 0.0 when inactive. +The source's ENLYZE unit metadata is not authoritative physical units. -- Application: `signal_sum * factor * 1000 / line_speed_m_min`, independent of width. -- Consumption rate: `signal_sum * factor * nominal_width_m` in kg/min, +- Application: `application_g_m2 = signal_sum * factor * 1000 / line_speed_m_min`, independent of width. +- Consumption rate: `mass_flow_kg_min = signal_sum * factor * nominal_width_m`, multiplied by 60 for the existing kg/h integrator. This equals `application_g_m2 * nominal_width_m * line_speed_m_min / 1000`. - Same ERP nominal-width provider, `Bento 1-{production_order}` formatting, - gate signal `fef41976-1103-4090-b780-eaeecc02fdfa` strictly > 0.3 m/min, + ERP workplace `Bento 1`, and gate signal + `fef41976-1103-4090-b780-eaeecc02fdfa` + (`Transport Auszug Geschwindigkeit Istwert`, unit m/min) strictly > 0.3 m/min, previous-value integration, 20-second maximum gap, and disjoint-run boundaries. - Application points are emitted only while the gate is active; zero source signal emits zero application during production. +Mass flow is independent of line speed. Speed is required for conversion to +application in g/m² and serves as the production gate; consumption does not +divide by speed. Consumption is attributed separately per production order. + | Calculation ID | Persistence | | --- | --- | | `bento1-spreader3-application` | `material_application_snapshots.application_g_m2` | | `bento1-spreader3-consumption` | `material_consumption_snapshots.consumption_kg` | -The new linear source namespaces JSON checkpoints under -`//`; existing 1+2 and K7 -checkpoint paths remain unchanged. Use a separate supervised consumption runner -with the spreader-3 config. No schema changes are needed if the existing generic -snapshot tables are present; otherwise apply `db/schema.sql` before starting it. -Do not reset 1+2 state. No migration, deployment, or service restart was performed. +### Validation -Production validation, 30 Sep 2026 10:00–13:00 Europe/Berlin, order `12026000984`, -article `180205` (Bfix NSP 4900, 5,00 x 40 m): `8.999 @ 4.999 m/min` gives -**844.471112 g/m²**. Adding the measured 1+2 average of 3915.961 gives -**4760.432112 g/m²**, within the expected 4400–4800 range. +The gravimetric reference, source 3.03 at 2.3 m/min, gives approximately +**618 g/m²**. This is the calibration reference. -Before redeployment, stop the spreader 3 runner and back up its checkpoints and -snapshots. Clear only its consumption checkpoint directory: -`/c8d0426504f2ce2ff214818e4ffa9b4daf4182131c0af3c5a1cca23a3dee566a/`. -With the default state root this is -`/opt/git-projects/production-analytics/data/state/material/c8d0426504f2ce2ff214818e4ffa9b4daf4182131c0af3c5a1cca23a3dee566a/`. -There is no separate application checkpoint directory. Clear all affected snapshot -rows, across orders and timestamps, using these exact predicates: +Production plausibility check on **2026-09-30**, 10:00–13:00 Europe/Berlin, +order `Bento 1-12026000984`: average Spreader 3 source approximately **8.999** +and average line speed approximately **4.999 m/min** give Spreader 3 application +approximately **844.47 g/m²**. Spreaders 1+2 application was approximately +**3915.96 g/m²**. The manually combined value for this verified bentonite +production was approximately **4760.43 g/m²**, matching the expected overall +range of roughly **4400–4800 g/m²**. These rounded values are a plausibility +cross-check, not a precision measurement. This combined value is only a +validation cross-check: software intentionally does not automatically combine +Spreader 3 with spreaders 1+2 because it may contain another material. -```sql -DELETE FROM material_application_snapshots -WHERE calculation_id = 'bento1-spreader3-application' - AND machine_id = '5f42a4f6-9ca0-4f6f-9786-40d50a35b230'; -DELETE FROM material_consumption_snapshots -WHERE calculation_id = 'bento1-spreader3-consumption' - AND machine_id = '5f42a4f6-9ca0-4f6f-9786-40d50a35b230'; +An observed short startup peak of approximately **2132.5 g/m²** was verified +as physically consistent with Spreader 3 signal approximately **2.2339** and +line speed approximately **0.4914 m/min**. Low web speed during startup causes +the high g/m² value. It should not be filtered from material consumption: +consumption integrates mass flow and does not divide by line speed. + +### Runtime and deployment notes + +Spreader 3 now runs as a dedicated systemd service, +`production-analytics-bento1-spreader3.service`, using the normal project `.env`, +ENLYZE secrets and ERP secrets for production-order attribution. The deployed +service was verified running successfully and polling approximately every +10 seconds. + +The shared material state root isolates calculation-specific JSON checkpoints +under `//`. For consumption calculation +`bento1-spreader3-consumption`, the directory is: + +```text +/opt/git-projects/production-analytics/data/state/material/c8d0426504f2ce2ff214818e4ffa9b4daf4182131c0af3c5a1cca23a3dee566a/ ``` -Perform cleanup before restarting with the corrected model; arrange a replay for -historical orders if corrected history is needed. Snapshot writes use -`ON CONFLICT DO NOTHING`, so existing application rows cannot correct themselves. -Leave spreaders 1+2 and K7 checkpoints and snapshots intact. These are instructions -only; no stored data has been deleted by this code change. +There is no separate application checkpoint directory. Existing spreaders 1+2 +and K7 checkpoint paths remain unchanged; do not reset their state. No schema +changes are needed if the existing generic snapshot tables are present. + +Verified accumulated state after correction for `Bento 1-12026000984`: +consumption approximately **11203.890692078 kg**, integrated running time +**31260 s**. This is only a runtime validation snapshot, not a calibration +reference or a precision claim for physical consumption. + +The initial manual validation run created Spreader 3 state as user `mtazl`, +causing a state-directory ownership issue. The production service runs as +`production-analytics:production-analytics`; the calculation-specific state +directory must be writable by that service account. This calibration is valid only for bentonite. Enable this runner only for validated bentonite operation; until reliable material identification is available, diff --git a/docs/material-calibrations.md b/docs/material-calibrations.md index 2fb881d..4db8ab7 100644 --- a/docs/material-calibrations.md +++ b/docs/material-calibrations.md @@ -40,7 +40,7 @@ consumption; the calculation algorithms are unchanged. There is no unit conversi Missing/unreadable files, missing IDs, invalid metadata and incompatible type or unit raise `CalculationConfigError` before a runner starts. Existing direct numeric configurations remain supported; specifying both a reference and a direct factor -is rejected. References are supported by rotational discharge and linear signal application consumers. +is rejected. References are supported by rotational discharge and `linear_signal_discharge` consumers. K7 uses direct mass rate and does not load or require a calibration file. ## Updating a calibration @@ -90,13 +90,13 @@ be configured directly as a substitute for the central reference. Calibration measurement: **3.03 signal @ 2.3 m/min → 618 g/m²**. The exact derived discharge factor is `618 * 2.3 / (3.03 * 1000) = 2369/5050`, stored at float precision as **0.4691089108910891 kg/(signal_unit*m)**. -The previously supplied approximation 0.4693069307 does not equal that expression. Application is `signal_sum * factor * 1000 / line_speed_m_min`, independent of width. Mass flow is `signal_sum * factor * nominal_width_m` kg/min, independent of speed; the existing kg/h integrator receives this discharge multiplied by 60. This measured bentonite calibration does not establish physical units from -ENLYZE metadata and must not be used for sand. Spreader 3 may carry sand on other +ENLYZE metadata and must not be used for sand. Sand calibration is intentionally +not implemented yet. Spreader 3 may carry sand on other products. Its application, consumption and checkpoints remain separate from fresh-bentonite spreaders 1+2, with no inferred material identity or automatic sum. See [Bento material documentation](bento1-fresh-bentonite.md) for configuration,