feat: instrument model
This commit is contained in:
@@ -44,6 +44,18 @@ class NodeConfigBody(BaseModel):
|
||||
macro_key: Optional[str] = None # "" to clear, None = no-op
|
||||
|
||||
|
||||
class NodeScenarioBody(BaseModel):
|
||||
node_id: str
|
||||
label: str
|
||||
horizon: str = "mt" # 'ct' | 'mt' | 'lt'
|
||||
target_date: str # YYYY-MM-DD
|
||||
target_value: float
|
||||
confidence: float = 0.7 # 0.0 – 1.0
|
||||
trajectory: str = "linear" # 'step' | 'linear' | 'exp'
|
||||
absorption_days: int = 30
|
||||
notes: Optional[str] = ""
|
||||
|
||||
|
||||
class CalibrateBody(BaseModel):
|
||||
ref_date: Optional[str] = None
|
||||
|
||||
@@ -539,6 +551,48 @@ def calibrate_intercept(
|
||||
conn.close()
|
||||
|
||||
|
||||
@router.get("/{instrument}/scenarios")
|
||||
def list_scenarios(instrument: str, node_id: Optional[str] = Query(None)) -> List[Dict[str, Any]]:
|
||||
"""Tous les scénarios CT/MT/LT d'un instrument (ou d'un nœud spécifique)."""
|
||||
from services.database import get_conn
|
||||
from services.instrument_models import get_node_scenarios
|
||||
conn = get_conn()
|
||||
try:
|
||||
return get_node_scenarios(conn, instrument.upper(), node_id)
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
@router.post("/{instrument}/scenarios")
|
||||
def create_scenario(instrument: str, body: NodeScenarioBody) -> Dict[str, Any]:
|
||||
"""Crée un scénario forecast sur un nœud."""
|
||||
from services.database import get_conn
|
||||
from services.instrument_models import add_node_scenario
|
||||
conn = get_conn()
|
||||
try:
|
||||
sid = add_node_scenario(
|
||||
conn, instrument.upper(), body.node_id, body.label,
|
||||
body.horizon, body.target_date, body.target_value,
|
||||
body.confidence, body.trajectory, body.absorption_days, body.notes or "",
|
||||
)
|
||||
return {"ok": True, "id": sid, "node_id": body.node_id}
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
@router.delete("/{instrument}/scenarios/{scenario_id}")
|
||||
def remove_scenario(instrument: str, scenario_id: int) -> Dict[str, Any]:
|
||||
"""Supprime un scénario forecast."""
|
||||
from services.database import get_conn
|
||||
from services.instrument_models import delete_node_scenario
|
||||
conn = get_conn()
|
||||
try:
|
||||
delete_node_scenario(conn, scenario_id)
|
||||
return {"ok": True, "id": scenario_id}
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
@router.patch("/{instrument}/nodes/{node_id}")
|
||||
def update_node_config(
|
||||
instrument: str,
|
||||
|
||||
Reference in New Issue
Block a user