PIbd-42_SSPR/main.py

59 lines
2.5 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.

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, experiment_category_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_category_router.router,
prefix="/experiment_category",
tags=["experiment_category"])
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)}")