Esta página foi traduzida por máquina e ainda não foi revisada por uma pessoa. O inglês é a referência; correções são bem-vindas no GitHub. GitHub
Cookwala / SDK e cenários / 038
Cold chain in the kitchen: chilling and marinating traces
Chilling and marinating happen at 0 to 5 degC. A fridge that never gets there, or a marinade that warms to 7 degC, fails the check; a fridge thermometer is the first rung for both.
Leia primeiro: /docs/CORE/ /docs/QUICKSTART/
Passos
A salad cooling from 20 to 8, 4 and 3 degC: the band is reached and held.
checkEnvelopeA fridge that stays at 7 degC: never reached the band.
checkEnvelopeA marinade at 4 degC that warms to 7 degC after two hours: left the envelope.
checkEnvelopeBoth operations share the 0 to 5 degC band; marinating names the time-temperature hazard.
getOpsA fridge thermometer is the first rung for chilling.
ladderThe fridge rung.
Resultado
You can check cold steps with the same tool as hot ones and advise which sensor a kitchen needs for them. The same bands return in the humanitarian profile's cold-chain checks.
Linha de comando
printf '[{"t": 0, "tempC": 20}, {"t": 30, "tempC": 8}, {"t": 60, "tempC": 4}, {"t": 90, "tempC": 3}]' > trace.json && cookwala envelope cw.op.chill trace.json
printf '[{"t": 0, "tempC": 4}, {"t": 30, "tempC": 4}, {"t": 60, "tempC": 7}]' > trace.json && cookwala envelope cw.op.marinate trace.json
curl -s http://localhost:7878/v1/tools/vocab/opsSaída gravada
Status: ok
[1] checkEnvelope: {"envelopeOk": true, "targetOk": null, "reason": "ok"}
[2] checkEnvelope: {"envelopeOk": false, "targetOk": null, "reason": "never_reached_envelope"}
[3] checkEnvelope: {"envelopeOk": false, "targetOk": null, "reason": "left_envelope"}
[4] getOps: {"name": "ops", "version": "0.2.0", "entries": [{"id": "cw.op.dispense", "label": {"en": "Dispense / measure", "ar": "قياس وإضافة"}, "definition": "Measure an ingredient by mass, volume or count and add it to a target.", "classes": ["cw.opfamily.handle"], "paramsSchema": {"type": "object", "properties": {"precision": {"type": "number"}}}, "sensors": ["cw.sense.mass"], "links": {"ieee1872": "IEEE 1872.1-2024 Task (to be mapped)"}}, {"id": "cw.op.transfer", "label": {"en": "Transfer", "ar": "نقل"}, "definition": "Move food or a vessel's contents from one place to another.", "classes": ["cw.opfam…
[5] ladder: "cw.sense.fridge_temp"Código
Executar: python scenarios/out/038-cold-chain-in-the-kitchen/python.py
# Scenario 038: Cold chain in the kitchen: chilling and marinating traces
# Chilling and marinating happen at 0 to 5 degC. A fridge that never gets there, or a marinade that warms to 7 degC, fails the check; a fridge thermometer is the first rung for both.
# Run a hub first: python hub/cookwala_hub.py --recipes examples
import json, os
from cookwala.client import CookwalaClient, CookwalaProblem
def load(path):
with open(path, encoding="utf-8") as f:
return json.load(f)
def pick(obj, path):
for part in path.replace("]", "").replace("[", ".").split("."):
obj = obj[int(part)] if part.isdigit() else (len(obj) if part == "length" else obj.get(part))
return obj
c = CookwalaClient(os.environ.get("COOKWALA_HUB", "http://localhost:7878"))
# Step 1: A salad cooling from 20 to 8, 4 and 3 degC: the band is reached and held.
ok = c.check_envelope("cw.op.chill", [{"t": 0, "tempC": 20}, {"t": 600, "tempC": 8}, {"t": 1200, "tempC": 4}, {"t": 1800, "tempC": 3}])
assert pick(ok, "envelopeOk") == True, pick(ok, "envelopeOk")
print("ok", "envelopeOk", "=", True)
assert pick(ok, "reason") == "ok", pick(ok, "reason")
print("ok", "reason", "=", "ok")
# Step 2: A fridge that stays at 7 degC: never reached the band.
warmFridge = c.check_envelope("cw.op.chill", [{"t": 0, "tempC": 20}, {"t": 600, "tempC": 8}, {"t": 1200, "tempC": 7}])
assert pick(warmFridge, "envelopeOk") == False, pick(warmFridge, "envelopeOk")
print("ok", "envelopeOk", "=", False)
assert pick(warmFridge, "reason") == "never_reached_envelope", pick(warmFridge, "reason")
print("ok", "reason", "=", "never_reached_envelope")
# Step 3: A marinade at 4 degC that warms to 7 degC after two hours: left the envelope.
marinade = c.check_envelope("cw.op.marinate", [{"t": 0, "tempC": 4}, {"t": 3600, "tempC": 4}, {"t": 7200, "tempC": 7}])
assert pick(marinade, "envelopeOk") == False, pick(marinade, "envelopeOk")
print("ok", "envelopeOk", "=", False)
assert pick(marinade, "reason") == "left_envelope", pick(marinade, "reason")
print("ok", "reason", "=", "left_envelope")
# Step 4: Both operations share the 0 to 5 degC band; marinating names the time-temperature hazard.
ops = c.get_ops()
assert pick(ops, "entries[47].id") == "cw.op.chill", pick(ops, "entries[47].id")
print("ok", "entries[47].id", "=", "cw.op.chill")
assert pick(ops, "entries[47].envelope.tempC.max") == 5, pick(ops, "entries[47].envelope.tempC.max")
print("ok", "entries[47].envelope.tempC.max", "=", 5)
assert pick(ops, "entries[17].id") == "cw.op.marinate", pick(ops, "entries[17].id")
print("ok", "entries[17].id", "=", "cw.op.marinate")
assert pick(ops, "entries[17].envelope.tempC.max") == 5, pick(ops, "entries[17].envelope.tempC.max")
print("ok", "entries[17].envelope.tempC.max", "=", 5)
assert pick(ops, "entries[17].envelope.hazards[0]") == "cw.hz.time_temperature", pick(ops, "entries[17].envelope.hazards[0]")
print("ok", "entries[17].envelope.hazards[0]", "=", "cw.hz.time_temperature")
# Step 5: A fridge thermometer is the first rung for chilling.
fridge = c.ladder("cw.op.chill", ["cw.sense.fridge_temp"], False, False)
# Step 6: The fridge rung.
assert fridge == "cw.sense.fridge_temp", fridge
print("ok", "fridge", "=", "cw.sense.fridge_temp")
print("scenario complete")