PIbd-42_SSPR/main.py

32 lines
1.1 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
from pydantic import BaseModel
from new_experiment_planner import run_experiment # Импортируем функцию из твоего скрипта
app = FastAPI()
# Модель данных для передачи параметров
class ExperimentParameters(BaseModel):
outer_blades_count: str
outer_blades_length: str
outer_blades_angle: str
middle_blades_count: str
load: str
recycling: str
# Эндпоинт для запуска эксперимента
@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)}")