From 5a2ffba098b1608018078f348c68f885e18dc774 Mon Sep 17 00:00:00 2001 From: Cizz22 Date: Thu, 18 Sep 2025 20:39:05 +0700 Subject: [PATCH] simulation id rbd --- src/calculation_target_reliability/router.py | 2 +- src/calculation_target_reliability/service.py | 4 +- src/calculation_time_constrains/service.py | 47 +++++++++++++++++-- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/calculation_target_reliability/router.py b/src/calculation_target_reliability/router.py index 3301296..403be76 100644 --- a/src/calculation_target_reliability/router.py +++ b/src/calculation_target_reliability/router.py @@ -59,7 +59,7 @@ async def get_target_reliability( # ) if not simulation_id: - simulation_id = "default" + simulation_id = "6825d5b9-c165-45fe-b553-8c71c1a15903" results = await get_simulation_results( simulation_id=simulation_id, diff --git a/src/calculation_target_reliability/service.py b/src/calculation_target_reliability/service.py index ae29172..c230e58 100644 --- a/src/calculation_target_reliability/service.py +++ b/src/calculation_target_reliability/service.py @@ -48,9 +48,9 @@ async def get_simulation_results(*, simulation_id: str, token: str): "Content-Type": "application/json" } - calc_result_url = f"{RBD_SERVICE_API}/aeros/simulation/result/calc/default?nodetype=RegularNode" + calc_result_url = f"{RBD_SERVICE_API}/aeros/simulation/result/calc/{simulation_id}?nodetype=RegularNode" # plot_result_url = f"{RBD_SERVICE_API}/aeros/simulation/result/plot/{simulation_id}?nodetype=RegularNode" - calc_plant_result = f"{RBD_SERVICE_API}/aeros/simulation/result/calc/default/plant" + calc_plant_result = f"{RBD_SERVICE_API}/aeros/simulation/result/calc/{simulation_id}/plant" async with httpx.AsyncClient(timeout=300.0) as client: calc_task = client.get(calc_result_url, headers=headers) diff --git a/src/calculation_time_constrains/service.py b/src/calculation_time_constrains/service.py index 65caca6..62665ed 100644 --- a/src/calculation_time_constrains/service.py +++ b/src/calculation_time_constrains/service.py @@ -1112,7 +1112,7 @@ class OptimumCostModel: async def get_failures_prediction(self, simulation_id: str, location_tag): # calc_result_url = f"{RBD_SERVICE_API}/aeros/simulation/result/calc/{simulation_id}?nodetype=RegularNode" - plot_result_url = f"{RBD_SERVICE_API}/aeros/simulation/result/plot/default/{location_tag}?use_location_tag=1" + plot_result_url = f"{RBD_SERVICE_API}/aeros/simulation/result/plot/{simulation_id}/{location_tag}?use_location_tag=1" # calc_plant_result = f"{RBD_SERVICE_API}/aeros/simulation/result/calc/{simulation_id}/plant" @@ -1144,6 +1144,37 @@ class OptimumCostModel: return calculate_failures_per_month(time_series) + async def get_simulation_results(self): + headers = { + "Authorization": f"Bearer {self.token}", + "Content-Type": "application/json" + } + + calc_result_url = f"{RBD_SERVICE_API}/aeros/simulation/result/calc/default?nodetype=RegularNode" + # plot_result_url = f"{RBD_SERVICE_API}/aeros/simulation/result/plot/{simulation_id}?nodetype=RegularNode" + calc_plant_result = f"{RBD_SERVICE_API}/aeros/simulation/result/calc/default/plant" + + 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) + plant_task = client.get(calc_plant_result, headers=headers) + + # Run all three requests concurrently + calc_response, plant_response = await asyncio.gather(calc_task, plant_task) + + calc_response.raise_for_status() + # plot_response.raise_for_status() + plant_response.raise_for_status() + + calc_data = calc_response.json()["data"] + # plot_data = plot_response.json()["data"] + plant_data = plant_response.json()["data"] + + return { + "calc_result": calc_data, + # "plot_result": plot_data, + "plant_result": plant_data + } async def calculate_cost_all_equipment( self, @@ -1169,6 +1200,10 @@ class OptimumCostModel: # all_reliabilities = await self._get_reliability_equipment_batch(location_tags) print("Processing cost calculations...") + + importance_results = await self.get_simulation_results() + + equipment_birbaum = {imp['aeros_node']['node_name']: imp['contribution'] for imp in importance_results["calc_result"]} # Process each equipment's costs fleet_results = [] @@ -1185,9 +1220,15 @@ class OptimumCostModel: service_cost = equipment.service_cost failures_prediction = await self.get_failures_prediction( - simulation_id = "864f1558-79cc-40b1-8d1f-8e7339d9d8ce", + simulation_id = "6825d5b9-c165-45fe-b553-8c71c1a15903", location_tag=location_tag ) + + energy_price_per_mwh = 1000000 + + birnbaum = equipment_birbaum.get(location_tag, 0) + mw_lost_when_failed = birnbaum * 660 + cost_per_hour_downtime = mw_lost_when_failed * energy_price_per_mwh # # Get pre-fetched reliability data # failure_rate = all_reliabilities.get(location_tag, {}) @@ -1197,7 +1238,7 @@ class OptimumCostModel: # Calculate costs using vectorized operations predicted_costs = self._calculate_costs_vectorized( preventive_cost=overhaul_cost + service_cost, - failure_replacement_cost=cost_per_failure, + failure_replacement_cost=cost_per_failure + cost_per_hour_downtime, failures_prediction=failures_prediction )