PIbd-42_SSPR/main.py
AnnZhimol 49e327005e Update Database:
+ch_experiment_data in click_house
+experiment_data and experiment_parameters in postgresql
+experiment_data has foreign_key from experiment_parameters
+new connections
+realize routes for ch_experiment_data
+new alg csv_to_db
+new methods in repos
+update dockerfile
+update readme "how to init db"
2024-10-25 01:02:31 +03:00

55 lines
2.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import asyncio
from fastapi import FastAPI, HTTPException, BackgroundTasks
from db.csv_to_db import csv_to_db
from network.routes import ch_experimentdb_experiment_data_router, experiment_data_router, experiment_parameters_router
from network.routes import load_parameters_router, recycling_parameters_router
from network.schemas import *
from new_experiment_planner import run_experiment
app = FastAPI()
app.include_router(ch_experimentdb_experiment_data_router.router,
prefix="/ch_experimentdb_experiment_data",
tags=["ch_experimentdb_experiment_data"])
app.include_router(experiment_data_router.router,
prefix="/experiment_data",
tags=["experiment_data"])
app.include_router(experiment_parameters_router.router,
prefix="/experiment_parameters",
tags=["experiment_parameters"])
app.include_router(load_parameters_router.router,
prefix="/load_parameters",
tags=["load_parameters"])
app.include_router(recycling_parameters_router.router,
prefix="/recycling_parameters",
tags=["recycling_parameters"])
# Эндпоинт для запуска эксперимента
@app.post("/run_experiment/")
def run_experiment_api(params: ExperimentParameters):
try:
# Вызываем функцию run_experiment с параметрами
run_experiment(
params.outer_blades_count,
params.outer_blades_length,
params.outer_blades_angle,
params.middle_blades_count,
params.load,
params.recycling
)
return {"status": "success", "message": "Experiment started successfully."}
except Exception as e:
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
# эндпоинт инициализации бд из csv файлов
@app.get('/init_db_data')
async def init_db_data(background_tasks: BackgroundTasks):
try:
background_tasks.add_task(csv_to_db)
return {"status": "success", "message": "Инициализация БД запущена в фоне"}
except Exception as e:
print(str(e.with_traceback()))
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")