72 lines
1.9 KiB
Python
72 lines
1.9 KiB
Python
"""DSL Sketches for CommonsGrid core primitives.
|
|
|
|
This module provides lightweight dataclass-backed DSL primitives that sketch
|
|
the intended canonical representations used for CommunityPolicy, LocalProblem,
|
|
SharedSignals, PlanDelta, PrivacyBudget, and AuditLog blocks.
|
|
|
|
These are intentionally small and opinionated scaffolds to bootstrap a DSL
|
|
without pulling in heavy dependencies. They can be extended to integrate with the
|
|
GovernanceLedger and EnergiBridge as the project matures.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
from typing import Dict, Any, Optional
|
|
|
|
|
|
@dataclass
|
|
class LocalProblemDSL:
|
|
neighborhood_id: str
|
|
demand_kw: float
|
|
pv_kw: float
|
|
storage_kwh: float
|
|
metadata: Dict[str, float] = field(default_factory=dict)
|
|
|
|
def to_model(self) -> "LocalProblem":
|
|
# Import locally to avoid a hard coupling at import time
|
|
from .models import LocalProblem
|
|
return LocalProblem(
|
|
neighborhood_id=self.neighborhood_id,
|
|
demand_kw=self.demand_kw,
|
|
pv_kw=self.pv_kw,
|
|
storage_kwh=self.storage_kwh,
|
|
evs=0,
|
|
metadata=self.metadata,
|
|
)
|
|
|
|
|
|
@dataclass
|
|
class SharedSignalsDSL:
|
|
weather_forecast: Dict[str, float] = field(default_factory=dict)
|
|
demand_signals: Dict[str, float] = field(default_factory=dict)
|
|
|
|
|
|
@dataclass
|
|
class PlanDeltaDSL:
|
|
delta_kw: float
|
|
delta_pv: float
|
|
description: Optional[str] = None
|
|
|
|
|
|
@dataclass
|
|
class PrivacyBudgetDSL:
|
|
total_budget: float
|
|
spent: float = 0.0
|
|
|
|
def spend(self, amount: float) -> bool:
|
|
if self.spent + amount > self.total_budget:
|
|
return False
|
|
self.spent += amount
|
|
return True
|
|
|
|
def remaining(self) -> float:
|
|
return max(self.total_budget - self.spent, 0.0)
|
|
|
|
|
|
@dataclass
|
|
class AuditLogBlock:
|
|
entry: str
|
|
timestamp: float
|
|
block_hash: str
|