Merge branch 'dev_and'

# Conflicts:
#	db/repositories/experiment_parameters_repos.py
#	requirements.txt
This commit is contained in:
Bazunov Andrew Igorevich 2024-12-11 13:48:57 +04:00
commit 5f4dcf84f6
7 changed files with 27 additions and 404610 deletions

File diff suppressed because it is too large Load Diff

View File

@ -37,9 +37,11 @@ def generate_experiment_hash(data: dict) -> str:
async def save_experiment_to_db(df: pd.DataFrame):
for _, row in df.iterrows():
try:
# Преобразуем load и recycling_level в соответствующие id
load = int(row['load'])
recycling = int(row['recycling_level'])
# Генерация хеша для experiment_hash
experiment_hash = generate_experiment_hash(row)
exp = await create(
@ -48,10 +50,11 @@ async def save_experiment_to_db(df: pd.DataFrame):
outer_blades_length=float(row['outer_blades_length']),
outer_blades_angle=float(row['outer_blades_angle']),
middle_blades_count=int(row['middle_blades_count']),
load_id= None,
load_id=None,
recycling_id=None,
experiment_hash=experiment_hash,
oxidizer_temp=float(row['oxidizer_temp'])
oxidizer_temp=float(row['oxidizer_temp']),
experiment_category_id=experiment_category_id
)
await process_and_save_experiment_data(exp.id, load, recycling)
@ -59,6 +62,7 @@ async def save_experiment_to_db(df: pd.DataFrame):
print(f"Ошибка при сохранении данных: {e}")
raise HTTPException(status_code=500, detail=f"Ошибка при сохранении данных: {e}")
async def process_and_save_experiment_data(id: int, load: float, recycling_level: float) -> dict:
try:
experiment = await get_by_id(ExperimentParameters, id)

View File

@ -1,4 +1,3 @@
services:
db:
image: postgres
@ -8,7 +7,7 @@ services:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
ports:
- "5432:5432"
- ${DB_PORT}
volumes:
- postgres_data:/var/lib/postgresql/data

15
main.py
View File

@ -3,6 +3,7 @@ from traceback import format_exc
import pandas as pd
from fastapi import FastAPI, HTTPException, BackgroundTasks
from fastapi.middleware.cors import CORSMiddleware
from pyDOE3 import pbdesign, lhs
from db.csv_to_db import csv_to_db
@ -20,6 +21,14 @@ from new_experiment_planner_pyDOE3 import scale_design, scale_design_lhs, round_
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=['*'],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(ch_experimentdb_experiment_data_router.router,
prefix="/ch_experimentdb_experiment_data",
tags=["ch_experimentdb_experiment_data"])
@ -118,6 +127,7 @@ async def init_data_plot():
@app.post("/pyDOE3_screening_design")
async def generate_screening_design(request: ExperimentParametersPyDOE3) -> List[Dict[str, float]]:
param_ranges = request.param_ranges
category = request.category
# Создаем screening design и масштабируем его
num_factors = len(param_ranges)
@ -128,7 +138,7 @@ async def generate_screening_design(request: ExperimentParametersPyDOE3) -> List
df_screening = pd.DataFrame(scaled_screening_design, columns=param_ranges.keys())
# Сохраняем результаты в базу данных
await save_experiment_to_db(df_screening)
await save_experiment_to_db(df_screening, category)
return df_screening.to_dict(orient="records")
@ -138,6 +148,7 @@ async def generate_lhs_design(request: ExperimentParametersPyDOE3) -> List[Dict[
param_ranges = request.param_ranges
count_exp = request.count_exp
round_rules = request.round_rules
category = request.category
# Создаем lhs design и масштабируем его
num_factors = len(param_ranges)
@ -151,6 +162,6 @@ async def generate_lhs_design(request: ExperimentParametersPyDOE3) -> List[Dict[
df_lhs = pd.DataFrame(round_scaled_lhs_samples, columns=param_ranges.keys())
# Сохраняем результаты в базу данных
await save_experiment_to_db(df_lhs)
await save_experiment_to_db(df_lhs, category)
return df_lhs.to_dict(orient="records")

View File

@ -28,7 +28,8 @@ async def create_experiment_parameters(body: ExperimentParametersBody):
middle_blades_count=body.middle_blades_count,
load_id=body.load_id,
recycling_id=body.recycling_id,
experiment_hash=body.experiment_hash
experiment_hash=body.experiment_hash,
experiment_category_id=body.experiment_category_id
)
return {"message": "Новая запись <ExperimentParameters> успешно добавлена"}

View File

@ -4,10 +4,14 @@ from typing import Optional, Dict, Tuple, List
from psycopg.types import enum
from pydantic import BaseModel, ConfigDict
class ExperimentParametersPyDOE3(BaseModel):
param_ranges: Dict[str, Tuple[float, float]]
category: int
count_exp: int
round_rules: List[int]
category: int
class ExperimentParameters(BaseModel):
outer_blades_count: str
@ -59,6 +63,7 @@ class ExperimentParametersBody(BaseModel):
load_id: Optional[int]
recycling_id: Optional[int]
experiment_hash: str
experiment_category_id: int
class LoadParametersBody(BaseModel):

Binary file not shown.