Diese Seite wurde maschinell übersetzt und wurde noch nicht von einer Person überprüft. Englisch ist die Referenz; Korrekturen auf GitHub sind willkommen. GitHub
Cookwala / SDK und Szenarien / 021
Water boils lower at altitude: the same trace at sea level and at 1,500 m
Water and steam bands shift by minus 1 degC per 300 m. A reading of 97 degC is not a boil at sea level and is one in a mountain kitchen; a reading of 100 degC at 1,500 m is something a sensor should not see.
Zuerst lesen: /docs/CORE/ /docs/QUICKSTART/
Schritte
A pot that holds at 97 degC at sea level never reaches the 98 to 102 band.
checkEnvelopeThe same readings at 1,500 m: the band is 93 to 97, and the pot is boiling.
checkEnvelopeA reading of 100 degC at 1,500 m is above the shifted band: water cannot be that hot there, so the sensor or the medium is in question.
checkEnvelopeAt 2,400 m with a recipe target of 94 plus or minus 1: the target is checked inside the shifted band.
checkEnvelope
Ergebnis
You can validate boiling and simmering traces from kitchens at any altitude, and you have a test for sensors that read what physics forbids. Next: scenario 022 checks hot oil.
Kommandozeile
printf '[{"t": 0, "tempC": 80}, {"t": 30, "tempC": 97}, {"t": 60, "tempC": 97}]' > trace.json && cookwala envelope cw.op.boil trace.json
printf '[{"t": 0, "tempC": 80}, {"t": 30, "tempC": 97}, {"t": 60, "tempC": 97}]' > trace.json && cookwala envelope cw.op.boil trace.json --altitude 1500
printf '[{"t": 0, "tempC": 80}, {"t": 30, "tempC": 100}, {"t": 60, "tempC": 100}]' > trace.json && cookwala envelope cw.op.boil trace.json --altitude 1500Aufgezeichnete Ausgabe
Status: ok
[1] checkEnvelope: {"envelopeOk": false, "targetOk": null, "reason": "never_reached_envelope"}
[2] checkEnvelope: {"envelopeOk": true, "targetOk": null, "reason": "ok"}
[3] checkEnvelope: {"envelopeOk": false, "targetOk": null, "reason": "never_reached_envelope"}
[4] checkEnvelope: {"envelopeOk": true, "targetOk": true, "reason": "ok"}Code
Ausführen: python scenarios/out/021-boiling-at-altitude/python.py
# Scenario 021: Water boils lower at altitude: the same trace at sea level and at 1,500 m
# Water and steam bands shift by minus 1 degC per 300 m. A reading of 97 degC is not a boil at sea level and is one in a mountain kitchen; a reading of 100 degC at 1,500 m is something a sensor should not see.
# 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 pot that holds at 97 degC at sea level never reaches the 98 to 102 band.
seaLevel = c.check_envelope("cw.op.boil", [{"t": 0, "tempC": 80}, {"t": 60, "tempC": 97}, {"t": 120, "tempC": 97}])
assert pick(seaLevel, "envelopeOk") == False, pick(seaLevel, "envelopeOk")
print("ok", "envelopeOk", "=", False)
assert pick(seaLevel, "reason") == "never_reached_envelope", pick(seaLevel, "reason")
print("ok", "reason", "=", "never_reached_envelope")
# Step 2: The same readings at 1,500 m: the band is 93 to 97, and the pot is boiling.
mountain = c.check_envelope("cw.op.boil", [{"t": 0, "tempC": 80}, {"t": 60, "tempC": 97}, {"t": 120, "tempC": 97}], None, 1500)
assert pick(mountain, "envelopeOk") == True, pick(mountain, "envelopeOk")
print("ok", "envelopeOk", "=", True)
assert pick(mountain, "reason") == "ok", pick(mountain, "reason")
print("ok", "reason", "=", "ok")
# Step 3: A reading of 100 degC at 1,500 m is above the shifted band: water cannot be that hot there, so the sensor or the medium is in question.
tooHot = c.check_envelope("cw.op.boil", [{"t": 0, "tempC": 80}, {"t": 60, "tempC": 100}, {"t": 120, "tempC": 100}], None, 1500)
assert pick(tooHot, "envelopeOk") == False, pick(tooHot, "envelopeOk")
print("ok", "envelopeOk", "=", False)
assert pick(tooHot, "reason") == "never_reached_envelope", pick(tooHot, "reason")
print("ok", "reason", "=", "never_reached_envelope")
# Step 4: At 2,400 m with a recipe target of 94 plus or minus 1: the target is checked inside the shifted band.
highTarget = c.check_envelope("cw.op.boil", [{"t": 0, "tempC": 95}, {"t": 60, "tempC": 94}], {"value": 94, "tolerance": 1}, 2400)
assert pick(highTarget, "envelopeOk") == True, pick(highTarget, "envelopeOk")
print("ok", "envelopeOk", "=", True)
assert pick(highTarget, "targetOk") == True, pick(highTarget, "targetOk")
print("ok", "targetOk", "=", True)
assert pick(highTarget, "reason") == "ok", pick(highTarget, "reason")
print("ok", "reason", "=", "ok")
print("scenario complete")