2024-10-14 21:18:07 +04:00
|
|
|
from typing import Optional
|
|
|
|
from sqlalchemy import select
|
|
|
|
from db.db_connection import async_session
|
|
|
|
from db.models.experiment_parameters_model import ExperimentParameters
|
2024-10-22 16:46:39 +04:00
|
|
|
from network.schemas import ExperimentParametersBody
|
2024-10-14 21:18:07 +04:00
|
|
|
|
|
|
|
|
|
|
|
class ExperimentParametersRepository:
|
|
|
|
@staticmethod
|
|
|
|
async def get_all() -> Optional[list[ExperimentParameters]]:
|
|
|
|
async with async_session() as session:
|
|
|
|
result = await session.execute(select(ExperimentParameters))
|
2024-10-18 16:42:39 +04:00
|
|
|
return result.scalars().all()
|
2024-10-14 21:18:07 +04:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
async def get_by_id(id_: int) -> Optional[ExperimentParameters]:
|
|
|
|
async with async_session() as session:
|
2024-10-18 16:42:39 +04:00
|
|
|
result = session.get(ExperimentParameters, id_)
|
|
|
|
return result
|
2024-10-14 21:18:07 +04:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
async def create(outer_blades_count: int,
|
|
|
|
outer_blades_length: float,
|
|
|
|
outer_blades_angle: float,
|
|
|
|
middle_blades_count: int,
|
|
|
|
load_id: int,
|
|
|
|
recycling_id: int,
|
|
|
|
experiment_hash: str):
|
|
|
|
new_data = ExperimentParameters(
|
|
|
|
outer_blades_count=outer_blades_count,
|
|
|
|
outer_blades_length=outer_blades_length,
|
|
|
|
outer_blades_angle=outer_blades_angle,
|
|
|
|
middle_blades_count=middle_blades_count,
|
|
|
|
load_id=load_id,
|
|
|
|
recycling_id=recycling_id,
|
|
|
|
experiment_hash=experiment_hash
|
|
|
|
)
|
|
|
|
async with async_session() as session:
|
|
|
|
session.add(new_data)
|
|
|
|
await session.commit()
|
2024-10-22 16:46:39 +04:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
async def create_from_pydantic(body: ExperimentParametersBody):
|
|
|
|
new_data = ExperimentParameters(
|
|
|
|
outer_blades_count=body.outer_blades_count,
|
|
|
|
outer_blades_length=body.outer_blades_length,
|
|
|
|
outer_blades_angle=body.outer_blades_angle,
|
|
|
|
middle_blades_count=body.middle_blades_count,
|
|
|
|
load_id=body.load_id,
|
|
|
|
recycling_id=body.recycling_id,
|
|
|
|
experiment_hash=body.experiment_hash
|
|
|
|
)
|
|
|
|
async with async_session() as session:
|
|
|
|
session.add(new_data)
|
|
|
|
await session.commit()
|