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 / 084

A food program and a dataset receive nothing from a home

Two recipient roles have empty allow-lists: program (a food bank or a school) and dataset. Derive both over the example household and see twelve withheld facets and zero constraints, which is the intended result.

Audience: school program · Objectif: Aider à éradiquer la faim, Rendre les gens en meilleure santé · Niveau: beginner

Lire d'abord: /docs/HOUSEHOLD-CONTEXT/ /trust/ /docs/HUMANITARIAN-PROFILE/

Étapes

  1. A program plans menus from its own Distribution documents and the recipes' allergen lists; it receives nothing from households. deriveConstraints

  2. A dataset receives nothing either: there is no research export of household facets, derived or raw. deriveConstraints

  3. Every withheld entry carries the reason, so an auditor can tell an empty allow-list from a missing consent.

Résultat

A refusal is a result: a program that integrates with homes gets an empty list by design and keeps working from its own documents. Next: 085, what another robot in the same home may learn.

Ligne de commande

cookwala constraints examples/household/context.json --role program
cookwala constraints examples/household/context.json --role dataset

Sortie enregistrée

Statut: ok

[1] 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…
[2] 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…

Code

Exécuter: python scenarios/out/084-program-and-dataset-receive-nothing/python.py

# Scenario 084: A food program and a dataset receive nothing from a home
# Two recipient roles have empty allow-lists: program (a food bank or a school) and dataset. Derive both over the example household and see twelve withheld facets and zero constraints, which is the intended result.
# 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: A program plans menus from its own Distribution documents and the recipes' allergen lists; it receives nothing from households.
program = c.derive_constraints(pick(load("examples/household/context.json"), "facets"), "program")
assert pick(program, "constraints.length") == 0, pick(program, "constraints.length")
print("ok", "constraints.length", "=", 0)
assert pick(program, "disclosed.length") == 0, pick(program, "disclosed.length")
print("ok", "disclosed.length", "=", 0)
assert pick(program, "withheld.length") == 12, pick(program, "withheld.length")
print("ok", "withheld.length", "=", 12)

# Step 2: A dataset receives nothing either: there is no research export of household facets, derived or raw.
dataset = c.derive_constraints(pick(load("examples/household/context.json"), "facets"), "dataset")
assert pick(dataset, "constraints.length") == 0, pick(dataset, "constraints.length")
print("ok", "constraints.length", "=", 0)
assert pick(dataset, "disclosed.length") == 0, pick(dataset, "disclosed.length")
print("ok", "disclosed.length", "=", 0)
assert pick(dataset, "withheld.length") == 12, pick(dataset, "withheld.length")
print("ok", "withheld.length", "=", 12)

# Step 3: Every withheld entry carries the reason, so an auditor can tell an empty allow-list from a missing consent.
assert pick(program, "withheld[0].reason") == "not_allowed_for_role", pick(program, "withheld[0].reason")
print("ok", "withheld[0].reason", "=", "not_allowed_for_role")
assert pick(program, "withheld[10].facet") == "cw.facet.self.firmware", pick(program, "withheld[10].facet")
print("ok", "withheld[10].facet", "=", "cw.facet.self.firmware")
assert pick(program, "withheld[10].reason") == "no_consent", pick(program, "withheld[10].reason")
print("ok", "withheld[10].reason", "=", "no_consent")
assert pick(dataset, "withheld[0].reason") == "not_allowed_for_role", pick(dataset, "withheld[0].reason")
print("ok", "withheld[0].reason", "=", "not_allowed_for_role")

print("scenario complete")

scenarios/084-program-and-dataset-receive-nothing.json

Précédent: 083 Suivant: 085