You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.3 KiB
Python
83 lines
2.3 KiB
Python
from typing import Dict, List, Optional
|
|
|
|
from fastapi import APIRouter, HTTPException, status
|
|
from fastapi.params import Query
|
|
|
|
from src.database.core import DbSession, CollectorDbSession
|
|
from src.auth.service import Token
|
|
from src.models import StandardResponse
|
|
|
|
from .service import run_rbd_simulation, get_simulation_results, identify_worst_eaf_contributors
|
|
from .schema import OptimizationResult
|
|
router = APIRouter()
|
|
|
|
|
|
# @router.get("", response_model=StandardResponse[List[Dict]])
|
|
# async def get_target_reliability(
|
|
# db_session: DbSession,
|
|
# scope_name: Optional[str] = Query(None),
|
|
# eaf_threshold: float = Query(100),
|
|
# ):
|
|
# """Get all scope pagination."""
|
|
# results = await get_all_target_reliability(
|
|
# db_session=db_session, scope_name=scope_name, eaf_threshold=eaf_threshold
|
|
# )
|
|
|
|
# return StandardResponse(
|
|
# data=results,
|
|
# message="Data retrieved successfully",
|
|
# )
|
|
|
|
|
|
@router.get("", response_model=StandardResponse[OptimizationResult])
|
|
async def get_target_reliability(
|
|
db_session: DbSession,
|
|
token: Token,
|
|
collector_db: CollectorDbSession,
|
|
oh_session_id: Optional[str] = Query(None),
|
|
eaf_input: float = Query(99.8),
|
|
duration: int = Query(8760),
|
|
simulation_id: Optional[str] = Query(None)
|
|
):
|
|
"""Get all scope pagination."""
|
|
if not oh_session_id:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_400_BAD_REQUEST,
|
|
detail="oh_session_id is required",
|
|
)
|
|
|
|
# results = await get_eaf_timeline(
|
|
# db_session=db_session,
|
|
# oh_session_id=oh_session_id,
|
|
# eaf_input=eaf_input,
|
|
# oh_duration=duration
|
|
# )
|
|
|
|
# simulation_id = await run_rbd_simulation(
|
|
# sim_hours=duration,
|
|
# token=token
|
|
# )
|
|
|
|
if not simulation_id:
|
|
simulation_id = "f31103ef-1ac8-4c29-8f66-ea9ccf06bd87"
|
|
|
|
results = await get_simulation_results(
|
|
simulation_id=simulation_id,
|
|
token=token
|
|
)
|
|
|
|
optimize_result = await identify_worst_eaf_contributors(
|
|
simulation_result=results,
|
|
target_eaf=eaf_input,
|
|
db_session=db_session,
|
|
oh_session_id=oh_session_id,
|
|
collector_db=collector_db,
|
|
simulation_id=simulation_id
|
|
)
|
|
|
|
|
|
return StandardResponse(
|
|
data=optimize_result,
|
|
message="Data retrieved successfully",
|
|
)
|