Заливаем готовую часть #1
7
db/db.py
7
db/db.py
@ -1,7 +0,0 @@
|
|||||||
from sqlalchemy import create_engine
|
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
|
||||||
from sqlalchemy.orm import sessionmaker
|
|
||||||
|
|
||||||
engine = create_engine('sqlite:///example.db', echo=True)
|
|
||||||
|
|
||||||
Base = declarative_base()
|
|
7
db/db_connection.py
Normal file
7
db/db_connection.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine, async_sessionmaker
|
||||||
|
|
||||||
|
# Асинхронное подключение к PostgreSQL
|
||||||
|
DATABASE_URL = 'postgresql+asyncpg://username:password@localhost:5432/database_name'
|
||||||
|
engine = create_async_engine(DATABASE_URL, echo=True)
|
||||||
|
|
||||||
|
async_session = async_sessionmaker(engine)
|
5
db/models/base.py
Normal file
5
db/models/base.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from sqlalchemy.orm import DeclarativeBase
|
||||||
|
|
||||||
|
|
||||||
|
class Base(DeclarativeBase):
|
||||||
|
pass
|
@ -1,4 +1,4 @@
|
|||||||
from db.db import Base
|
from data_base.db import Base
|
||||||
from sqlalchemy.orm import Mapped, mapped_column
|
from sqlalchemy.orm import Mapped, mapped_column
|
||||||
|
|
||||||
class ChExperimentDBExperimentData(Base):
|
class ChExperimentDBExperimentData(Base):
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
from db.db import Base
|
from base import Base
|
||||||
from sqlalchemy.orm import Mapped, mapped_column
|
from sqlalchemy.orm import Mapped, mapped_column
|
||||||
|
|
||||||
class ExperimentData(Base):
|
class ExperimentData(Base):
|
||||||
__tablename__ = 'ExperimentData'
|
__tablename__ = 'ExperimentData'
|
||||||
|
|
||||||
id: Mapped[int] = mapped_column(primary_key=True)
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||||
direction: Mapped[float]
|
direction: Mapped[float]
|
||||||
temperature: Mapped[float]
|
temperature: Mapped[float]
|
||||||
nox: Mapped[float]
|
nox: Mapped[float]
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
from db.db import Base
|
from base import Base
|
||||||
from sqlalchemy.orm import Mapped, mapped_column
|
from sqlalchemy.orm import Mapped, mapped_column
|
||||||
|
|
||||||
class ExperimentParameters(Base):
|
class ExperimentParameters(Base):
|
||||||
__tablename__ = 'ExperimentParameters'
|
__tablename__ = 'ExperimentParameters'
|
||||||
|
|
||||||
id: Mapped[int] = mapped_column(primary_key=True)
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||||
outer_blades_count: Mapped[int]
|
outer_blades_count: Mapped[int]
|
||||||
outer_blades_length: Mapped[float]
|
outer_blades_length: Mapped[float]
|
||||||
outer_blades_angle: Mapped[float]
|
outer_blades_angle: Mapped[float]
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
from db.db import Base
|
from base import Base
|
||||||
from sqlalchemy.orm import Mapped, mapped_column
|
from sqlalchemy.orm import Mapped, mapped_column
|
||||||
|
|
||||||
class LoadParameters(Base):
|
class LoadParameters(Base):
|
||||||
__tablename__ = 'LoadParameters'
|
__tablename__ = 'LoadParameters'
|
||||||
|
|
||||||
id: Mapped[int] = mapped_column(primary_key=True)
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||||
load: Mapped[int]
|
load: Mapped[int]
|
||||||
primary_air_consumption: Mapped[float]
|
primary_air_consumption: Mapped[float]
|
||||||
secondary_air_consumption: Mapped[float]
|
secondary_air_consumption: Mapped[float]
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
from db.db import Base
|
from base import Base
|
||||||
from sqlalchemy.orm import Mapped, mapped_column
|
from sqlalchemy.orm import Mapped, mapped_column
|
||||||
|
|
||||||
class RecyclingParameters(Base):
|
class RecyclingParameters(Base):
|
||||||
__tablename__ = 'RecyclingParameters'
|
__tablename__ = 'RecyclingParameters'
|
||||||
|
|
||||||
id: Mapped[int] = mapped_column(primary_key=True)
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||||
load_id: Mapped[int]
|
load_id: Mapped[int]
|
||||||
recycling_level: Mapped[int]
|
recycling_level: Mapped[int]
|
||||||
co2: Mapped[float]
|
co2: Mapped[float]
|
||||||
|
38
db/repositories/experiment_data_repos.py
Normal file
38
db/repositories/experiment_data_repos.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
from typing import Optional
|
||||||
|
from sqlalchemy import select
|
||||||
|
from db.db_connection import async_session
|
||||||
|
from db.models.experiment_data_model import ExperimentData
|
||||||
|
|
||||||
|
|
||||||
|
class ExperimentDataRepository:
|
||||||
|
@staticmethod
|
||||||
|
async def get_all() -> Optional[list[ExperimentData]]:
|
||||||
|
async with async_session() as session:
|
||||||
|
result = await session.execute(select(ExperimentData))
|
||||||
|
return result.scalar.all()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def get_by_id(id_: int) -> Optional[ExperimentData]:
|
||||||
|
async with async_session() as session:
|
||||||
|
result = await session.execute(select(ExperimentData).where(ExperimentData.id == id_))
|
||||||
|
return result.scalars().first()
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def create(direction: float,
|
||||||
|
temperature: float,
|
||||||
|
nox: float,
|
||||||
|
co2: float,
|
||||||
|
co: float,
|
||||||
|
file_id: str):
|
||||||
|
new_data = ExperimentData(
|
||||||
|
direction=direction,
|
||||||
|
temperature=temperature,
|
||||||
|
nox=nox,
|
||||||
|
co2=co2,
|
||||||
|
co=co,
|
||||||
|
file_id=file_id
|
||||||
|
)
|
||||||
|
async with async_session() as session:
|
||||||
|
session.add(new_data)
|
||||||
|
await session.commit()
|
39
db/repositories/experiment_parameters_repos.py
Normal file
39
db/repositories/experiment_parameters_repos.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
from typing import Optional
|
||||||
|
from sqlalchemy import select
|
||||||
|
from db.db_connection import async_session
|
||||||
|
from db.models.experiment_parameters_model import ExperimentParameters
|
||||||
|
|
||||||
|
|
||||||
|
class ExperimentParametersRepository:
|
||||||
|
@staticmethod
|
||||||
|
async def get_all() -> Optional[list[ExperimentParameters]]:
|
||||||
|
async with async_session() as session:
|
||||||
|
result = await session.execute(select(ExperimentParameters))
|
||||||
|
return result.scalar.all()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def get_by_id(id_: int) -> Optional[ExperimentParameters]:
|
||||||
|
async with async_session() as session:
|
||||||
|
result = await session.execute(select(ExperimentParameters).where(ExperimentParameters.id == id_))
|
||||||
|
return result.scalars().first()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def create(outer_blades_count: int,
|
||||||
|
outer_blades_length: float,
|
||||||
|
outer_blades_angle: float,
|
||||||
|
middle_blades_count: int,
|
||||||
|
load_id: int,
|
||||||
|
recycling_id: int,
|
||||||
|
experiment_hash: str):
|
||||||
|
new_data = ExperimentParameters(
|
||||||
|
outer_blades_count=outer_blades_count,
|
||||||
|
outer_blades_length=outer_blades_length,
|
||||||
|
outer_blades_angle=outer_blades_angle,
|
||||||
|
middle_blades_count=middle_blades_count,
|
||||||
|
load_id=load_id,
|
||||||
|
recycling_id=recycling_id,
|
||||||
|
experiment_hash=experiment_hash
|
||||||
|
)
|
||||||
|
async with async_session() as session:
|
||||||
|
session.add(new_data)
|
||||||
|
await session.commit()
|
33
db/repositories/load_parameters_repos.py
Normal file
33
db/repositories/load_parameters_repos.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
from typing import Optional
|
||||||
|
from sqlalchemy import select
|
||||||
|
from db.db_connection import async_session
|
||||||
|
from db.models.load_parameters_model import LoadParameters
|
||||||
|
|
||||||
|
|
||||||
|
class LoadParametersRepository:
|
||||||
|
@staticmethod
|
||||||
|
async def get_all() -> Optional[list[LoadParameters]]:
|
||||||
|
async with async_session() as session:
|
||||||
|
result = await session.execute(select(LoadParameters))
|
||||||
|
return result.scalar.all()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def get_by_id(id_: int) -> Optional[LoadParameters]:
|
||||||
|
async with async_session() as session:
|
||||||
|
result = await session.execute(select(LoadParameters).where(LoadParameters.id == id_))
|
||||||
|
return result.scalars().first()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def create(load: int,
|
||||||
|
primary_air_consumption: float,
|
||||||
|
secondary_air_consumption: float,
|
||||||
|
gas_inlet_consumption: float):
|
||||||
|
new_data = LoadParameters(
|
||||||
|
load=load,
|
||||||
|
primary_air_consumption=primary_air_consumption,
|
||||||
|
secondary_air_consumption=secondary_air_consumption,
|
||||||
|
gas_inlet_consumption=gas_inlet_consumption
|
||||||
|
)
|
||||||
|
async with async_session() as session:
|
||||||
|
session.add(new_data)
|
||||||
|
await session.commit()
|
37
db/repositories/recycling_parameters_repos.py
Normal file
37
db/repositories/recycling_parameters_repos.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
from typing import Optional
|
||||||
|
from sqlalchemy import select
|
||||||
|
from db.db_connection import async_session
|
||||||
|
from db.models.recycling_parameters_model import RecyclingParameters
|
||||||
|
|
||||||
|
|
||||||
|
class RecyclingParametersRepository:
|
||||||
|
@staticmethod
|
||||||
|
async def get_all() -> Optional[list[RecyclingParameters]]:
|
||||||
|
async with async_session() as session:
|
||||||
|
result = await session.execute(select(RecyclingParameters))
|
||||||
|
return result.scalar.all()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def get_by_id(id_: int) -> Optional[RecyclingParameters]:
|
||||||
|
async with async_session() as session:
|
||||||
|
result = await session.execute(select(RecyclingParameters).where(RecyclingParameters.id == id_))
|
||||||
|
return result.scalars().first()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def create(load_id: int,
|
||||||
|
recycling_level: int,
|
||||||
|
co2: float,
|
||||||
|
n2: float,
|
||||||
|
h2o: float,
|
||||||
|
o2: float):
|
||||||
|
new_data = RecyclingParameters(
|
||||||
|
load_id=load_id,
|
||||||
|
recycling_level=recycling_level,
|
||||||
|
co2=co2,
|
||||||
|
n2=n2,
|
||||||
|
h2o=h2o,
|
||||||
|
o2=o2
|
||||||
|
)
|
||||||
|
async with async_session() as session:
|
||||||
|
session.add(new_data)
|
||||||
|
await session.commit()
|
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
Loading…
Reference in New Issue
Block a user