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 / 094
Validate a demand signal and a supply signal
A DemandSignal says how much of an ingredient class kitchens in a region planned to use in a past week (42 sources, published 9 days after the week, no prices); a SupplySignal says a class is in glut, open to all. Validate both examples and hash the supply signal.
Leia primeiro: /docs/SUPPLY-SIGNALS/
Passos
Validate the example DemandSignal (legume, Cairo, week of 2026-11-02). The reference hub's validate checks the document against the schema file's root; this schema keeps its kinds under $defs, so today this call reports ok for any document, and `cookwala validate` (the CLI line) is the real check.
validateValidate the example SupplySignal (tomato glut, Beheira, week of 2026-10-05, harvest window to 18 October).
validateHash the supply signal: a signal is public, free and identical for every reader, and the hash lets any reader prove it.
hash
Resultado
You know the two documents a cooperative or a program publishes and why they are aggregated, delayed and price-free. The policy check is check_signal() in tools/cookwala_ref.py with vectors in conformance/profiles/signal.json. Next: 095 validates a kitchen and a production run.
Linha de comando
cookwala validate
cookwala hash examples/supply/supply-signal.json
jq '{sources: .contributingSources, delayDays, prices}' examples/supply/demand-signal.jsonSaída gravada
Status: ok
[1] validate: {"ok": true, "errors": []}
[2] validate: {"ok": true, "errors": []}
[3] hash: {"hash": "sha256:eba53b0bb96f2745349ec9c1565b7dff698ad062c1d209a9ddbf4de4c7bf7f03"}Código
Executar: python scenarios/out/094-validate-demand-and-supply-signals/python.py
# Scenario 094: Validate a demand signal and a supply signal
# A DemandSignal says how much of an ingredient class kitchens in a region planned to use in a past week (42 sources, published 9 days after the week, no prices); a SupplySignal says a class is in glut, open to all. Validate both examples and hash the supply signal.
# 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: Validate the example DemandSignal (legume, Cairo, week of 2026-11-02). The reference hub's validate checks the document against the schema file's root; this schema keeps its kinds under $defs, so today this call reports ok for any document, and `cookwala validate` (the CLI line) is the real check.
demand = c.validate("supply", load("examples/supply/demand-signal.json"))
assert pick(demand, "ok") == True, pick(demand, "ok")
print("ok", "ok", "=", True)
# Step 2: Validate the example SupplySignal (tomato glut, Beheira, week of 2026-10-05, harvest window to 18 October).
supply = c.validate("supply", load("examples/supply/supply-signal.json"))
assert pick(supply, "ok") == True, pick(supply, "ok")
print("ok", "ok", "=", True)
# Step 3: Hash the supply signal: a signal is public, free and identical for every reader, and the hash lets any reader prove it.
h = c.hash(load("examples/supply/supply-signal.json"))
assert pick(h, "hash") == "sha256:eba53b0bb96f2745349ec9c1565b7dff698ad062c1d209a9ddbf4de4c7bf7f03", pick(h, "hash")
print("ok", "hash", "=", "sha256:eba53b0bb96f2745349ec9c1565b7dff698ad062c1d209a9ddbf4de4c7bf7f03")
print("scenario complete")