From 0d92e6b21ba8494673c19e7d98364746f8890531 Mon Sep 17 00:00:00 2001 From: Cizz22 Date: Thu, 13 Feb 2025 15:16:29 +0700 Subject: [PATCH] add id --- src/calculation_time_constrains/service.py | 49 +++++++++------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/src/calculation_time_constrains/service.py b/src/calculation_time_constrains/service.py index 49fe394..7695054 100644 --- a/src/calculation_time_constrains/service.py +++ b/src/calculation_time_constrains/service.py @@ -30,11 +30,14 @@ def get_overhaul_cost_by_time_chart( if days <= 0: raise ValueError("Days must be positive") - exponents = np.arange(1, days+1) + hours = days * 24 + + rate = np.arange(1, hours+1) + cost_per_equipment = overhaul_cost / numEquipments - # Using a slower decay base to spread the budget depletion over more days - results = cost_per_equipment - ((cost_per_equipment / days) * exponents) - results = np.where(np.isfinite(results), results, 0) + + results = cost_per_equipment - ((cost_per_equipment / hours) * rate) + return results @@ -58,21 +61,8 @@ def get_overhaul_cost_by_time_chart( async def get_corrective_cost_time_chart( material_cost: float, service_cost: float, location_tag: str, token, max_days: int ) -> Tuple[np.ndarray, np.ndarray]: - """ - Fetch failure data from API and calculate corrective costs, ensuring 365 days of data. - - Args: - material_cost: Cost of materials per failure - service_cost: Cost of service per failure - location_tag: Location tag of the equipment - token: Authorization token - - Returns: - Tuple of (corrective_costs, daily_failure_rate) - """ - start_date = datetime.datetime(2025, 1, 1) -# Calculate end date (667 days after start date) + start_date = datetime.datetime(2025, 1, 1) end_date = start_date + datetime.timedelta(days=max_days) url = f"http://192.168.1.82:8000/reliability/main/number-of-failures/{location_tag}/{start_date.strftime('%Y-%m-%d')}/{end_date.strftime('%Y-%m-%d')}" @@ -120,6 +110,10 @@ async def get_corrective_cost_time_chart( # Convert to numpy array daily_failure = np.array(complete_data) + hourly_failure = np.repeat(daily_failure, 24) / 24 + + + # failure_counts = np.cumsum(daily_failure) # Calculate corrective costs @@ -128,9 +122,10 @@ async def get_corrective_cost_time_chart( if cost_per_failure == 0: raise ValueError("Cost per failure cannot be zero") - corrective_costs = daily_failure * cost_per_failure + corrective_costs = hourly_failure * cost_per_failure + - return corrective_costs, daily_failure + return corrective_costs, hourly_failure except Exception as e: print(f"Error fetching or processing data: {str(e)}") @@ -190,7 +185,7 @@ async def create_param_and_data( async def get_calculation_result(db_session: DbSession, calculation_id: str): - days = 667 + days = 667*24 scope_calculation = await get_calculation_data_by_id( db_session=db_session, calculation_id=calculation_id ) @@ -332,8 +327,8 @@ async def create_calculation_result_service( # Store results for each equipment equipment_results: List[CalculationEquipmentResult] = [] - total_corrective_costs = np.zeros(days) - total_daily_failures = np.zeros(days) + total_corrective_costs = np.zeros(days*24) + total_daily_failures = np.zeros(days*24) # Calculate for each equipment for eq in equipments: @@ -344,16 +339,10 @@ async def create_calculation_result_service( location_tag=eq.equipment.location_tag, max_days=667 ) - # corrective_costs, daily_failures = get_corrective_cost_time_chart( - # material_cost=eq.material_cost, - # service_cost=eq.service_cost, - # days=days, - # numEquipments=len(equipments), - # ) overhaul_cost_points = get_overhaul_cost_by_time_chart( calculation_data.parameter.overhaul_cost, - days=len(corrective_costs), + days=667, numEquipments=len(equipments), )