Merge branch 'dev_and'
# Conflicts: # db/repositories/experiment_parameters_repos.py # requirements.txt
This commit is contained in:
commit
5f4dcf84f6
404603
db/files/experiment_data.csv
404603
db/files/experiment_data.csv
File diff suppressed because it is too large
Load Diff
@ -37,9 +37,11 @@ def generate_experiment_hash(data: dict) -> str:
|
|||||||
async def save_experiment_to_db(df: pd.DataFrame):
|
async def save_experiment_to_db(df: pd.DataFrame):
|
||||||
for _, row in df.iterrows():
|
for _, row in df.iterrows():
|
||||||
try:
|
try:
|
||||||
|
# Преобразуем load и recycling_level в соответствующие id
|
||||||
load = int(row['load'])
|
load = int(row['load'])
|
||||||
recycling = int(row['recycling_level'])
|
recycling = int(row['recycling_level'])
|
||||||
|
|
||||||
|
# Генерация хеша для experiment_hash
|
||||||
experiment_hash = generate_experiment_hash(row)
|
experiment_hash = generate_experiment_hash(row)
|
||||||
|
|
||||||
exp = await create(
|
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_length=float(row['outer_blades_length']),
|
||||||
outer_blades_angle=float(row['outer_blades_angle']),
|
outer_blades_angle=float(row['outer_blades_angle']),
|
||||||
middle_blades_count=int(row['middle_blades_count']),
|
middle_blades_count=int(row['middle_blades_count']),
|
||||||
load_id= None,
|
load_id=None,
|
||||||
recycling_id=None,
|
recycling_id=None,
|
||||||
experiment_hash=experiment_hash,
|
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)
|
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}")
|
print(f"Ошибка при сохранении данных: {e}")
|
||||||
raise HTTPException(status_code=500, detail=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:
|
async def process_and_save_experiment_data(id: int, load: float, recycling_level: float) -> dict:
|
||||||
try:
|
try:
|
||||||
experiment = await get_by_id(ExperimentParameters, id)
|
experiment = await get_by_id(ExperimentParameters, id)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
db:
|
db:
|
||||||
image: postgres
|
image: postgres
|
||||||
@ -8,7 +7,7 @@ services:
|
|||||||
POSTGRES_USER: ${POSTGRES_USER}
|
POSTGRES_USER: ${POSTGRES_USER}
|
||||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||||
ports:
|
ports:
|
||||||
- "5432:5432"
|
- ${DB_PORT}
|
||||||
volumes:
|
volumes:
|
||||||
- postgres_data:/var/lib/postgresql/data
|
- postgres_data:/var/lib/postgresql/data
|
||||||
|
|
||||||
|
15
main.py
15
main.py
@ -3,6 +3,7 @@ from traceback import format_exc
|
|||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from fastapi import FastAPI, HTTPException, BackgroundTasks
|
from fastapi import FastAPI, HTTPException, BackgroundTasks
|
||||||
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from pyDOE3 import pbdesign, lhs
|
from pyDOE3 import pbdesign, lhs
|
||||||
|
|
||||||
from db.csv_to_db import csv_to_db
|
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 = FastAPI()
|
||||||
|
|
||||||
|
app.add_middleware(
|
||||||
|
CORSMiddleware,
|
||||||
|
allow_origins=['*'],
|
||||||
|
allow_credentials=True,
|
||||||
|
allow_methods=["*"],
|
||||||
|
allow_headers=["*"],
|
||||||
|
)
|
||||||
|
|
||||||
app.include_router(ch_experimentdb_experiment_data_router.router,
|
app.include_router(ch_experimentdb_experiment_data_router.router,
|
||||||
prefix="/ch_experimentdb_experiment_data",
|
prefix="/ch_experimentdb_experiment_data",
|
||||||
tags=["ch_experimentdb_experiment_data"])
|
tags=["ch_experimentdb_experiment_data"])
|
||||||
@ -118,6 +127,7 @@ async def init_data_plot():
|
|||||||
@app.post("/pyDOE3_screening_design")
|
@app.post("/pyDOE3_screening_design")
|
||||||
async def generate_screening_design(request: ExperimentParametersPyDOE3) -> List[Dict[str, float]]:
|
async def generate_screening_design(request: ExperimentParametersPyDOE3) -> List[Dict[str, float]]:
|
||||||
param_ranges = request.param_ranges
|
param_ranges = request.param_ranges
|
||||||
|
category = request.category
|
||||||
|
|
||||||
# Создаем screening design и масштабируем его
|
# Создаем screening design и масштабируем его
|
||||||
num_factors = len(param_ranges)
|
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())
|
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")
|
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
|
param_ranges = request.param_ranges
|
||||||
count_exp = request.count_exp
|
count_exp = request.count_exp
|
||||||
round_rules = request.round_rules
|
round_rules = request.round_rules
|
||||||
|
category = request.category
|
||||||
|
|
||||||
# Создаем lhs design и масштабируем его
|
# Создаем lhs design и масштабируем его
|
||||||
num_factors = len(param_ranges)
|
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())
|
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")
|
return df_lhs.to_dict(orient="records")
|
@ -28,7 +28,8 @@ async def create_experiment_parameters(body: ExperimentParametersBody):
|
|||||||
middle_blades_count=body.middle_blades_count,
|
middle_blades_count=body.middle_blades_count,
|
||||||
load_id=body.load_id,
|
load_id=body.load_id,
|
||||||
recycling_id=body.recycling_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> успешно добавлена"}
|
return {"message": "Новая запись <ExperimentParameters> успешно добавлена"}
|
||||||
|
@ -4,10 +4,14 @@ from typing import Optional, Dict, Tuple, List
|
|||||||
from psycopg.types import enum
|
from psycopg.types import enum
|
||||||
from pydantic import BaseModel, ConfigDict
|
from pydantic import BaseModel, ConfigDict
|
||||||
|
|
||||||
|
|
||||||
class ExperimentParametersPyDOE3(BaseModel):
|
class ExperimentParametersPyDOE3(BaseModel):
|
||||||
param_ranges: Dict[str, Tuple[float, float]]
|
param_ranges: Dict[str, Tuple[float, float]]
|
||||||
|
category: int
|
||||||
count_exp: int
|
count_exp: int
|
||||||
round_rules: List[int]
|
round_rules: List[int]
|
||||||
|
category: int
|
||||||
|
|
||||||
|
|
||||||
class ExperimentParameters(BaseModel):
|
class ExperimentParameters(BaseModel):
|
||||||
outer_blades_count: str
|
outer_blades_count: str
|
||||||
@ -59,6 +63,7 @@ class ExperimentParametersBody(BaseModel):
|
|||||||
load_id: Optional[int]
|
load_id: Optional[int]
|
||||||
recycling_id: Optional[int]
|
recycling_id: Optional[int]
|
||||||
experiment_hash: str
|
experiment_hash: str
|
||||||
|
experiment_category_id: int
|
||||||
|
|
||||||
|
|
||||||
class LoadParametersBody(BaseModel):
|
class LoadParametersBody(BaseModel):
|
||||||
|
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
Loading…
Reference in New Issue
Block a user