From 7eea3cea407fc6efa115a7e4159a21aaa212f881 Mon Sep 17 00:00:00 2001 From: maksim Date: Wed, 20 Nov 2024 00:11:58 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4,=20?= =?UTF-8?q?=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=B9=20=D1=81=D0=B2=D1=8F?= =?UTF-8?q?=D0=B7=D1=8B=D0=B2=D0=B0=D0=B5=D1=82=20=D1=81=20=D0=B4=D1=80?= =?UTF-8?q?=D1=83=D0=B3=D0=B8=D0=BC=D0=B8=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8?= =?UTF-8?q?=D1=86=D0=B0=D0=BC=D0=B8=20(load=20=D0=B8=20recyle)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/models/load_parameters_model.py | 2 +- db/models/recycling_parameters_model.py | 2 +- main.py | 2 +- .../routes/experiment_parameters_router.py | 53 +++++++++++++++++++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/db/models/load_parameters_model.py b/db/models/load_parameters_model.py index ffb5a8a..9f84dac 100644 --- a/db/models/load_parameters_model.py +++ b/db/models/load_parameters_model.py @@ -7,7 +7,7 @@ from db.models.base import Base class LoadParameters(Base): __tablename__ = 'load_parameters' - id: Mapped[int] = mapped_column(Identity(start=6, cycle=True), + id: Mapped[int] = mapped_column(Identity(start=1000, cycle=True), primary_key=True) load: Mapped[int] primary_air_consumption: Mapped[float] diff --git a/db/models/recycling_parameters_model.py b/db/models/recycling_parameters_model.py index 507b261..4e22524 100644 --- a/db/models/recycling_parameters_model.py +++ b/db/models/recycling_parameters_model.py @@ -9,7 +9,7 @@ from db.models.base import Base class RecyclingParameters(Base): __tablename__ = 'recycling_parameters' - id: Mapped[int] = mapped_column(Identity(start=6, cycle=True), + id: Mapped[int] = mapped_column(Identity(start=1000, cycle=True), primary_key=True) load_id: Mapped[Optional[int]] = mapped_column(ForeignKey('load_parameters.id', ondelete='SET NULL')) diff --git a/main.py b/main.py index f1892fb..74e5fdd 100644 --- a/main.py +++ b/main.py @@ -73,7 +73,7 @@ async def init_db_data(background_tasks: BackgroundTasks): # "oxidizer_temp": [471, 493] # }, # "count_exp": 1440, -# "round_rules": [0, 1, 1, 0, 1, 1, 1] +# "round_rules": [0, 1, 1, 0, 0, 0, 0] # } @app.post("/pyDOE3_screening_design") diff --git a/network/routes/experiment_parameters_router.py b/network/routes/experiment_parameters_router.py index 189dfd7..d79bd89 100644 --- a/network/routes/experiment_parameters_router.py +++ b/network/routes/experiment_parameters_router.py @@ -89,3 +89,56 @@ async def delete_experiment_parameters(id: int): return {"message": "Запись не найдена"} except Exception as e: raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}") + +@router.post('/process_and_save/{id}') +async def process_and_save_experiment_data(id: int): + try: + # Получаем данные из ExperimentParameters по id + experiment = await get_by_id(ExperimentParameters, id) + if experiment is None: + raise HTTPException(status_code=404, detail=f"ExperimentParameters с id {id} не найден.") + + # Пример обработки данных + load_value = experiment.outer_blades_length * experiment.middle_blades_count + primary_air_consumption = load_value * 0.1 # Условный коэффициент + secondary_air_consumption = load_value * 0.05 + gas_inlet_consumption = load_value * 0.03 + + recycling_level = experiment.outer_blades_count * 0.5 + co2 = recycling_level * 0.02 + n2 = recycling_level * 0.01 + h2o = recycling_level * 0.005 + o2 = recycling_level * 0.015 + + # Сохраняем данные в LoadParameters + load_params = await create( + LoadParameters, + load=int(load_value), + primary_air_consumption=primary_air_consumption, + secondary_air_consumption=secondary_air_consumption, + gas_inlet_consumption=gas_inlet_consumption + ) + + # Сохраняем данные в RecyclingParameters + recycling_params = await create( + RecyclingParameters, + load_id=load_params.id, + recycling_level=int(recycling_level), + co2=co2, + n2=n2, + h2o=h2o, + o2=o2 + ) + + # Обновляем ExperimentParameters, чтобы сохранить связи + experiment.load_id = load_params.id + experiment.recycling_id = recycling_params.id + + return { + "message": "Данные успешно обработаны и сохранены.", + "load_parameters": load_params, + "recycling_parameters": recycling_params + } + + except Exception as e: + raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")