|
|
|
|
@ -1031,8 +1031,32 @@ class OptimumCostModel:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
raise # Non-retryable errors
|
|
|
|
|
|
|
|
|
|
def _get_equipment_fr(
|
|
|
|
|
self,
|
|
|
|
|
location_tag: str,
|
|
|
|
|
token: str
|
|
|
|
|
):
|
|
|
|
|
failure_rate_url = f"{self.api_base_url}/reliability/asset/failure-rate/{self.location_tag}"
|
|
|
|
|
try:
|
|
|
|
|
response = requests.get(
|
|
|
|
|
failure_rate_url,
|
|
|
|
|
headers={
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
"Authorization": f"Bearer {token}",
|
|
|
|
|
},
|
|
|
|
|
timeout=10
|
|
|
|
|
)
|
|
|
|
|
response.raise_for_status()
|
|
|
|
|
result = response.json()
|
|
|
|
|
except (requests.RequestException, ValueError) as e:
|
|
|
|
|
raise Exception(f"Failed to fetch or parse mdt data: {e}")
|
|
|
|
|
|
|
|
|
|
fr = result["data"]["failure_rate"]
|
|
|
|
|
|
|
|
|
|
return fr
|
|
|
|
|
|
|
|
|
|
def _calculate_costs_vectorized(self, reliabilities: Dict[datetime, float],
|
|
|
|
|
preventive_cost: float, failure_replacement_cost: float) -> List[Dict]:
|
|
|
|
|
preventive_cost: float, failure_replacement_cost: float, failure_rate) -> List[Dict]:
|
|
|
|
|
valid_data = [(date, rel) for date, rel in reliabilities.items() if rel is not None]
|
|
|
|
|
if not valid_data:
|
|
|
|
|
return []
|
|
|
|
|
@ -1064,7 +1088,7 @@ class OptimumCostModel:
|
|
|
|
|
|
|
|
|
|
# Calculate costs according to the formula
|
|
|
|
|
# Failure cost = (1-R(T)) × IDRu / ∫₀ᵀ R(t) dt
|
|
|
|
|
failure_costs = (failure_probs * failure_replacement_cost) / expected_operating_times
|
|
|
|
|
failure_costs = (failure_rate * failure_replacement_cost * expected_operating_times)
|
|
|
|
|
# Preventive cost = R(T) × IDRp / ∫₀ᵀ R(t) dt
|
|
|
|
|
preventive_costs = (reliability_values * preventive_cost) / expected_operating_times
|
|
|
|
|
|
|
|
|
|
@ -1153,7 +1177,7 @@ class OptimumCostModel:
|
|
|
|
|
|
|
|
|
|
# Get pre-fetched reliability data
|
|
|
|
|
reliabilities = all_reliabilities.get(location_tag, {})
|
|
|
|
|
|
|
|
|
|
failure_rate = self._get_equipment_fr(location_tag, self.token)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not reliabilities:
|
|
|
|
|
@ -1165,6 +1189,7 @@ class OptimumCostModel:
|
|
|
|
|
reliabilities=reliabilities,
|
|
|
|
|
preventive_cost=preventive_cost_per_equipment,
|
|
|
|
|
failure_replacement_cost=cost_per_failure
|
|
|
|
|
failute_rate=failure_rate
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if not predicted_costs:
|
|
|
|
|
|