Esta página fue traducida por una máquina y aún no ha sido revisada por una persona. El inglés es la referencia; las correcciones son bienvenidas en GitHub. GitHub
Cookwala / SDK y escenarios / 085
A second robot learns where not to move, never when people are home
Another robot in the same home may receive movement, quiet, safe-zone, pet-storage and equipment constraints. The no-movement zone is derived from the schedule and the hallway traffic facet without revealing either. A role that is not in the roles file receives nothing.
Leer primero: /docs/HOUSEHOLD-CONTEXT/ /trust/
Pasos
Derive the other-robot view of the example household.
deriveConstraintsThe no-movement zone comes from the household schedule and the observed hallway traffic; the constraint says where, not when the children come home.
A role name that is not in profiles/household/recipient-roles.json has an empty allow-list: the roles file is an allow-list, not a default.
deriveConstraints
Resultado
Two robots from different makers can share a kitchen through constraints without sharing the household's facts. Next: 086 reads the travel rules behind these answers.
Línea de comandos
cookwala constraints examples/household/context.json --role other_robot
cookwala constraints examples/household/context.json --role visitor_robotSalida grabada
Estado: ok
[1] deriveConstraints: {"constraints": [{"type": "no_movement_zone", "derivedFrom": ["cw.facet.household.people.schedule", "cw.facet.space.environment.foot_traffic"]}, {"type": "pet_safe_storage", "derivedFrom": ["cw.facet.household.pets.animals"]}, {"type": "equipment_available", "derivedFrom": ["cw.facet.space.appliances"]}], "disclosed": [], "withheld": [{"facet": "cw.facet.household.health.allergies", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.household.health.diets", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.household.health.medications", "reason": "not_allowed_for_role"}, {"facet": "cw…
[3] deriveConstraints: {"constraints": [], "disclosed": [], "withheld": [{"facet": "cw.facet.household.health.allergies", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.household.health.diets", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.household.health.medications", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.household.people.schedule", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.space.environment.foot_traffic", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.household.pets.animals", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.commerce.receiving_rules", "r…Código
Ejecutar: python scenarios/out/085-other-robot-learns-zones-not-schedules/python.py
# Scenario 085: A second robot learns where not to move, never when people are home
# Another robot in the same home may receive movement, quiet, safe-zone, pet-storage and equipment constraints. The no-movement zone is derived from the schedule and the hallway traffic facet without revealing either. A role that is not in the roles file receives nothing.
# 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: Derive the other-robot view of the example household.
robot = c.derive_constraints(pick(load("examples/household/context.json"), "facets"), "other_robot")
assert pick(robot, "constraints.length") == 3, pick(robot, "constraints.length")
print("ok", "constraints.length", "=", 3)
assert pick(robot, "constraints[0].type") == "no_movement_zone", pick(robot, "constraints[0].type")
print("ok", "constraints[0].type", "=", "no_movement_zone")
assert pick(robot, "constraints[1].type") == "pet_safe_storage", pick(robot, "constraints[1].type")
print("ok", "constraints[1].type", "=", "pet_safe_storage")
assert pick(robot, "constraints[2].type") == "equipment_available", pick(robot, "constraints[2].type")
print("ok", "constraints[2].type", "=", "equipment_available")
assert pick(robot, "disclosed.length") == 0, pick(robot, "disclosed.length")
print("ok", "disclosed.length", "=", 0)
assert pick(robot, "withheld.length") == 8, pick(robot, "withheld.length")
print("ok", "withheld.length", "=", 8)
# Step 2: The no-movement zone comes from the household schedule and the observed hallway traffic; the constraint says where, not when the children come home.
assert pick(robot, "constraints[0].derivedFrom") == ["cw.facet.household.people.schedule", "cw.facet.space.environment.foot_traffic"], pick(robot, "constraints[0].derivedFrom")
print("ok", "constraints[0].derivedFrom", "=", ["cw.facet.household.people.schedule", "cw.facet.space.environment.foot_traffic"])
assert pick(robot, "withheld[0].facet") == "cw.facet.household.health.allergies", pick(robot, "withheld[0].facet")
print("ok", "withheld[0].facet", "=", "cw.facet.household.health.allergies")
assert pick(robot, "withheld[5].facet") == "cw.facet.self.battery", pick(robot, "withheld[5].facet")
print("ok", "withheld[5].facet", "=", "cw.facet.self.battery")
assert pick(robot, "withheld[5].reason") == "not_allowed_for_role", pick(robot, "withheld[5].reason")
print("ok", "withheld[5].reason", "=", "not_allowed_for_role")
# Step 3: A role name that is not in profiles/household/recipient-roles.json has an empty allow-list: the roles file is an allow-list, not a default.
unknown = c.derive_constraints(pick(load("examples/household/context.json"), "facets"), "visitor_robot")
assert pick(unknown, "constraints.length") == 0, pick(unknown, "constraints.length")
print("ok", "constraints.length", "=", 0)
assert pick(unknown, "disclosed.length") == 0, pick(unknown, "disclosed.length")
print("ok", "disclosed.length", "=", 0)
assert pick(unknown, "withheld.length") == 12, pick(unknown, "withheld.length")
print("ok", "withheld.length", "=", 12)
print("scenario complete")