main
Cizz22 11 months ago
parent 84d91e464c
commit 0d92e6b21b

@ -30,11 +30,14 @@ def get_overhaul_cost_by_time_chart(
if days <= 0: if days <= 0:
raise ValueError("Days must be positive") 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 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 = cost_per_equipment - ((cost_per_equipment / hours) * rate)
results = np.where(np.isfinite(results), results, 0)
return results return results
@ -58,21 +61,8 @@ def get_overhaul_cost_by_time_chart(
async def get_corrective_cost_time_chart( async def get_corrective_cost_time_chart(
material_cost: float, service_cost: float, location_tag: str, token, max_days: int material_cost: float, service_cost: float, location_tag: str, token, max_days: int
) -> Tuple[np.ndarray, np.ndarray]: ) -> 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) 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')}" 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 # Convert to numpy array
daily_failure = np.array(complete_data) daily_failure = np.array(complete_data)
hourly_failure = np.repeat(daily_failure, 24) / 24
# failure_counts = np.cumsum(daily_failure) # failure_counts = np.cumsum(daily_failure)
# Calculate corrective costs # Calculate corrective costs
@ -128,9 +122,10 @@ async def get_corrective_cost_time_chart(
if cost_per_failure == 0: if cost_per_failure == 0:
raise ValueError("Cost per failure cannot be zero") 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: except Exception as e:
print(f"Error fetching or processing data: {str(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): async def get_calculation_result(db_session: DbSession, calculation_id: str):
days = 667 days = 667*24
scope_calculation = await get_calculation_data_by_id( scope_calculation = await get_calculation_data_by_id(
db_session=db_session, calculation_id=calculation_id db_session=db_session, calculation_id=calculation_id
) )
@ -332,8 +327,8 @@ async def create_calculation_result_service(
# Store results for each equipment # Store results for each equipment
equipment_results: List[CalculationEquipmentResult] = [] equipment_results: List[CalculationEquipmentResult] = []
total_corrective_costs = np.zeros(days) total_corrective_costs = np.zeros(days*24)
total_daily_failures = np.zeros(days) total_daily_failures = np.zeros(days*24)
# Calculate for each equipment # Calculate for each equipment
for eq in equipments: for eq in equipments:
@ -344,16 +339,10 @@ async def create_calculation_result_service(
location_tag=eq.equipment.location_tag, location_tag=eq.equipment.location_tag,
max_days=667 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( overhaul_cost_points = get_overhaul_cost_by_time_chart(
calculation_data.parameter.overhaul_cost, calculation_data.parameter.overhaul_cost,
days=len(corrective_costs), days=667,
numEquipments=len(equipments), numEquipments=len(equipments),
) )

Loading…
Cancel
Save