|
|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
|
|
from sqlalchemy import Delete, Select
|
|
|
|
|
|
|
|
|
|
import httpx
|
|
|
|
|
from src.auth.service import CurrentUser
|
|
|
|
|
from src.database.core import DbSession
|
|
|
|
|
# from src.scope_equipment.model import ScopeEquipment
|
|
|
|
|
@ -14,6 +14,12 @@ from .utils import generate_down_periods
|
|
|
|
|
from src.overhaul_scope.service import get as get_overhaul
|
|
|
|
|
from bisect import bisect_left
|
|
|
|
|
from collections import defaultdict
|
|
|
|
|
|
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
|
|
RBD_SERVICE_API = "https://example.com/api"
|
|
|
|
|
|
|
|
|
|
client = httpx.AsyncClient(timeout=300.0)
|
|
|
|
|
# async def get_all_target_reliability(
|
|
|
|
|
# *, db_session: DbSession, scope_name: str, eaf_threshold: float = 100.0
|
|
|
|
|
# ):
|
|
|
|
|
@ -184,7 +190,53 @@ from collections import defaultdict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# return results
|
|
|
|
|
async def run_rbd_simulation(*, sim_hours: int, token):
|
|
|
|
|
sim_data = {
|
|
|
|
|
"SimulationName": "Simulation OH Reliability Target",
|
|
|
|
|
"SchematicName": "- TJB - Unit 3 -",
|
|
|
|
|
"SimSeed": 1,
|
|
|
|
|
"SimDuration": sim_hours,
|
|
|
|
|
"DurationUnit": "UHour",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
headers = {
|
|
|
|
|
"Authorization": f"Bearer {token}",
|
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rbd_simulation_url = f"{RBD_SERVICE_API}/aeros/simulation/run"
|
|
|
|
|
|
|
|
|
|
async with httpx.AsyncClient(timeout=300.0) as client:
|
|
|
|
|
response = await client.post(rbd_simulation_url, json=sim_data, headers=headers)
|
|
|
|
|
response.raise_for_status()
|
|
|
|
|
return response.json()
|
|
|
|
|
|
|
|
|
|
async def get_simulation_results(*, simulation_id: str, token: str):
|
|
|
|
|
headers = {
|
|
|
|
|
"Authorization": f"Bearer {token}",
|
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
calc_result_url = f"{RBD_SERVICE_API}/aeros/simulation/result/calc/{simulation_id}"
|
|
|
|
|
plot_result_url = f"{RBD_SERVICE_API}/aeros/simulation/result/plot/{simulation_id}"
|
|
|
|
|
|
|
|
|
|
async with httpx.AsyncClient(timeout=300.0) as client:
|
|
|
|
|
calc_task = client.get(calc_result_url, headers=headers)
|
|
|
|
|
plot_task = client.get(plot_result_url, headers=headers)
|
|
|
|
|
|
|
|
|
|
# Run both requests concurrently
|
|
|
|
|
calc_response, plot_response = await asyncio.gather(calc_task, plot_task)
|
|
|
|
|
|
|
|
|
|
calc_response.raise_for_status()
|
|
|
|
|
plot_response.raise_for_status()
|
|
|
|
|
|
|
|
|
|
calc_data = calc_response.json()["data"]
|
|
|
|
|
plot_data = plot_response.json()["data"]
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
"calc_result": calc_data,
|
|
|
|
|
"plot_result": plot_data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async def get_eaf_timeline(*, db_session, eaf_input: float, oh_session_id: str, oh_duration = 8000) -> List[dict]:
|
|
|
|
|
"""
|
|
|
|
|
|