Search and contents

The MES as a database log: one order's life, played into a stand-in

Many plants have no way to ask their MES for an order's status, but the MES keeps its own database and writes to it as the order moves. Kindred can read that database (database-log-scanning.md). This page is a scenario for that case: one order is released, its weld reading comes in under the limit, and it is blocked. A scenario file and a seed make the statements that tell that story, the row player plays them into a stand-in database, and a MES Node reads the stand-in. What the Node makes of it is pinned by a test. What the whole practice site makes of the same order, across three Nodes and with a model, is on late-order-across-a-site.md.

Every value on this page is invented. The order, the vendor, the lot, the weld strength and the cycle time are made up for this scenario. They are not a plant's data, and the stand-in is not any real MES's database. The scenario's seed is 2027, and the scenario file, the Node's config and the dictionary extension are in examples/mes-database-log-site.

This is test tooling, not part of the public API. The files, the options and the output may change in any release, and the stability policy (public-api-stability.md) does not cover them.

What the stand-in is not

  • It is not a real MES's database. It is the row player's order_status layout: one table, one row for each order, updated in place, with the awkward parts a real one has (an integer status code, a padded lot, a timestamp with no time zone). No vendor's table looks like it.
  • It has no history. An update replaces the row, so a Node that reads it sees the row as it is when it looks, and an update it was too slow to see is gone.
  • It has no other writers, no transactions held open and no deletes. The player sets updated_at itself, which a real application would.
  • It does not make the Node's checks right for a plant. It shows what the checks do with the three rows written here and nothing more.
  • It is not the first demo's site. That demo had no MES software and read a PLC and an ERP only.

The files

FileWhat it is
order-weld-below-limit.scenario.jsonl The scenario: one order, three readings five minutes apart, from the shape simulator's generator.
mes-config.json A MES Node's config that reads the order_status layout and runs the three checks beside it. It uses the layout's own column names.
mes-dictionary-extension.json Declares the three values the checks read (weld_strength_n, material_id and cycle_time_seconds) and the one value no check reads, blocked_reason, for this site. They are not in the shipped MES dictionary.

The layout has a weld strength column and a cycle time column, so a weld reading and a cycle time are on each order's row for the life of the order. The config sets qualification_relevant to false, which stops the first-article flag that a section with no vendor fields would otherwise raise.

Setup and the commands in this document

The commands run in order, from the repository root with the project's Python environment active, and each one relies on the ones before it. The block below makes a working directory and a target file for a database on this machine. It needs a Postgres server you may create tables in on this machine's standard port, with a database called standin and an account called kindred_player; change the target file if yours are named differently. Run it first, in the same shell.

WORK=$(mktemp -d)
mkdir -p "$WORK/files" "$WORK/again" "$WORK/other"
SCENARIO=examples/mes-database-log-site/order-weld-below-limit.scenario.jsonl
cat > "$WORK/target.json" <<'JSON'
{"host": "127.0.0.1", "port": 5432, "database": "standin", "user": "kindred_player", "schema": "standin"}
JSON

Making the statement file

python -m engine.scenario_cli check "$SCENARIO"
Scenario order-weld-below-limit (order-weld-below-limit.scenario.jsonl), seed 2027: synthetic data made from a scenario file; it is not a site's data and proves nothing about one.
  records: 3 (3 ticks x 1 identities)
python -m engine.scenario_cli write "$SCENARIO" --out "$WORK/files"
Scenario order-weld-below-limit (order-weld-below-limit.scenario.jsonl), seed 2027: synthetic data made from a scenario file; it is not a site's data and proves nothing about one.
  records: 3 (3 ticks x 1 identities)
  wrote order-weld-below-limit-seed-2027.sample.jsonl
  wrote order-weld-below-limit-seed-2027.statements.jsonl
  wrote order-weld-below-limit-seed-2027.manifest.json

The statement file is an insert for the order's first reading and an update for each later one, because the scenario's database line names the order as its update_key (the shape simulator page has the key). A delay of 300 seconds sits between the statements.

cat "$WORK/files/order-weld-below-limit-seed-2027.statements.jsonl"
{"op":"insert","table":"order_status","row":{"order_id":"MD-2027-0301","status_code":0.0,"vendor":"Corvale Polymers","vendor_lot":"CP-88301","weld_strength_n":9.1,"cycle_seconds":1800.0,"updated_at":"2027-03-08T10:00:00Z"}}
{"op":"delay","seconds":300.0}
{"op":"update","table":"order_status","key":{"order_id":"MD-2027-0301"},"set":{"status_code":0.0,"vendor":"Corvale Polymers","vendor_lot":"CP-88301","weld_strength_n":7.9,"cycle_seconds":1800.0,"updated_at":"2027-03-08T10:05:00Z"}}
{"op":"delay","seconds":300.0}
{"op":"update","table":"order_status","key":{"order_id":"MD-2027-0301"},"set":{"status_code":1.0,"vendor":"Corvale Polymers","vendor_lot":"CP-88301","weld_strength_n":7.9,"cycle_seconds":1800.0,"updated_at":"2027-03-08T10:10:00Z"}}

The story is in three rows. The order is released at status 0 with a material lot and a weld of 9.1 newtons, which is inside the limit of 8.5 the config sets. Five minutes later its weld reads 7.9, under the limit. Five minutes after that its status goes to 1, which the layout's mapping reads as blocked. The scenario starts at 10:00 on purpose: the layout's own seed rows are stamped 09:15 and 09:20, and a Node that has already taken its first position at 09:20 would not see an order stamped at or before it.

The same scenario and seed give the same bytes. Writing it again into another directory gives files that are identical, byte for byte:

python -m engine.scenario_cli write "$SCENARIO" --out "$WORK/again" > /dev/null && cmp -s "$WORK/files/order-weld-below-limit-seed-2027.statements.jsonl" "$WORK/again/order-weld-below-limit-seed-2027.statements.jsonl" && cmp -s "$WORK/files/order-weld-below-limit-seed-2027.manifest.json" "$WORK/again/order-weld-below-limit-seed-2027.manifest.json"

The seed names the files and the manifest, and does not move a value here. The scenario adds no noise to the weld or the cycle time, so a different seed gives a differently named file with the same statements. That is on purpose: the third statement has to carry the same weld as the second, or the Node would see a new reading and judge it again.

python -m engine.scenario_cli write "$SCENARIO" --out "$WORK/other" --seed 7
Scenario order-weld-below-limit (order-weld-below-limit.scenario.jsonl), seed 7: synthetic data made from a scenario file; it is not a site's data and proves nothing about one.
  records: 3 (3 ticks x 1 identities)
  wrote order-weld-below-limit-seed-7.sample.jsonl
  wrote order-weld-below-limit-seed-7.statements.jsonl
  wrote order-weld-below-limit-seed-7.manifest.json

Checking the config

python -m engine.offline_check_cli examples/mes-database-log-site/mes-config.json node-types/mes
Offline check: the config is valid (Node Type MES).

The check reaches no database and no peer. A test also checks the config's mapping against the shipped MES dictionary, which reports the three values as unknown, and against the dictionary with the extension file added, which agrees.

Playing it into a stand-in

python -m engine.db_row_player_cli init order_status --target "$WORK/target.json"

Start the Node and let it make its first scan before the player writes anything. The config does not set start_from, so it takes its default of now, and the Node's first scan only notes the highest position in the table. A row written before that scan is a row that existed when the Node began, and it is not read. The Node then reads the stand-in once a second.

python -m engine.db_row_player_cli play "$WORK/files/order-weld-below-limit-seed-2027.statements.jsonl" --target "$WORK/target.json" --speed 1000

--speed 1000 shortens each 300-second pause to a third of a second. A Node reading once a second could miss rows, because an update replaces the row before the Node looks. Leave --speed out to play at the scenario's own pace, or give it a smaller number, when a Node is reading.

What the Node does with it

This page does not start a Node. A Node announces itself on the broker at the address in its environment, and one started carelessly on a machine that serves a site overwrites that site's retained identity message. The test behind this page, tests/test_mes_database_log_scenario.py, starts one inside the test suite, against a database of its own, with a real ERP answering over a loopback listener. It builds the Node from mes-config.json, with only the connection details of the test machine changed and the model switched off, and reads the stand-in as the player writes it. To start a Node yourself, see node-runtime.md and set the broker's address first.

After the player writesThe order's record holds
The insert in-progress, a weld of 9.10, the lot CP-88301 (it arrives padded to twelve characters), a cycle time of 1800
The first update in-progress, a weld of 7.90
The second update blocked, with blocked_reason quality hold
  • The status. The order reads in-progress, then in-progress again, then blocked, on one identity record, and the block carries a reason: the config's rule for status code 1 sets blocked_reason to quality hold, in words this invented site chose, so the order's record and its trail say why the source marks it blocked. Kindred reports the reason the mapping gives and does not decide it. A block is another order_release entry in the Node's own log, one for each row the Node read. There is no order_blocked entry. Those entries carry the id of the queued row and not the order's id, so the order's trail does not show them: what the trail shows of the status change is a reconciliation entry, and the record's status reads blocked.
  • The weld. The reading of 7.9 under the limit of 8.5 queues one deviation that names the order. Case Triage turns it into one entry in the order's trail and a pending sign-off for a person. The status update that follows carries the same 7.9, which the Node has already judged, so it flags nothing more.
  • The lot. The order gets one material link, with the lot CP-88301 and the padding stripped. A link is written once for each material of an order, however many rows repeat it.
  • The cycle time. The reading of 1800 seconds is priced once against the ERP's standard cost. The test's ERP answers with half an hour a unit, so the order is on standard, the variance is nothing, and no deviation is queued. The milestone is reported to the ERP once.
  • The ERP hears each status. It is told in-progress, in-progress and blocked.

Limits

  • The data is invented, and it is one order. Nothing here says a plant's MES looks like this, or that the checks suit a plant.
  • The config is a development-mode config. It declares the ERP as a plain-HTTP peer on this machine, which a Node in production mode refuses, and its inference endpoint and model name are placeholders. The test runs with the model off.
  • With no ERP answering, the cost check waits. The peer the config names has to exist for the cycle time to be priced. If it does not, the check is set aside and tried again every 30 seconds, and the order's status and the other checks are not held up.
  • The shortage task is not shown here. The ERP finding this order through its material link has its own test.
  • The generator makes readings, not an MES. The scenario's statements are time-ordered readings of one row. A real MES's database has the habits of its own application.

Release: v0.11.0