|
|
|
|
@ -1,11 +1,13 @@
|
|
|
|
|
import numpy as np
|
|
|
|
|
from sqlalchemy import Select, func, select
|
|
|
|
|
from src.workorder.model import MasterWorkOrder
|
|
|
|
|
from src.scope_equipment.model import ScopeEquipment
|
|
|
|
|
from src.scope.model import Scope
|
|
|
|
|
from src.database.core import DbSession
|
|
|
|
|
from src.scope.service import get_all
|
|
|
|
|
from .schema import CalculationTimeConstrainsParametersRead
|
|
|
|
|
from .service import get_overhaul_cost_by_time_chart
|
|
|
|
|
from .schema import CalculationTimeConstrainsParametersRead, CalculationTimeConstrainsCreate
|
|
|
|
|
from .service import get_overhaul_cost_by_time_chart, get_corrective_cost_time_chart
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_create_calculation_parameters(*, db_session: DbSession):
|
|
|
|
|
stmt = (
|
|
|
|
|
@ -40,27 +42,48 @@ async def get_create_calculation_parameters(*, db_session: DbSession):
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def create_calculation(*, db_session: DbSession):
|
|
|
|
|
|
|
|
|
|
async def create_calculation(*, db_session: DbSession, calculation_time_constrains_in: CalculationTimeConstrainsCreate):
|
|
|
|
|
days = 365
|
|
|
|
|
##
|
|
|
|
|
overhaul_cost_points = get_overhaul_cost_by_time_chart(
|
|
|
|
|
calculation_time_constrains_in.overhaulCost, days)
|
|
|
|
|
corrective_cost_points, dailyNumberOfFailure = get_corrective_cost_time_chart(
|
|
|
|
|
calculation_time_constrains_in.costPerFailure, days)
|
|
|
|
|
|
|
|
|
|
total_cost = overhaul_cost_points + corrective_cost_points
|
|
|
|
|
|
|
|
|
|
optimumOH = np.argmin(total_cost)
|
|
|
|
|
numbersOfFailure = sum(dailyNumberOfFailure[:optimumOH])
|
|
|
|
|
|
|
|
|
|
# raise Exception(optimumOH)
|
|
|
|
|
|
|
|
|
|
points = []
|
|
|
|
|
for i in range(days):
|
|
|
|
|
points.append({
|
|
|
|
|
"day": int(i+1),
|
|
|
|
|
"overhaulCost": float(overhaul_cost_points[i]),
|
|
|
|
|
"correctiveCost": float(corrective_cost_points[i]),
|
|
|
|
|
"totalCost": float(overhaul_cost_points[i] + corrective_cost_points[i]),
|
|
|
|
|
# "dailyFailureRate": float(daily_failure_rate[i]),
|
|
|
|
|
# "cumulativeFailures": float(failure_counts[i])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
"id": "calc_123",
|
|
|
|
|
"result": {
|
|
|
|
|
"summary": {
|
|
|
|
|
"scope": "B",
|
|
|
|
|
"numberOfFailures": 59,
|
|
|
|
|
"optimumOHTime": 90,
|
|
|
|
|
"optimumTotalCost": 500000000
|
|
|
|
|
"scope": calculation_time_constrains_in.scopeOH,
|
|
|
|
|
"numberOfFailures": int(np.floor(numbersOfFailure)),
|
|
|
|
|
"optimumOHTime": int(optimumOH+1),
|
|
|
|
|
"optimumTotalCost": float(total_cost[optimumOH]),
|
|
|
|
|
},
|
|
|
|
|
"chartData": {},
|
|
|
|
|
"comparisons": {
|
|
|
|
|
"vsLastCalculation": {
|
|
|
|
|
"costDifference": -50000000,
|
|
|
|
|
"timeChange": "+15 days"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
"chartData": points,
|
|
|
|
|
# "comparisons": {
|
|
|
|
|
# "vsLastCalculation": {
|
|
|
|
|
# "costDifference": -50000000,
|
|
|
|
|
# "timeChange": "+15 days"
|
|
|
|
|
# }
|
|
|
|
|
# }
|
|
|
|
|
},
|
|
|
|
|
"simulationLimits": {
|
|
|
|
|
"minInterval": 30,
|
|
|
|
|
|