|
|
|
|
@ -1,9 +1,11 @@
|
|
|
|
|
from typing import Optional
|
|
|
|
|
from uuid import UUID
|
|
|
|
|
import numpy as np
|
|
|
|
|
from sqlalchemy import and_, select
|
|
|
|
|
from sqlalchemy import and_, func, select
|
|
|
|
|
from sqlalchemy.orm import joinedload
|
|
|
|
|
from src.database.core import DbSession
|
|
|
|
|
from src.scope_equipment.model import ScopeEquipment
|
|
|
|
|
from src.workorder.model import MasterWorkOrder
|
|
|
|
|
from .schema import CalculationTimeConstrainsParametersCreate, CalculationTimeConstrainsRead
|
|
|
|
|
from .model import CalculationParam, OverhaulReferenceType, CalculationData, CalculationResult
|
|
|
|
|
from fastapi import HTTPException, status
|
|
|
|
|
@ -110,14 +112,14 @@ async def get_calculation_data_by_id(db_session: DbSession, calculation_id) -> C
|
|
|
|
|
return result.unique().scalar()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def create_calculation_result_service(db_session: DbSession, calculation_id: UUID):
|
|
|
|
|
async def create_calculation_result_service(db_session: DbSession, calculation_id: UUID, costPerFailure: Optional[float]):
|
|
|
|
|
days = 60
|
|
|
|
|
calculation = await get_calculation_data_by_id(db_session=db_session, calculation_id=calculation_id)
|
|
|
|
|
reference = calculation.reference_id if calculation.overhaul_reference_type == OverhaulReferenceType.ASSET else await get(db_session=db_session, scope_id=calculation.reference_id)
|
|
|
|
|
|
|
|
|
|
# Parameter
|
|
|
|
|
overhaulCost = calculation.parameter.overhaul_cost
|
|
|
|
|
costPerFailure = calculation.parameter.avg_failure_cost
|
|
|
|
|
costPerFailure = costPerFailure if costPerFailure else calculation.parameter.avg_failure_cost
|
|
|
|
|
|
|
|
|
|
overhaul_cost_points = get_overhaul_cost_by_time_chart(
|
|
|
|
|
overhaulCost, days=days)
|
|
|
|
|
@ -168,19 +170,28 @@ async def get_calculation_by_reference_and_parameter(*, db_session: DbSession, c
|
|
|
|
|
CalculationData.reference_id == calculation_reference_id,
|
|
|
|
|
CalculationData.parameter_id == parameter_id,
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = await db_session.execute(stmt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result.scalar()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_calculation_result_by_day(*, db_session:DbSession, calculation_id, simulation_day):
|
|
|
|
|
async def get_calculation_result_by_day(*, db_session: DbSession, calculation_id, simulation_day):
|
|
|
|
|
stmt = select(CalculationResult).filter(and_(
|
|
|
|
|
CalculationResult.day == simulation_day,
|
|
|
|
|
CalculationResult.calculation_data_id == calculation_id
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = await db_session.execute(stmt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result.scalar()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_avg_cost_by_asset(*, db_session: DbSession, assetnum: str):
|
|
|
|
|
stmt = (
|
|
|
|
|
select(func.avg(MasterWorkOrder.total_cost_max).label('average_cost'))
|
|
|
|
|
.where(MasterWorkOrder.assetnum == assetnum)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
result = await db_session.execute(stmt)
|
|
|
|
|
return result.scalar_one_or_none()
|
|
|
|
|
|