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 / 025
A recipe target outside its operation's envelope is invalid whatever the readings
A recipe may narrow an envelope, never widen it. A simmer at 100 degC, a deep fry at 195 degC or a bake at 110 degC fail before a single reading is looked at.
Leia primeiro: /docs/CORE/ /docs/QUICKSTART/
Passos
Simmer with a target of 100 plus or minus 2: 100 is a boil.
checkEnvelopeDeep fry at 195 degC: above the 190 ceiling of the band.
checkEnvelopeBake at 110 degC: below the 120 floor.
checkEnvelopeThe corrected simmer target, 94 plus or minus 3, passes with the same kind of trace.
checkEnvelope
Resultado
You know the rule the validator applies to every recipe: targets live inside envelopes. A publisher fixes the recipe; a device never stretches the band. Next: scenario 026 walks a ladder rung by rung.
Linha de comando
printf '[{"t": 0, "tempC": 90}]' > trace.json && cookwala envelope cw.op.simmer trace.json --target 100 --tolerance 2
printf '[{"t": 0, "tempC": 170}]' > trace.json && cookwala envelope cw.op.deep_fry trace.json --target 195 --tolerance 5
cookwala validate # the repository validator applies the same rule to every recipe targetSaída gravada
Status: ok
[1] checkEnvelope: {"envelopeOk": false, "targetOk": false, "reason": "target_outside_envelope"}
[2] checkEnvelope: {"envelopeOk": false, "targetOk": false, "reason": "target_outside_envelope"}
[3] checkEnvelope: {"envelopeOk": false, "targetOk": false, "reason": "target_outside_envelope"}
[4] checkEnvelope: {"envelopeOk": true, "targetOk": true, "reason": "ok"}Código
Executar: python scenarios/out/025-target-outside-envelope/python.py
# Scenario 025: A recipe target outside its operation's envelope is invalid whatever the readings
# A recipe may narrow an envelope, never widen it. A simmer at 100 degC, a deep fry at 195 degC or a bake at 110 degC fail before a single reading is looked at.
# 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: Simmer with a target of 100 plus or minus 2: 100 is a boil.
simmer = c.check_envelope("cw.op.simmer", [{"t": 0, "tempC": 90}], {"value": 100, "tolerance": 2})
assert pick(simmer, "envelopeOk") == False, pick(simmer, "envelopeOk")
print("ok", "envelopeOk", "=", False)
assert pick(simmer, "targetOk") == False, pick(simmer, "targetOk")
print("ok", "targetOk", "=", False)
assert pick(simmer, "reason") == "target_outside_envelope", pick(simmer, "reason")
print("ok", "reason", "=", "target_outside_envelope")
# Step 2: Deep fry at 195 degC: above the 190 ceiling of the band.
fry = c.check_envelope("cw.op.deep_fry", [{"t": 0, "tempC": 170}], {"value": 195, "tolerance": 5})
assert pick(fry, "envelopeOk") == False, pick(fry, "envelopeOk")
print("ok", "envelopeOk", "=", False)
assert pick(fry, "targetOk") == False, pick(fry, "targetOk")
print("ok", "targetOk", "=", False)
assert pick(fry, "reason") == "target_outside_envelope", pick(fry, "reason")
print("ok", "reason", "=", "target_outside_envelope")
# Step 3: Bake at 110 degC: below the 120 floor.
bake = c.check_envelope("cw.op.bake", [{"t": 0, "tempC": 200}], {"value": 110, "tolerance": 5})
assert pick(bake, "envelopeOk") == False, pick(bake, "envelopeOk")
print("ok", "envelopeOk", "=", False)
assert pick(bake, "targetOk") == False, pick(bake, "targetOk")
print("ok", "targetOk", "=", False)
assert pick(bake, "reason") == "target_outside_envelope", pick(bake, "reason")
print("ok", "reason", "=", "target_outside_envelope")
# Step 4: The corrected simmer target, 94 plus or minus 3, passes with the same kind of trace.
fixed = c.check_envelope("cw.op.simmer", [{"t": 0, "tempC": 90}, {"t": 30, "tempC": 94}], {"value": 94, "tolerance": 3})
assert pick(fixed, "envelopeOk") == True, pick(fixed, "envelopeOk")
print("ok", "envelopeOk", "=", True)
assert pick(fixed, "targetOk") == True, pick(fixed, "targetOk")
print("ok", "targetOk", "=", True)
assert pick(fixed, "reason") == "ok", pick(fixed, "reason")
print("ok", "reason", "=", "ok")
print("scenario complete")