Diese Seite wurde maschinell übersetzt und wurde noch nicht von einer Person überprüft. Englisch ist die Referenz; Korrekturen auf GitHub sind willkommen. GitHub
Cookwala / SDK und Szenarien / 003
A grocer receives constraints, never the household's facts
The Household Context Profile keeps a home's facts at home. Derive what a grocer may receive from a full household context and confirm that the raw facets about children and health stay withheld.
Zuerst lesen: /docs/HOUSEHOLD-CONTEXT/ /trust/
Schritte
Run the derivation for the grocer role over the example household (an allergy, a child, a budget, a delivery window among the facets).
deriveConstraintsA meal planner may receive more constraint types than a grocer, still never a raw facet.
deriveConstraintsThe constraint list carries types and the facet ids it was derived from; no facet value appears.
Ergebnis
You know the shape of a DerivedConstraint and why providers plug in as peers without seeing the home. Next: scenario 030 adds a consent grant for a device self-state facet.
Kommandozeile
cookwala constraints examples/household/context.json --role grocer
cookwala constraints examples/household/context.json --role plannerAufgezeichnete Ausgabe
Status: ok
[1] deriveConstraints: {"constraints": [{"type": "allergen_block", "derivedFrom": ["cw.facet.household.health.allergies"]}, {"type": "labeling_required", "derivedFrom": ["cw.facet.household.health.allergies"]}, {"type": "delivery_window", "derivedFrom": ["cw.facet.commerce.receiving_rules"]}, {"type": "access_point", "derivedFrom": ["cw.facet.commerce.receiving_rules"]}, {"type": "budget_cap", "derivedFrom": ["cw.facet.household.economics.budget_posture"]}], "disclosed": [], "withheld": [{"facet": "cw.facet.household.health.diets", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.household.health.medications",…
[2] deriveConstraints: {"constraints": [{"type": "allergen_block", "derivedFrom": ["cw.facet.household.health.allergies"]}, {"type": "diet_rule", "derivedFrom": ["cw.facet.household.health.diets"]}, {"type": "avoid_ingredient", "derivedFrom": ["cw.facet.household.health.medications"]}, {"type": "serve_window", "derivedFrom": ["cw.facet.household.health.medications", "cw.facet.household.people.schedule"]}, {"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"]}, {"ty…Code
Ausführen: python scenarios/out/003-household-constraints-for-a-grocer/python.py
# Scenario 003: A grocer receives constraints, never the household's facts
# The Household Context Profile keeps a home's facts at home. Derive what a grocer may receive from a full household context and confirm that the raw facets about children and health stay withheld.
# 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: Run the derivation for the grocer role over the example household (an allergy, a child, a budget, a delivery window among the facets).
grocer = c.derive_constraints(pick(load("examples/household/context.json"), "facets"), "grocer")
assert pick(grocer, "withheld.length") == 9, pick(grocer, "withheld.length")
print("ok", "withheld.length", "=", 9)
# Step 2: A meal planner may receive more constraint types than a grocer, still never a raw facet.
planner = c.derive_constraints(pick(load("examples/household/context.json"), "facets"), "planner")
# Step 3: The constraint list carries types and the facet ids it was derived from; no facet value appears.
assert pick(grocer, "constraints[0].type") == "allergen_block", pick(grocer, "constraints[0].type")
print("ok", "constraints[0].type", "=", "allergen_block")
print("scenario complete")