You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
4.3 KiB

1 year ago
"""initial
Revision ID: 3c651a0d1fe0
Revises:
Create Date: 2023-10-27 18:19:47.402501
"""
1 year ago
import random
import time
1 year ago
from datetime import datetime, timedelta
1 year ago
1 year ago
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '3c651a0d1fe0'
down_revision = None
branch_labels = None
depends_on = None
1 year ago
def generate_normal_random(mean, std_dev):
return int(random.gauss(mean, std_dev))
1 year ago
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('camera',
1 year ago
sa.Column('camera_type', sa.String(), nullable=False),
sa.Column('order_numb', sa.Integer(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('CURRENT_TIMESTAMP'),
nullable=False),
sa.Column('updated_at', sa.TIMESTAMP(), server_default=sa.text('CURRENT_TIMESTAMP'),
nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('pk_camera')),
sa.UniqueConstraint('id', name=op.f('uq_camera_id')),
sa.UniqueConstraint('order_numb', name=op.f('uq_camera_order_numb'))
)
1 year ago
op.create_table('conveer',
1 year ago
sa.Column('wood', sa.Integer(), nullable=True),
sa.Column('metal', sa.Integer(), nullable=True),
sa.Column('glass', sa.Integer(), nullable=True),
sa.Column('plastic', sa.Integer(), nullable=True),
sa.Column('camera_id', sa.Integer(), nullable=False),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('CURRENT_TIMESTAMP'),
nullable=False),
sa.Column('updated_at', sa.TIMESTAMP(), server_default=sa.text('CURRENT_TIMESTAMP'),
nullable=False),
sa.ForeignKeyConstraint(['camera_id'], ['camera.id'], name=op.f('fk_conveer_camera_id_camera')),
sa.PrimaryKeyConstraint('id', name=op.f('pk_conveer')),
sa.UniqueConstraint('id', name=op.f('uq_conveer_id'))
)
1 year ago
op.execute('''INSERT INTO camera(id,order_numb, camera_type) VALUES (1,1, 'По умолчанию')''')
1 year ago
import random
from datetime import datetime, timedelta
1 year ago
1 year ago
# Устанавливаем параметры нормального распределения
mean_metal = 10 # Среднее значение для металла
std_dev_metal = 3 # Стандартное отклонение для металла
mean_glass = 5 # Среднее значение для стекла
std_dev_glass = 2 # Стандартное отклонение для стекла
mean_plastic = 7.5 # Среднее значение для пластика
std_dev_plastic = 2.5 # Стандартное отклонение для пластика
mean_wood = 15 # Среднее значение для дерева
std_dev_wood = 5 # Стандартное отклонение для дерева
1 year ago
for _ in range(0, 10):
1 year ago
random_date = datetime.now() - timedelta(days=random.randint(1, 365))
# Генерируем случайные значения, следующие нормальному распределению
metal = generate_normal_random(mean_metal, std_dev_metal)
glass = generate_normal_random(mean_glass, std_dev_glass)
plastic = generate_normal_random(mean_plastic, std_dev_plastic)
wood = generate_normal_random(mean_wood, std_dev_wood)
# Далее вы можете выполнить ваш SQL-запрос с этими случайными значениями
1 year ago
op.execute(f'''INSERT INTO conveer (metal, glass, plastic, wood, camera_id, created_at)
1 year ago
VALUES ({metal}, {glass}, {plastic}, {wood}, 1, '{random_date}');''')
1 year ago
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('conveer')
op.drop_table('camera')
# ### end Alembic commands ###