Cookwala / حزمة التطوير والسيناريوهات / 023

An oven trace against the bake envelope and a recipe target

Baking is air at 120 to 250 degC. The kofta recipe asks for 200 plus or minus 10. The check separates leaving the band from missing the target, and treats the preheat as warm-up.

الفئة: appliance maker · الهدف: روبوتات في خدمة الناس · المستوى: beginner

اقرأ أولًا: /docs/CORE/ /docs/QUICKSTART/

الخطوات

  1. Preheat from 25, then 180, 198, 203 degC: the band is reached and the target held. checkEnvelope

  2. The oven overshoots to 215 degC: still inside the envelope, but the target was missed. checkEnvelope

  3. The door was open for five minutes and the air fell to 115 degC: left the envelope. No target given, so targetOk is null. checkEnvelope

  4. An oven that only reached 110 degC never baked. checkEnvelope

النتيجة

You can grade an oven's log into ok, missed_target, left_envelope and never_reached_envelope, the same four words every executor uses. Next: scenario 032 plans a recipe on the oven preset.

سطر الأوامر

printf '[{"t": 0, "tempC": 25}, {"t": 30, "tempC": 180}, {"t": 60, "tempC": 198}, {"t": 90, "tempC": 203}]' > trace.json && cookwala envelope cw.op.bake trace.json --target 200 --tolerance 10
printf '[{"t": 0, "tempC": 25}, {"t": 30, "tempC": 180}, {"t": 60, "tempC": 200}, {"t": 90, "tempC": 215}]' > trace.json && cookwala envelope cw.op.bake trace.json --target 200 --tolerance 10
printf '[{"t": 0, "tempC": 200}, {"t": 30, "tempC": 115}, {"t": 60, "tempC": 200}]' > trace.json && cookwala envelope cw.op.bake trace.json

المخرجات المسجلة

الحالة: ok

[1] checkEnvelope: {"envelopeOk": true, "targetOk": true, "reason": "ok"}
[2] checkEnvelope: {"envelopeOk": true, "targetOk": false, "reason": "missed_target"}
[3] checkEnvelope: {"envelopeOk": false, "targetOk": null, "reason": "left_envelope"}
[4] checkEnvelope: {"envelopeOk": false, "targetOk": null, "reason": "never_reached_envelope"}

الكود

التشغيل: python scenarios/out/023-bake-trace-with-a-target/python.py

# Scenario 023: An oven trace against the bake envelope and a recipe target
# Baking is air at 120 to 250 degC. The kofta recipe asks for 200 plus or minus 10. The check separates leaving the band from missing the target, and treats the preheat as warm-up.
# 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: Preheat from 25, then 180, 198, 203 degC: the band is reached and the target held.
ok = c.check_envelope("cw.op.bake", [{"t": 0, "tempC": 25}, {"t": 300, "tempC": 180}, {"t": 600, "tempC": 198}, {"t": 900, "tempC": 203}], {"value": 200, "tolerance": 10})
assert pick(ok, "envelopeOk") == True, pick(ok, "envelopeOk")
print("ok", "envelopeOk", "=", True)
assert pick(ok, "targetOk") == True, pick(ok, "targetOk")
print("ok", "targetOk", "=", True)
assert pick(ok, "reason") == "ok", pick(ok, "reason")
print("ok", "reason", "=", "ok")

# Step 2: The oven overshoots to 215 degC: still inside the envelope, but the target was missed.
overshoot = c.check_envelope("cw.op.bake", [{"t": 0, "tempC": 25}, {"t": 300, "tempC": 180}, {"t": 600, "tempC": 200}, {"t": 900, "tempC": 215}], {"value": 200, "tolerance": 10})
assert pick(overshoot, "envelopeOk") == True, pick(overshoot, "envelopeOk")
print("ok", "envelopeOk", "=", True)
assert pick(overshoot, "targetOk") == False, pick(overshoot, "targetOk")
print("ok", "targetOk", "=", False)
assert pick(overshoot, "reason") == "missed_target", pick(overshoot, "reason")
print("ok", "reason", "=", "missed_target")

# Step 3: The door was open for five minutes and the air fell to 115 degC: left the envelope. No target given, so targetOk is null.
doorOpen = c.check_envelope("cw.op.bake", [{"t": 0, "tempC": 200}, {"t": 300, "tempC": 115}, {"t": 600, "tempC": 200}])
assert pick(doorOpen, "envelopeOk") == False, pick(doorOpen, "envelopeOk")
print("ok", "envelopeOk", "=", False)
assert pick(doorOpen, "targetOk") == None, pick(doorOpen, "targetOk")
print("ok", "targetOk", "=", None)
assert pick(doorOpen, "reason") == "left_envelope", pick(doorOpen, "reason")
print("ok", "reason", "=", "left_envelope")

# Step 4: An oven that only reached 110 degC never baked.
cold = c.check_envelope("cw.op.bake", [{"t": 0, "tempC": 25}, {"t": 300, "tempC": 60}, {"t": 600, "tempC": 110}])
assert pick(cold, "envelopeOk") == False, pick(cold, "envelopeOk")
print("ok", "envelopeOk", "=", False)
assert pick(cold, "reason") == "never_reached_envelope", pick(cold, "reason")
print("ok", "reason", "=", "never_reached_envelope")

print("scenario complete")

scenarios/023-bake-trace-with-a-target.json

السابق: 022 التالي: 024