You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
orquestrador/app/db/mock_seed.py

97 lines
2.7 KiB
Python

import random
from datetime import datetime
from app.core.settings import settings
from app.db.mock_database import SessionMockLocal
from app.db.mock_models import Customer, Order, Vehicle
VEHICLE_MODELS = [
"Toyota Corolla",
"Honda Civic",
"Chevrolet Onix",
"Hyundai HB20",
"Volkswagen T-Cross",
"Jeep Compass",
"Fiat Argo",
"Nissan Kicks",
"Renault Duster",
"Ford Ranger",
]
CATEGORIES = ["hatch", "sedan", "suv", "pickup"]
NAMES = [
"Ana Souza",
"Bruno Lima",
"Carla Mendes",
"Diego Santos",
"Eduarda Alves",
"Felipe Rocha",
"Gabriela Costa",
"Henrique Martins",
"Isabela Ferreira",
"Joao Ribeiro",
]
def _cpf_from_index(index: int) -> str:
return str(10_000_000_000 + index).zfill(11)
def seed_mock_data() -> None:
if not settings.mock_seed_enabled:
return
rng = random.Random(42)
db = SessionMockLocal()
try:
if db.query(Vehicle).count() == 0:
vehicles = []
for idx in range(60):
model = VEHICLE_MODELS[idx % len(VEHICLE_MODELS)]
category = CATEGORIES[idx % len(CATEGORIES)]
base_price = 55_000 + (idx * 1_700)
noise = rng.randint(-7_000, 9_000)
vehicles.append(
Vehicle(
modelo=f"{model} {2020 + (idx % 6)}",
categoria=category,
preco=float(max(35_000, base_price + noise)),
)
)
db.add_all(vehicles)
db.commit()
if db.query(Customer).count() == 0:
customers = []
for idx in range(120):
entropy = (idx * 9973) % 10_000
customers.append(
Customer(
cpf=_cpf_from_index(idx),
nome=f"{NAMES[idx % len(NAMES)]} {idx + 1}",
score=300 + (entropy % 550),
limite_credito=float(30_000 + (entropy * 12)),
possui_restricao=(idx % 11 == 0),
)
)
db.add_all(customers)
db.commit()
if db.query(Order).count() == 0:
orders = []
for idx in range(40):
created = datetime(2026, 1, 1, 8, 0, 0)
orders.append(
Order(
numero_pedido=f"PED-{2026}{idx + 1:05d}",
cpf=_cpf_from_index(idx),
status="Ativo",
created_at=created,
)
)
db.add_all(orders)
db.commit()
finally:
db.close()