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

The impact summary: every measure says how it was obtained

An ImpactSummary is computed from a folder of offers, claims, handovers and distributions. Each measure carries a value, a unit, a method and a source, and the document lists what went wrong and what is unknown. Validate and hash the four example summaries.

Público: regulator · Objetivo: Ajude a acabar com a fome · Nível: beginner

Leia primeiro: /docs/HUMANITARIAN-PROFILE/ /humanitarian/

Passos

  1. The Cairo food bank's November summary validates. validate

  2. Its content hash: the value a regulator can quote when citing the summary. hash

  3. The school-meals summary. hash

  4. The disaster-kitchen summary. hash

  5. The robot-kitchen summary. hash

Resultado

You can cite a summary by hash and recompute it from the documents with the command above. Next: scenario 077 does the same for rule packs.

Linha de comando

cookwala humanitarian --summary examples/humanitarian/flows/food-bank-cairo --org did:web:food-bank-cairo.example --from 2026-11-01 --to 2026-11-30
cookwala hash examples/humanitarian/flows/food-bank-cairo/impact-summary.json

Saída gravada

Status: ok

[1] validate: {"ok": true, "errors": []}
[2] hash: {"hash": "sha256:eda7e2205fb07e9745e301208cc4b8a9ab0e54ddf9c791a9baf512cc8b7b7bc5"}
[3] hash: {"hash": "sha256:c9dbb3c8a8fdaffbe03c239b7f0fa6cae5f8c5e021585a17aebaeca5540abf2b"}
[4] hash: {"hash": "sha256:de065ed850673ae3e975f85130e693ca2c515eb7853aac39fc6fab2108e850cc"}
[5] hash: {"hash": "sha256:f3640f78bbe864521e6dec9c999e95d2fd61bda5595ec5fa4c76d1215f9711a3"}

Código

Executar: python scenarios/out/075-the-impact-summary-document/python.py

# Scenario 075: The impact summary: every measure says how it was obtained
# An ImpactSummary is computed from a folder of offers, claims, handovers and distributions. Each measure carries a value, a unit, a method and a source, and the document lists what went wrong and what is unknown. Validate and hash the four example summaries.
# 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: The Cairo food bank's November summary validates.
cairo = c.validate("humanitarian", load("examples/humanitarian/flows/food-bank-cairo/impact-summary.json"))
assert pick(cairo, "ok") == True, pick(cairo, "ok")
print("ok", "ok", "=", True)

# Step 2: Its content hash: the value a regulator can quote when citing the summary.
cairoHash = c.hash(load("examples/humanitarian/flows/food-bank-cairo/impact-summary.json"))
assert pick(cairoHash, "hash") == "sha256:eda7e2205fb07e9745e301208cc4b8a9ab0e54ddf9c791a9baf512cc8b7b7bc5", pick(cairoHash, "hash")
print("ok", "hash", "=", "sha256:eda7e2205fb07e9745e301208cc4b8a9ab0e54ddf9c791a9baf512cc8b7b7bc5")

# Step 3: The school-meals summary.
schoolHash = c.hash(load("examples/humanitarian/flows/school-meals/impact-summary.json"))
assert pick(schoolHash, "hash") == "sha256:c9dbb3c8a8fdaffbe03c239b7f0fa6cae5f8c5e021585a17aebaeca5540abf2b", pick(schoolHash, "hash")
print("ok", "hash", "=", "sha256:c9dbb3c8a8fdaffbe03c239b7f0fa6cae5f8c5e021585a17aebaeca5540abf2b")

# Step 4: The disaster-kitchen summary.
disasterHash = c.hash(load("examples/humanitarian/flows/disaster-kitchen/impact-summary.json"))
assert pick(disasterHash, "hash") == "sha256:de065ed850673ae3e975f85130e693ca2c515eb7853aac39fc6fab2108e850cc", pick(disasterHash, "hash")
print("ok", "hash", "=", "sha256:de065ed850673ae3e975f85130e693ca2c515eb7853aac39fc6fab2108e850cc")

# Step 5: The robot-kitchen summary.
robotHash = c.hash(load("examples/humanitarian/flows/robot-kitchen/impact-summary.json"))
assert pick(robotHash, "hash") == "sha256:f3640f78bbe864521e6dec9c999e95d2fd61bda5595ec5fa4c76d1215f9711a3", pick(robotHash, "hash")
print("ok", "hash", "=", "sha256:f3640f78bbe864521e6dec9c999e95d2fd61bda5595ec5fa4c76d1215f9711a3")

print("scenario complete")

scenarios/075-the-impact-summary-document.json

Anterior: 074 Próximo: 076