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 / 009
Ask the sensor ladder which rung a device can satisfy for simmering, sauteing and deep frying
Each operation envelope lists ways to verify the step, best first. The ladder tool returns the first rung a device can satisfy, or null when the step must be refused.
Leia primeiro: /docs/CORE/ /docs/QUICKSTART/
Passos
Simmering with a liquid thermometer: the sensor is the first rung.
ladderNo thermometer, estimates allowed: a logged model estimate.
ladderNo thermometer, no estimates: simmering may run on time alone, because it is unattended-safe.
ladderSauteing with nothing and nobody: null. Its last rung is a person watching.
ladderThe same with a person present: the human rung.
ladderDeep frying with a person present but no oil thermometer: still null. The ladder has one rung.
ladderThe six answers.
Resultado
You can predict, per operation, which sensors a device needs so that a plan does not fall back to a person. Next: scenario 026 walks the boiling ladder rung by rung.
Linha de comando
curl -s -X POST http://localhost:7878/v1/tools/ladder -H 'Content-Type: application/json' -d '{"op": "cw.op.simmer", "sensors": ["cw.sense.liquid_temp"], "allowModel": true, "humanPresent": false}'
curl -s -X POST http://localhost:7878/v1/tools/ladder -H 'Content-Type: application/json' -d '{"op": "cw.op.saute", "sensors": [], "allowModel": false, "humanPresent": false}'
curl -s -X POST http://localhost:7878/v1/tools/ladder -H 'Content-Type: application/json' -d '{"op": "cw.op.deep_fry", "sensors": [], "allowModel": true, "humanPresent": true}'Saída gravada
Status: ok
[1] ladder: "cw.sense.liquid_temp"
[2] ladder: "model"
[3] ladder: "time"
[4] ladder: null
[5] ladder: "human"
[6] ladder: nullCódigo
Executar: python scenarios/out/009-sensor-ladder-for-several-ops/python.py
# Scenario 009: Ask the sensor ladder which rung a device can satisfy for simmering, sauteing and deep frying
# Each operation envelope lists ways to verify the step, best first. The ladder tool returns the first rung a device can satisfy, or null when the step must be refused.
# 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: Simmering with a liquid thermometer: the sensor is the first rung.
simmerSensor = c.ladder("cw.op.simmer", ["cw.sense.liquid_temp"], True, False)
# Step 2: No thermometer, estimates allowed: a logged model estimate.
simmerModel = c.ladder("cw.op.simmer", [], True, False)
# Step 3: No thermometer, no estimates: simmering may run on time alone, because it is unattended-safe.
simmerTime = c.ladder("cw.op.simmer", [], False, False)
# Step 4: Sauteing with nothing and nobody: null. Its last rung is a person watching.
sauteAlone = c.ladder("cw.op.saute", [], False, False)
# Step 5: The same with a person present: the human rung.
sauteHuman = c.ladder("cw.op.saute", [], False, True)
# Step 6: Deep frying with a person present but no oil thermometer: still null. The ladder has one rung.
fryHuman = c.ladder("cw.op.deep_fry", [], True, True)
# Step 7: The six answers.
assert simmerSensor == "cw.sense.liquid_temp", simmerSensor
print("ok", "simmerSensor", "=", "cw.sense.liquid_temp")
assert simmerModel == "model", simmerModel
print("ok", "simmerModel", "=", "model")
assert simmerTime == "time", simmerTime
print("ok", "simmerTime", "=", "time")
assert sauteAlone == None, sauteAlone
print("ok", "sauteAlone", "=", None)
assert sauteHuman == "human", sauteHuman
print("ok", "sauteHuman", "=", "human")
assert fryHuman == None, fryHuman
print("ok", "fryHuman", "=", None)
print("scenario complete")