|
|
|
|
@ -37,10 +37,13 @@ active_simulations = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Get Data Service
|
|
|
|
|
async def get_all(common: CommonParameters, status):
|
|
|
|
|
async def get_all(common: CommonParameters, status, current_user):
|
|
|
|
|
query = select(AerosSimulation).order_by(desc(AerosSimulation.created_at))
|
|
|
|
|
if status:
|
|
|
|
|
query = query.where(AerosSimulation.status == "completed")
|
|
|
|
|
|
|
|
|
|
if current_user.role.lower() != "admin":
|
|
|
|
|
query = query.where(AerosSimulation.created_by == current_user.user_id)
|
|
|
|
|
|
|
|
|
|
results = await search_filter_sort_paginate(model=query, **common)
|
|
|
|
|
|
|
|
|
|
@ -225,7 +228,7 @@ async def get_result_ranking(*, db_session: DbSession, simulation_id: UUID, limi
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
query = query.order_by(AerosSimulationCalcResult.availability.desc())
|
|
|
|
|
query = query.order_by(AerosSimulationCalcResult.availability.asc())
|
|
|
|
|
|
|
|
|
|
if limit:
|
|
|
|
|
query = query.limit(limit)
|
|
|
|
|
@ -987,9 +990,10 @@ def convert_id_to_none_if_negative(value):
|
|
|
|
|
return None if value < 0 else value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def create_simulation(*, db_session: DbSession, simulation_in: SimulationInput):
|
|
|
|
|
async def create_simulation(*, db_session: DbSession, simulation_in: SimulationInput, current_user):
|
|
|
|
|
"""Create a new simulation."""
|
|
|
|
|
input = simulation_in.model_dump(exclude={"SimulationName"})
|
|
|
|
|
user_id = current_user.get("user_id")
|
|
|
|
|
|
|
|
|
|
# Check if is default
|
|
|
|
|
if simulation_in.IsDefault:
|
|
|
|
|
@ -1005,7 +1009,8 @@ async def create_simulation(*, db_session: DbSession, simulation_in: SimulationI
|
|
|
|
|
"schematic_name": "- TJB - Unit 3 -",
|
|
|
|
|
"is_default": simulation_in.IsDefault,
|
|
|
|
|
"duration": simulation_in.SimDuration,
|
|
|
|
|
"offset": simulation_in.OffSet
|
|
|
|
|
"offset": simulation_in.OffSet,
|
|
|
|
|
"created_by": user_id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
simulation = AerosSimulation(**active_simulations)
|
|
|
|
|
|