Cookwala / SDK and scenarios / 026
The boiling ladder rung by rung: thermometer, boil detector, estimate, time
Boiling is unattended-safe, so its ladder ends in time. Walk it with different sensor sets and see that a pan thermometer does not verify a pot of water.
Read first: /docs/CORE/ /docs/QUICKSTART/
Steps
A liquid thermometer is the first rung.
ladderA boil detector (bubbles, sound or steam) is the second.
ladderNeither, estimates allowed: a logged model estimate.
ladderNeither, estimates forbidden: time alone.
ladderA pan-surface thermometer is not on the boiling ladder, so it changes nothing: time again.
ladderFour rungs, in order.
Outcome
You can choose sensors for a product by reading ladders: a boil detector is enough for boiling, a pan thermometer is not. Next: scenario 027 lists the operations that never fall back to time.
Command line
curl -s -X POST http://localhost:7878/v1/tools/ladder -H 'Content-Type: application/json' -d '{"op": "cw.op.boil", "sensors": ["cw.sense.boil_detect"], "allowModel": true, "humanPresent": false}'
curl -s -X POST http://localhost:7878/v1/tools/ladder -H 'Content-Type: application/json' -d '{"op": "cw.op.boil", "sensors": ["cw.sense.pan_surface_temp"], "allowModel": false, "humanPresent": false}'Recorded output
Status: ok
[1] ladder: "cw.sense.liquid_temp"
[2] ladder: "cw.sense.boil_detect"
[3] ladder: "model"
[4] ladder: "time"
[5] ladder: "time"Code
Run: python scenarios/out/026-boil-ladder-rung-by-rung/python.py
# Scenario 026: The boiling ladder rung by rung: thermometer, boil detector, estimate, time
# Boiling is unattended-safe, so its ladder ends in time. Walk it with different sensor sets and see that a pan thermometer does not verify a pot of water.
# 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 liquid thermometer is the first rung.
thermometer = c.ladder("cw.op.boil", ["cw.sense.liquid_temp"], True, False)
# Step 2: A boil detector (bubbles, sound or steam) is the second.
detector = c.ladder("cw.op.boil", ["cw.sense.boil_detect"], True, False)
# Step 3: Neither, estimates allowed: a logged model estimate.
estimate = c.ladder("cw.op.boil", [], True, False)
# Step 4: Neither, estimates forbidden: time alone.
time = c.ladder("cw.op.boil", [], False, False)
# Step 5: A pan-surface thermometer is not on the boiling ladder, so it changes nothing: time again.
wrongSensor = c.ladder("cw.op.boil", ["cw.sense.pan_surface_temp"], False, False)
# Step 6: Four rungs, in order.
assert thermometer == "cw.sense.liquid_temp", thermometer
print("ok", "thermometer", "=", "cw.sense.liquid_temp")
assert detector == "cw.sense.boil_detect", detector
print("ok", "detector", "=", "cw.sense.boil_detect")
assert estimate == "model", estimate
print("ok", "estimate", "=", "model")
assert time == "time", time
print("ok", "time", "=", "time")
assert wrongSensor == "time", wrongSensor
print("ok", "wrongSensor", "=", "time")
print("scenario complete")