Files
TJWaterServerBinary/app/api/v1/endpoints/network/demands.py
2026-01-21 18:19:48 +08:00

35 lines
1.3 KiB
Python

from fastapi import APIRouter, Request
from typing import Any, List, Dict, Union
from app.services.tjnetwork import *
router = APIRouter()
############################################################
# demand 9.[DEMANDS]
############################################################
@router.get("/getdemandschema")
async def fastapi_get_demand_schema(network: str) -> dict[str, dict[str, Any]]:
return get_demand_schema(network)
@router.get("/getdemandproperties/")
async def fastapi_get_demand_properties(network: str, junction: str) -> dict[str, Any]:
return get_demand(network, junction)
# example: set_demand(p, ChangeSet({'junction': 'j1', 'demands': [{'demand': 10.0, 'pattern': None, 'category': 'x'}, {'demand': 20.0, 'pattern': None, 'category': None}]}))
@router.post("/setdemandproperties/", response_model=None)
async def fastapi_set_demand_properties(
network: str, junction: str, req: Request
) -> ChangeSet:
props = await req.json()
ps = {"junction": junction} | props
return set_demand(network, ChangeSet(ps))
############################################################
# water distribution 36.[Water Distribution]
############################################################
# This section was empty in main.py, so skipping unless found elsewhere or needed.
# If there are specific Water Distribution endpoints they should go here.