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 / 027
Operations that never fall back to time: toasting, reducing, cutting
Operations that need constant attention end their ladder with a person, not a timer. Without the sensor and without the person the answer is null, and a dry run refuses the step.
Leia primeiro: /docs/CORE/ /docs/QUICKSTART/
Passos
Toasting, no sensor, no person: null. Its ladder has no model rung either.
ladderToasting with a person: the human rung.
ladderToasting with a colour camera: the sensor rung, no person needed for verification.
ladderReducing a sauce without a thermometer, a scale or a person: null.
ladderA scale verifies a reduction by mass.
ladderCutting with no camera and nobody present: null.
ladderThree nulls and three rungs.
Resultado
You can separate the vocabulary into operations a timer may verify and operations that need a sensor or a person, which is the first question for any unattended-cooking study. Next: scenario 030 shows the refusal this produces in a dry run.
Linha de comando
curl -s -X POST http://localhost:7878/v1/tools/ladder -H 'Content-Type: application/json' -d '{"op": "cw.op.toast", "sensors": [], "allowModel": true, "humanPresent": false}'
curl -s -X POST http://localhost:7878/v1/tools/ladder -H 'Content-Type: application/json' -d '{"op": "cw.op.reduce", "sensors": ["cw.sense.mass"], "allowModel": false, "humanPresent": false}'Saída gravada
Status: ok
[1] ladder: null
[2] ladder: "human"
[3] ladder: "cw.sense.color_vision"
[4] ladder: null
[5] ladder: "cw.sense.mass"
[6] ladder: nullCódigo
Executar: python scenarios/out/027-ops-that-never-fall-back-to-time/python.py
# Scenario 027: Operations that never fall back to time: toasting, reducing, cutting
# Operations that need constant attention end their ladder with a person, not a timer. Without the sensor and without the person the answer is null, and a dry run refuses the step.
# 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: Toasting, no sensor, no person: null. Its ladder has no model rung either.
toastAlone = c.ladder("cw.op.toast", [], True, False)
# Step 2: Toasting with a person: the human rung.
toastHuman = c.ladder("cw.op.toast", [], True, True)
# Step 3: Toasting with a colour camera: the sensor rung, no person needed for verification.
toastCamera = c.ladder("cw.op.toast", ["cw.sense.color_vision"], False, False)
# Step 4: Reducing a sauce without a thermometer, a scale or a person: null.
reduceAlone = c.ladder("cw.op.reduce", [], False, False)
# Step 5: A scale verifies a reduction by mass.
reduceScale = c.ladder("cw.op.reduce", ["cw.sense.mass"], False, False)
# Step 6: Cutting with no camera and nobody present: null.
cutAlone = c.ladder("cw.op.cut", [], True, False)
# Step 7: Three nulls and three rungs.
assert toastAlone == None, toastAlone
print("ok", "toastAlone", "=", None)
assert toastHuman == "human", toastHuman
print("ok", "toastHuman", "=", "human")
assert toastCamera == "cw.sense.color_vision", toastCamera
print("ok", "toastCamera", "=", "cw.sense.color_vision")
assert reduceAlone == None, reduceAlone
print("ok", "reduceAlone", "=", None)
assert reduceScale == "cw.sense.mass", reduceScale
print("ok", "reduceScale", "=", "cw.sense.mass")
assert cutAlone == None, cutAlone
print("ok", "cutAlone", "=", None)
print("scenario complete")