idea143-crisisguard-federat.../crisisguard/adapters/shelter_planner.py

31 lines
969 B
Python

"""Minimal shelter planner adapter for CrisisGuard MVP.
This adapter mirrors a simple use-case: apply updates to the shelter section
of the LocalPlan.contents to reflect allocations or changes in capacity.
"""
from __future__ import annotations
from crisisguard.core import LocalPlan, PlanDelta
def process(plan: LocalPlan, delta: PlanDelta) -> LocalPlan:
new_shelter = plan.contents.get("shelter", {})
updates = delta.updates.get("shelter", {}) if isinstance(delta.updates, dict) else {}
if isinstance(updates, dict):
# Merge shelter updates
merged = dict(new_shelter)
merged.update(updates)
new_contents = dict(plan.contents)
new_contents["shelter"] = merged
else:
new_contents = dict(plan.contents)
return LocalPlan(
plan_id=plan.plan_id,
neighborhood=plan.neighborhood,
contents=new_contents,
version=plan.version + 1,
timestamp=plan.timestamp,
)