From f709052990b79ae60a966589b4e66a09ba0a23f3 Mon Sep 17 00:00:00 2001 From: maksim Date: Tue, 8 Oct 2024 21:21:05 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=B5=D0=BB=D0=B0=D1=8E=20=D1=81=D0=B5?= =?UTF-8?q?=D0=B9=D0=B2,=20=D1=82=D1=83=D1=82=20=D0=B7=D0=B0=D0=BF=D1=83?= =?UTF-8?q?=D1=81=D0=BA=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20FastAPI.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 10 ++++++++++ config.yaml | 2 +- docker-compose.yml | 11 +++++++++++ main.py | 31 +++++++++++++++++++++++++++++++ new_experiment_planner.py | 11 +++++++++-- requirements.txt | 4 +++- 6 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 Dockerfile create mode 100644 main.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2161134 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.9-slim + +WORKDIR /app + +COPY requirements.txt requirements.txt +RUN pip install -r requirements.txt + +COPY . . + +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"] diff --git a/config.yaml b/config.yaml index ef73fa3..b6d3f82 100644 --- a/config.yaml +++ b/config.yaml @@ -1,5 +1,5 @@ paths: - starccm: '/home/user/Siemens/19.02.009-R8/STAR-CCM+19.02.009-R8/star/bin/starccm+' + starccm: 'C:/Program Files/Siemens/19.04.007-R8/STAR-CCM+19.04.007-R8/star/bin/starccm+' chemkin: '/media/user/Projects/burner_data/chemkin' main: '/media/user/Data/experiment_data' diff --git a/docker-compose.yml b/docker-compose.yml index 28aa101..ab144a5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,6 +25,17 @@ services: volumes: - clickhouse_data:/var/lib/clickhouse + fastapi: + build: . + container_name: fastapi-app + ports: + - "8000:8000" + depends_on: + - db + - clickhouse + volumes: + - .:/app # Связываем текущую директорию с контейнером для доступа к коду + volumes: postgres_data: clickhouse_data: diff --git a/main.py b/main.py new file mode 100644 index 0000000..8a80af3 --- /dev/null +++ b/main.py @@ -0,0 +1,31 @@ +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)}") diff --git a/new_experiment_planner.py b/new_experiment_planner.py index 1bc1359..1663e66 100644 --- a/new_experiment_planner.py +++ b/new_experiment_planner.py @@ -210,6 +210,7 @@ def run_experiment(outer_blades_count, outer_blades_length, outer_blades_angle, if __name__ == "__main__": + import argparse parser = argparse.ArgumentParser(description="Запуск экспериментов с энергетической установкой ГМУ-45") parser.add_argument("outer_blades_count", type=str, help="Количество лопаток во внешнем контуре") parser.add_argument("outer_blades_length", type=str, help="Ширина лопаток во внешнем контуре") @@ -220,5 +221,11 @@ if __name__ == "__main__": args = parser.parse_args() - run_experiment(args.outer_blades_count, args.outer_blades_length, args.outer_blades_angle, args.middle_blades_count, - args.load, args.recycling) + run_experiment( + args.outer_blades_count, + args.outer_blades_length, + args.outer_blades_angle, + args.middle_blades_count, + args.load, + args.recycling + ) diff --git a/requirements.txt b/requirements.txt index 8563e28..8e195e5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,6 @@ psycopg[binary] clickhouse-driver pandas pydantic-settings -clickhouse-connect \ No newline at end of file +clickhouse-connect +fastapi +uvicorn \ No newline at end of file