2024-10-25 02:02:31 +04:00
|
|
|
|
from fastapi import FastAPI, HTTPException, BackgroundTasks
|
2024-10-28 13:30:02 +04:00
|
|
|
|
|
2024-10-15 16:34:09 +04:00
|
|
|
|
from db.csv_to_db import csv_to_db
|
2024-10-27 23:29:52 +04:00
|
|
|
|
from network.routes import (ch_experimentdb_experiment_data_router, experiment_data_router,
|
|
|
|
|
experiment_parameters_router, experiment_category_router)
|
2024-10-22 16:46:39 +04:00
|
|
|
|
from network.routes import load_parameters_router, recycling_parameters_router
|
|
|
|
|
from network.schemas import *
|
2024-10-25 02:02:31 +04:00
|
|
|
|
from new_experiment_planner import run_experiment
|
2024-10-08 21:21:05 +04:00
|
|
|
|
|
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
2024-10-22 16:46:39 +04:00
|
|
|
|
app.include_router(ch_experimentdb_experiment_data_router.router,
|
|
|
|
|
prefix="/ch_experimentdb_experiment_data",
|
|
|
|
|
tags=["ch_experimentdb_experiment_data"])
|
2024-10-27 23:29:52 +04:00
|
|
|
|
app.include_router(experiment_category_router.router,
|
|
|
|
|
prefix="/experiment_category",
|
|
|
|
|
tags=["experiment_category"])
|
2024-10-22 16:46:39 +04:00
|
|
|
|
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"])
|
2024-10-17 17:13:21 +04:00
|
|
|
|
|
|
|
|
|
|
2024-10-08 21:21:05 +04:00
|
|
|
|
# Эндпоинт для запуска эксперимента
|
|
|
|
|
@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)}")
|
2024-10-15 00:10:09 +04:00
|
|
|
|
|
|
|
|
|
|
2024-10-22 16:46:39 +04:00
|
|
|
|
# эндпоинт инициализации бд из csv файлов
|
2024-10-17 13:51:33 +04:00
|
|
|
|
@app.get('/init_db_data')
|
2024-10-25 02:02:31 +04:00
|
|
|
|
async def init_db_data(background_tasks: BackgroundTasks):
|
2024-10-15 00:10:09 +04:00
|
|
|
|
try:
|
2024-10-25 02:02:31 +04:00
|
|
|
|
background_tasks.add_task(csv_to_db)
|
|
|
|
|
return {"status": "success", "message": "Инициализация БД запущена в фоне"}
|
2024-10-15 00:10:09 +04:00
|
|
|
|
except Exception as e:
|
2024-10-25 02:02:31 +04:00
|
|
|
|
print(str(e.with_traceback()))
|
2024-10-15 00:10:09 +04:00
|
|
|
|
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
|