Cette page a été traduite par une machine et n'a pas encore été révisée par une personne. L'anglais est la référence ; les corrections sont les bienvenues sur GitHub. GitHub

Cookwala / SDK et scénarios / 093

Fifty-seven operations, thirty-two with envelopes, one legacy placeholder

Read the operation vocabulary from the hub: 57 entries, 32 of which carry a thermal envelope with a sensor ladder; the last is cw.op.legacy_step, the placeholder for unclassified V0 imports (RFC-0009).

Audience: developer · Objectif: Des robots pour les gens · Niveau: beginner

Lire d'abord: /docs/CORE/ /docs/CORE/

Étapes

  1. Fetch vocab/ops.json through the hub. getOps

  2. Deep frying's envelope: oil between 160 and 190 degrees C, one rung on the ladder (an oil thermometer), never unattended.

  3. Dispensing has no envelope: envelopes belong to operations that heat, cool or hold.

Résultat

You know where envelopes live and which operation an importer uses when it cannot classify a step. Next: 094 and 095 validate the supply and fleet documents.

Ligne de commande

curl -s ${COOKWALA_HUB:-http://localhost:7878}/v1/tools/vocab/ops | jq '.entries | length'
curl -s ${COOKWALA_HUB:-http://localhost:7878}/v1/tools/vocab/ops | jq '[.entries[] | select(.envelope)] | length'

Sortie enregistrée

Statut: ok

[1] getOps: {"name": "ops", "version": "0.2.0", "entries": [{"id": "cw.op.dispense", "label": {"en": "Dispense / measure", "ar": "قياس وإضافة"}, "definition": "Measure an ingredient by mass, volume or count and add it to a target.", "classes": ["cw.opfamily.handle"], "paramsSchema": {"type": "object", "properties": {"precision": {"type": "number"}}}, "sensors": ["cw.sense.mass"], "links": {"ieee1872": "IEEE 1872.1-2024 Task (to be mapped)"}}, {"id": "cw.op.transfer", "label": {"en": "Transfer", "ar": "نقل"}, "definition": "Move food or a vessel's contents from one place to another.", "classes": ["cw.opfam…

Code

Exécuter: python scenarios/out/093-operation-vocabulary-envelopes-and-legacy-step/python.py

# Scenario 093: Fifty-seven operations, thirty-two with envelopes, one legacy placeholder
# Read the operation vocabulary from the hub: 57 entries, 32 of which carry a thermal envelope with a sensor ladder; the last is cw.op.legacy_step, the placeholder for unclassified V0 imports (RFC-0009).
# 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: Fetch vocab/ops.json through the hub.
ops = c.get_ops()
assert pick(ops, "name") == "ops", pick(ops, "name")
print("ok", "name", "=", "ops")
assert pick(ops, "version") == "0.2.0", pick(ops, "version")
print("ok", "version", "=", "0.2.0")
assert pick(ops, "entries.length") == 57, pick(ops, "entries.length")
print("ok", "entries.length", "=", 57)
assert pick(ops, "entries[56].id") == "cw.op.legacy_step", pick(ops, "entries[56].id")
print("ok", "entries[56].id", "=", "cw.op.legacy_step")

# Step 2: Deep frying's envelope: oil between 160 and 190 degrees C, one rung on the ladder (an oil thermometer), never unattended.
assert pick(ops, "entries[30].id") == "cw.op.deep_fry", pick(ops, "entries[30].id")
print("ok", "entries[30].id", "=", "cw.op.deep_fry")
assert pick(ops, "entries[30].envelope.tempC") == {"min": 160, "max": 190}, pick(ops, "entries[30].envelope.tempC")
print("ok", "entries[30].envelope.tempC", "=", {"min": 160, "max": 190})
assert pick(ops, "entries[30].envelope.sensorLadder") == ["cw.sense.oil_temp"], pick(ops, "entries[30].envelope.sensorLadder")
print("ok", "entries[30].envelope.sensorLadder", "=", ["cw.sense.oil_temp"])
assert pick(ops, "entries[30].envelope.unattended") == False, pick(ops, "entries[30].envelope.unattended")
print("ok", "entries[30].envelope.unattended", "=", False)

# Step 3: Dispensing has no envelope: envelopes belong to operations that heat, cool or hold.
assert pick(ops, "entries[0].id") == "cw.op.dispense", pick(ops, "entries[0].id")
print("ok", "entries[0].id", "=", "cw.op.dispense")
assert pick(ops, "entries[0].envelope") == None, pick(ops, "entries[0].envelope")
print("ok", "entries[0].envelope", "=", None)

print("scenario complete")

scenarios/093-operation-vocabulary-envelopes-and-legacy-step.json

Précédent: 092 Suivant: 094