|
|
|
|
@ -11,6 +11,7 @@ from sqlalchemy.orm import joinedload
|
|
|
|
|
from src.database.core import DbSession
|
|
|
|
|
from src.overhaul_activity.service import get_all_by_session_id
|
|
|
|
|
from src.overhaul_scope.service import get as get_scope
|
|
|
|
|
from src.utils import get_latest_numOfFail
|
|
|
|
|
from src.workorder.model import MasterWorkOrder
|
|
|
|
|
|
|
|
|
|
from .model import (CalculationData, CalculationEquipmentResult,
|
|
|
|
|
@ -20,7 +21,6 @@ from .schema import (CalculationResultsRead,
|
|
|
|
|
CalculationTimeConstrainsParametersCreate,
|
|
|
|
|
CalculationTimeConstrainsRead, OptimumResult)
|
|
|
|
|
|
|
|
|
|
from src.utils import get_latest_numOfFail
|
|
|
|
|
|
|
|
|
|
def get_overhaul_cost_by_time_chart(
|
|
|
|
|
overhaul_cost: float, days: int, numEquipments: int, decay_base: float = 1.01
|
|
|
|
|
@ -32,7 +32,7 @@ def get_overhaul_cost_by_time_chart(
|
|
|
|
|
|
|
|
|
|
hours = days * 24
|
|
|
|
|
|
|
|
|
|
rate = np.arange(1, hours+1)
|
|
|
|
|
rate = np.arange(1, hours + 1)
|
|
|
|
|
|
|
|
|
|
cost_per_equipment = overhaul_cost / numEquipments
|
|
|
|
|
|
|
|
|
|
@ -79,7 +79,7 @@ async def get_corrective_cost_time_chart(
|
|
|
|
|
## Get latest data fromdata_today
|
|
|
|
|
# latest_num_of_fail:float = get_latest_numOfFail(location_tag=location_tag, token=token)
|
|
|
|
|
|
|
|
|
|
latest_num = data['data'][-1]['num_fail']
|
|
|
|
|
latest_num = data["data"][-1]["num_fail"]
|
|
|
|
|
|
|
|
|
|
if not latest_num:
|
|
|
|
|
latest_num = 1
|
|
|
|
|
@ -94,7 +94,6 @@ async def get_corrective_cost_time_chart(
|
|
|
|
|
for item in data["data"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Fill in missing dates with nearest available value
|
|
|
|
|
complete_data = []
|
|
|
|
|
last_known_value = 0 # Default value if no data is available
|
|
|
|
|
@ -112,8 +111,6 @@ async def get_corrective_cost_time_chart(
|
|
|
|
|
|
|
|
|
|
hourly_failure = np.repeat(daily_failure, 24) / 24
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# failure_counts = np.cumsum(daily_failure)
|
|
|
|
|
|
|
|
|
|
# Calculate corrective costs
|
|
|
|
|
@ -124,7 +121,6 @@ async def get_corrective_cost_time_chart(
|
|
|
|
|
|
|
|
|
|
corrective_costs = hourly_failure * cost_per_failure
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return corrective_costs, hourly_failure
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
@ -185,7 +181,7 @@ async def create_param_and_data(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_calculation_result(db_session: DbSession, calculation_id: str):
|
|
|
|
|
days = 667*24
|
|
|
|
|
days = 667 * 24
|
|
|
|
|
scope_calculation = await get_calculation_data_by_id(
|
|
|
|
|
db_session=db_session, calculation_id=calculation_id
|
|
|
|
|
)
|
|
|
|
|
@ -249,6 +245,19 @@ async def get_calculation_data_by_id(
|
|
|
|
|
return result.unique().scalar()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_calculation_by_assetnum(
|
|
|
|
|
*, db_session: DbSession, assetnum: str, calculation_id: str
|
|
|
|
|
):
|
|
|
|
|
stmt = (
|
|
|
|
|
select(CalculationEquipmentResult)
|
|
|
|
|
.where(CalculationEquipmentResult.assetnum == assetnum)
|
|
|
|
|
.where(CalculationEquipmentResult.calculation_data_id == calculation_id)
|
|
|
|
|
)
|
|
|
|
|
result = await db_session.execute(stmt)
|
|
|
|
|
|
|
|
|
|
return result.scalar()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# async def create_calculation_result_service(db_session: DbSession, calculation_id: UUID, costPerFailure: Optional[float] = None):
|
|
|
|
|
# days = 360
|
|
|
|
|
# calculation = await get_calculation_data_by_id(db_session=db_session, calculation_id=calculation_id)
|
|
|
|
|
@ -327,8 +336,8 @@ async def create_calculation_result_service(
|
|
|
|
|
|
|
|
|
|
# Store results for each equipment
|
|
|
|
|
equipment_results: List[CalculationEquipmentResult] = []
|
|
|
|
|
total_corrective_costs = np.zeros(days*24)
|
|
|
|
|
total_daily_failures = np.zeros(days*24)
|
|
|
|
|
total_corrective_costs = np.zeros(days * 24)
|
|
|
|
|
total_daily_failures = np.zeros(days * 24)
|
|
|
|
|
|
|
|
|
|
# Calculate for each equipment
|
|
|
|
|
for eq in equipments:
|
|
|
|
|
@ -337,7 +346,7 @@ async def create_calculation_result_service(
|
|
|
|
|
service_cost=eq.service_cost,
|
|
|
|
|
token=token,
|
|
|
|
|
location_tag=eq.equipment.location_tag,
|
|
|
|
|
max_days=667
|
|
|
|
|
max_days=667,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
overhaul_cost_points = get_overhaul_cost_by_time_chart(
|
|
|
|
|
|