|
|
|
|
@ -17,31 +17,74 @@ from src.overhaul_scope.service import get as get_scope
|
|
|
|
|
from .schema import CalculationResultsRead
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_overhaul_cost_by_time_chart(overhaul_cost: float, days: int, decay_base: float = 1.1) -> np.ndarray:
|
|
|
|
|
# def get_overhaul_cost_by_time_chart(overhaul_cost: float, days: int,numEquipments:int ,decay_base: float = 1.1) -> np.ndarray:
|
|
|
|
|
# if overhaul_cost < 0:
|
|
|
|
|
# raise ValueError("Overhaul cost cannot be negative")
|
|
|
|
|
# if days <= 0:
|
|
|
|
|
# raise ValueError("Days must be positive")
|
|
|
|
|
|
|
|
|
|
# exponents = np.arange(0, days)
|
|
|
|
|
# cost_per_equipment = overhaul_cost / numEquipments
|
|
|
|
|
# # Using a slower decay base to spread the budget depletion over more days
|
|
|
|
|
# results = cost_per_equipment / (decay_base ** exponents)
|
|
|
|
|
# results = np.where(np.isfinite(results), results, 0)
|
|
|
|
|
# return results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_overhaul_cost_by_time_chart(overhaul_cost: float, days: int, numEquipments: int, decay_base: float = 1.1) -> np.ndarray:
|
|
|
|
|
if overhaul_cost < 0:
|
|
|
|
|
raise ValueError("Overhaul cost cannot be negative")
|
|
|
|
|
if days <= 0:
|
|
|
|
|
raise ValueError("Days must be positive")
|
|
|
|
|
|
|
|
|
|
exponents = np.arange(0, days)
|
|
|
|
|
# Using a slower decay base to spread the budget depletion over more days
|
|
|
|
|
results = overhaul_cost / (decay_base ** exponents)
|
|
|
|
|
cost_per_equipment = overhaul_cost / numEquipments
|
|
|
|
|
|
|
|
|
|
# Introduce randomness by multiplying with a random factor
|
|
|
|
|
random_factors = np.random.normal(1.0, 0.1, numEquipments) # Mean 1.0, Std Dev 0.1
|
|
|
|
|
results = np.array([cost_per_equipment * factor / (decay_base ** exponents) for factor in random_factors])
|
|
|
|
|
|
|
|
|
|
results = np.where(np.isfinite(results), results, 0)
|
|
|
|
|
return results
|
|
|
|
|
|
|
|
|
|
def get_corrective_cost_time_chart(material_cost: float, service_cost: float, days: int) -> Tuple[np.ndarray, np.ndarray]:
|
|
|
|
|
# def get_corrective_cost_time_chart(material_cost: float, service_cost: float, days: int) -> Tuple[np.ndarray, np.ndarray]:
|
|
|
|
|
# day_points = np.arange(0, days)
|
|
|
|
|
|
|
|
|
|
# # Parameters for failure rate
|
|
|
|
|
# base_rate = 0.2 # Base failure rate per day
|
|
|
|
|
# acceleration = 2.4 # How quickly failure rate increases
|
|
|
|
|
# grace_period = 170 # Days before failures start increasing significantly
|
|
|
|
|
|
|
|
|
|
# # Calculate daily failure rate using sigmoid function
|
|
|
|
|
# daily_failure_rate = base_rate / (1 + np.exp(-acceleration * (day_points - grace_period)/days))
|
|
|
|
|
|
|
|
|
|
# # Calculate cumulative failures
|
|
|
|
|
# failure_counts = np.cumsum(daily_failure_rate)
|
|
|
|
|
|
|
|
|
|
# # Calculate corrective costs based on cumulative failures and combined costs
|
|
|
|
|
# cost_per_failure = material_cost + service_cost
|
|
|
|
|
# corrective_costs = failure_counts * cost_per_failure
|
|
|
|
|
|
|
|
|
|
# return corrective_costs, daily_failure_rate
|
|
|
|
|
|
|
|
|
|
def get_corrective_cost_time_chart(material_cost: float, service_cost: float, days: int, numEquipments: int) -> Tuple[np.ndarray, np.ndarray]:
|
|
|
|
|
day_points = np.arange(0, days)
|
|
|
|
|
|
|
|
|
|
# Parameters for failure rate
|
|
|
|
|
base_rate = 1.2 # Base failure rate per day
|
|
|
|
|
acceleration = 11.2 # How quickly failure rate increases
|
|
|
|
|
grace_period = 90 # Days before failures start increasing significantly
|
|
|
|
|
base_rate = 0.2 # Base failure rate per day
|
|
|
|
|
acceleration = 2.4 # How quickly failure rate increases
|
|
|
|
|
grace_period = 170 # Days before failures start increasing significantly
|
|
|
|
|
|
|
|
|
|
# Calculate daily failure rate using sigmoid function
|
|
|
|
|
daily_failure_rate = base_rate / (1 + np.exp(-acceleration * (day_points - grace_period)/days))
|
|
|
|
|
|
|
|
|
|
# Introduce randomness in the failure rate
|
|
|
|
|
random_noise = np.random.normal(0.0, 0.05, (numEquipments, days)) # Mean 0.0, Std Dev 0.05
|
|
|
|
|
daily_failure_rate = daily_failure_rate + random_noise
|
|
|
|
|
daily_failure_rate = np.clip(daily_failure_rate, 0, None) # Ensure failure rate is non-negative
|
|
|
|
|
|
|
|
|
|
# Calculate cumulative failures
|
|
|
|
|
failure_counts = np.cumsum(daily_failure_rate)
|
|
|
|
|
failure_counts = np.cumsum(daily_failure_rate, axis=1)
|
|
|
|
|
|
|
|
|
|
# Calculate corrective costs based on cumulative failures and combined costs
|
|
|
|
|
cost_per_failure = material_cost + service_cost
|
|
|
|
|
@ -203,7 +246,8 @@ async def create_calculation_result_service(
|
|
|
|
|
|
|
|
|
|
overhaul_cost_points = get_overhaul_cost_by_time_chart(
|
|
|
|
|
calculation_data.parameter.overhaul_cost,
|
|
|
|
|
days=days
|
|
|
|
|
days=days,
|
|
|
|
|
numEquipments=len(equipments)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|