|
|
|
|
@ -26,7 +26,7 @@ from .model import (
|
|
|
|
|
)
|
|
|
|
|
from src.aeros_equipment.model import AerosEquipment, AerosEquipmentCustomParameterData
|
|
|
|
|
from src.aeros_equipment.schema import EquipmentWithCustomParameters
|
|
|
|
|
from .schema import SimulationInput, SimulationRankingParameters
|
|
|
|
|
from .schema import SimulationInput, SimulationPlotResult, SimulationRankingParameters
|
|
|
|
|
from .utils import calculate_eaf
|
|
|
|
|
|
|
|
|
|
client = httpx.AsyncClient(timeout=300.0)
|
|
|
|
|
@ -232,27 +232,56 @@ async def get_result_ranking(*, db_session: DbSession, simulation_id: UUID):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_simulation_with_plot_result(
|
|
|
|
|
*, db_session: DbSession, simulation_id: UUID, node_type: Optional[str] = None
|
|
|
|
|
*, db_session: DbSession, simulation_id: UUID, node_type: Optional[str] = None, node_id: Optional[str] = None
|
|
|
|
|
):
|
|
|
|
|
"""Get a simulation by id."""
|
|
|
|
|
query = (
|
|
|
|
|
select(AerosSimulation)
|
|
|
|
|
.where(AerosSimulation.id == simulation_id)
|
|
|
|
|
.options(
|
|
|
|
|
selectinload(AerosSimulation.plot_results).options(
|
|
|
|
|
selectinload(AerosSimulationPlotResult.aeros_node)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if node_type:
|
|
|
|
|
query = query.join(
|
|
|
|
|
AerosNode, AerosNode.id == AerosSimulation.plot_results.aeros_node_id
|
|
|
|
|
).filter(AerosNode.node_type == node_type)
|
|
|
|
|
|
|
|
|
|
simulation = await db_session.execute(query)
|
|
|
|
|
return simulation.scalar()
|
|
|
|
|
# query = (
|
|
|
|
|
# select(AerosSimulation)
|
|
|
|
|
# .where(AerosSimulation.id == simulation_id)
|
|
|
|
|
# .options(
|
|
|
|
|
# selectinload(AerosSimulation.plot_results).options(
|
|
|
|
|
# selectinload(AerosSimulationPlotResult.aeros_node)
|
|
|
|
|
# )
|
|
|
|
|
# )
|
|
|
|
|
# )
|
|
|
|
|
|
|
|
|
|
# if node_type:
|
|
|
|
|
# query = query.join(
|
|
|
|
|
# AerosNode, AerosNode.id == AerosSimulation.plot_results.aeros_node_id
|
|
|
|
|
# ).filter(AerosNode.node_type == node_type)
|
|
|
|
|
|
|
|
|
|
# if node_id:
|
|
|
|
|
# if node_id == 'plant':
|
|
|
|
|
# query = query.join(
|
|
|
|
|
# AerosNode, AerosNode.id == AerosSimulation.plot_results.aeros_node_id
|
|
|
|
|
# ).filter(AerosNode.node_name == '- TJB - Unit 3 -')
|
|
|
|
|
# else:
|
|
|
|
|
# query = query.join(
|
|
|
|
|
# AerosNode, AerosNode.id == AerosSimulation.plot_results.aeros_node_id
|
|
|
|
|
# ).filter(AerosNode.id == node_id)
|
|
|
|
|
|
|
|
|
|
# simulation = await db_session.execute(query)
|
|
|
|
|
# return simulation.scalar()
|
|
|
|
|
|
|
|
|
|
query = select(AerosSimulationPlotResult).where(
|
|
|
|
|
AerosSimulationPlotResult.aeros_simulation_id == simulation_id
|
|
|
|
|
).options(selectinload(AerosSimulationPlotResult.aeros_node))
|
|
|
|
|
|
|
|
|
|
if node_id:
|
|
|
|
|
if node_id == 'plant':
|
|
|
|
|
query = query.join(
|
|
|
|
|
AerosNode, AerosNode.id == AerosSimulationPlotResult.aeros_node_id
|
|
|
|
|
).filter(AerosNode.node_name == '- TJB - Unit 3 -')
|
|
|
|
|
else:
|
|
|
|
|
query = query.join(
|
|
|
|
|
AerosNode, AerosNode.id == AerosSimulationPlotResult.aeros_node_id
|
|
|
|
|
).filter(AerosNode.id == node_id)
|
|
|
|
|
|
|
|
|
|
res = await db_session.execute(query)
|
|
|
|
|
return res.scalar_one_or_none()
|
|
|
|
|
|
|
|
|
|
simulation_plots = await db_session.execute(query)
|
|
|
|
|
return simulation_plots.scalars().all()
|
|
|
|
|
|
|
|
|
|
async def get_calc_result_by(
|
|
|
|
|
*, db_session: DbSession, simulation_id: UUID, node_name: Optional[str] = None
|
|
|
|
|
@ -548,9 +577,33 @@ async def save_simulation_result(
|
|
|
|
|
}
|
|
|
|
|
calc_objects = []
|
|
|
|
|
plot_objects = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
for result in plot_result:
|
|
|
|
|
node_type = "RegularNode" if result["nodeType"] == "RegularNode" else "SchematicNode"
|
|
|
|
|
node = avaiable_nodes.get(f"{node_type}:{result['nodeName']}", None)
|
|
|
|
|
if not node:
|
|
|
|
|
if result["nodeType"] != "RegularNode" and result["nodeType"] != "Schematic":
|
|
|
|
|
continue
|
|
|
|
|
node = await get_or_save_node(
|
|
|
|
|
db_session=db_session, node_data=result, type="plot"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
plot_result = AerosSimulationPlotResult(
|
|
|
|
|
aeros_simulation_id=simulation_id,
|
|
|
|
|
aeros_node_id=node.id,
|
|
|
|
|
max_flow_rate=result["maxFlowrate"],
|
|
|
|
|
storage_capacity=result["storageCapacity"],
|
|
|
|
|
point_availabilities=result["pointAvailabilities"],
|
|
|
|
|
point_flowrates=result["pointFlowrates"],
|
|
|
|
|
timestamp_outs=result["timeStampOuts"],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
plot_objects.append(plot_result)
|
|
|
|
|
|
|
|
|
|
for result in calc_result:
|
|
|
|
|
node_type = "RegularNode" if result["nodeType"] == "RegularNode" else "SchematicNode"
|
|
|
|
|
node = avaiable_nodes.get(f"{node_type}:{result['nodeName']}", None)
|
|
|
|
|
@ -561,6 +614,9 @@ async def save_simulation_result(
|
|
|
|
|
"mttr": 0,
|
|
|
|
|
"parameters": {}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
plot_data = next(plot for plot in plot_objects if plot.aeros_node_id == node.id) if node else {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not node:
|
|
|
|
|
@ -574,7 +630,9 @@ async def save_simulation_result(
|
|
|
|
|
available_hours=result["totalUpTime"],
|
|
|
|
|
period_hours=result["totalUpTime"] + result["totalDowntime"],
|
|
|
|
|
actual_production=result["production"],
|
|
|
|
|
ideal_production=result["idealProduction"]
|
|
|
|
|
ideal_production=result["idealProduction"],
|
|
|
|
|
downtime_hours = result["totalDowntime"],
|
|
|
|
|
plot_data=plot_data
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
efor = (result["totalDowntime"] / (result["totalDowntime"] + result["totalUpTime"]))*100 if (result["totalDowntime"] + result["totalUpTime"]) > 0 else 0
|
|
|
|
|
@ -623,27 +681,7 @@ async def save_simulation_result(
|
|
|
|
|
|
|
|
|
|
calc_objects.append(calc_result)
|
|
|
|
|
|
|
|
|
|
for result in plot_result:
|
|
|
|
|
node_type = "RegularNode" if result["nodeType"] == "RegularNode" else "SchematicNode"
|
|
|
|
|
node = avaiable_nodes.get(f"{node_type}:{result['nodeName']}", None)
|
|
|
|
|
if not node:
|
|
|
|
|
if result["nodeType"] != "RegularNode" and result["nodeType"] != "Schematic":
|
|
|
|
|
continue
|
|
|
|
|
node = await get_or_save_node(
|
|
|
|
|
db_session=db_session, node_data=result, type="plot"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
plot_result = AerosSimulationPlotResult(
|
|
|
|
|
aeros_simulation_id=simulation_id,
|
|
|
|
|
aeros_node_id=node.id,
|
|
|
|
|
max_flow_rate=result["maxFlowrate"],
|
|
|
|
|
storage_capacity=result["storageCapacity"],
|
|
|
|
|
point_availabilities=result["pointAvailabilities"],
|
|
|
|
|
point_flowrates=result["pointFlowrates"],
|
|
|
|
|
timestamp_outs=result["timeStampOuts"],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
plot_objects.append(plot_result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
simulation = await get_simulation_by_id(
|
|
|
|
|
|