59 lines
1.5 KiB
Python
59 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
from abc import ABC, abstractmethod
|
|
from typing import Any, Dict
|
|
|
|
from .models import LocalProblem, PlanDelta
|
|
|
|
|
|
class Adapter(ABC):
|
|
@abstractmethod
|
|
def start(self) -> None:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def stop(self) -> None:
|
|
pass
|
|
|
|
|
|
class MarketDataFeedAdapter(Adapter):
|
|
def __init__(self) -> None:
|
|
self.running = False
|
|
|
|
def start(self) -> None:
|
|
self.running = True
|
|
|
|
def stop(self) -> None:
|
|
self.running = False
|
|
|
|
def get_local_problem(self) -> LocalProblem:
|
|
# Seed a tiny LocalProblem from venue data (mocked here)
|
|
problem = LocalProblem(
|
|
id="lp-001",
|
|
neighborhood="Downtown",
|
|
tasks=[{"type": "evacuation", "constraints": {"capacity": 5000}}],
|
|
capacity=5000,
|
|
equity_budget=0.2,
|
|
)
|
|
return problem
|
|
|
|
|
|
class EdgeComputeAdapter(Adapter):
|
|
def __init__(self) -> None:
|
|
self.running = False
|
|
|
|
def start(self) -> None:
|
|
self.running = True
|
|
|
|
def stop(self) -> None:
|
|
self.running = False
|
|
|
|
def process_delta(self, delta: PlanDelta) -> PlanDelta:
|
|
# Minimal processing: append an execution action and bump version
|
|
plan = dict(delta.plan)
|
|
actions = plan.get("actions", [])
|
|
actions.append({"action": "recompute", "at": "edge"})
|
|
plan["actions"] = actions
|
|
new_delta = PlanDelta(version=delta.version + 1, plan=plan, provenance="edge", signature="edge-sig")
|
|
return new_delta
|