Initial commit: SejeteralO water tarification platform
Full-stack app for participatory water pricing using Bezier curves. - Backend: FastAPI + SQLAlchemy + SQLite with JWT auth - Frontend: Nuxt 4 + TypeScript with interactive SVG editor - Math engine: cubic Bezier tarification with Cardano solver - Admin: commune management, household import, vote monitoring, CMS - Citizen: interactive curve editor, vote submission - Docker-compose deployment ready Includes fixes for: - Impact table snake_case/camelCase property mismatch - CMS content backend API + frontend editor (was stub) - Admin route protection middleware - Public content display on commune page - Vote confirmation page link fix Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
103
backend/seed.py
Normal file
103
backend/seed.py
Normal file
@@ -0,0 +1,103 @@
|
||||
"""Seed the database with Saoû data from Eau2018.xls."""
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
|
||||
import xlrd
|
||||
from sqlalchemy import select
|
||||
|
||||
from app.database import engine, async_session, init_db
|
||||
from app.models import Commune, TariffParams, Household, AdminUser
|
||||
from app.services.auth_service import hash_password
|
||||
from app.services.import_service import generate_auth_code
|
||||
|
||||
XLS_PATH = os.path.join(os.path.dirname(__file__), "..", "Eau2018.xls")
|
||||
|
||||
|
||||
async def seed():
|
||||
await init_db()
|
||||
|
||||
async with async_session() as db:
|
||||
# Check if already seeded
|
||||
result = await db.execute(select(Commune).where(Commune.slug == "saou"))
|
||||
if result.scalar_one_or_none():
|
||||
print("Saoû already seeded.")
|
||||
return
|
||||
|
||||
# Create commune
|
||||
commune = Commune(
|
||||
name="Saoû",
|
||||
slug="saou",
|
||||
description="Commune de Saoû - Tarification progressive de l'eau",
|
||||
)
|
||||
db.add(commune)
|
||||
await db.flush()
|
||||
|
||||
# Create tariff params
|
||||
params = TariffParams(
|
||||
commune_id=commune.id,
|
||||
abop=100,
|
||||
abos=100,
|
||||
recettes=75000,
|
||||
pmax=20,
|
||||
vmax=2100,
|
||||
)
|
||||
db.add(params)
|
||||
|
||||
# Create super admin (manages all communes)
|
||||
super_admin = AdminUser(
|
||||
email="superadmin@sejeteralo.fr",
|
||||
hashed_password=hash_password("superadmin"),
|
||||
full_name="Super Admin",
|
||||
role="super_admin",
|
||||
)
|
||||
db.add(super_admin)
|
||||
|
||||
# Create commune admin for Saoû (manages only this commune)
|
||||
commune_admin = AdminUser(
|
||||
email="saou@sejeteralo.fr",
|
||||
hashed_password=hash_password("saou2024"),
|
||||
full_name="Admin Saoû",
|
||||
role="commune_admin",
|
||||
)
|
||||
commune_admin.communes.append(commune)
|
||||
db.add(commune_admin)
|
||||
|
||||
# Import households from Eau2018.xls
|
||||
book = xlrd.open_workbook(XLS_PATH)
|
||||
sheet = book.sheet_by_name("CALCULS")
|
||||
nb_hab = 363
|
||||
|
||||
existing_codes = set()
|
||||
for r in range(1, nb_hab + 1):
|
||||
name = sheet.cell_value(r, 0)
|
||||
status = sheet.cell_value(r, 3)
|
||||
volume = sheet.cell_value(r, 4)
|
||||
price = sheet.cell_value(r, 33)
|
||||
|
||||
code = generate_auth_code()
|
||||
while code in existing_codes:
|
||||
code = generate_auth_code()
|
||||
existing_codes.add(code)
|
||||
|
||||
household = Household(
|
||||
commune_id=commune.id,
|
||||
identifier=str(name).strip(),
|
||||
status=str(status).strip().upper(),
|
||||
volume_m3=float(volume),
|
||||
price_paid_eur=float(price) if price else 0.0,
|
||||
auth_code=code,
|
||||
)
|
||||
db.add(household)
|
||||
|
||||
await db.commit()
|
||||
print(f"Seeded: commune 'saou', {nb_hab} households")
|
||||
print(f" Super admin: superadmin@sejeteralo.fr / superadmin")
|
||||
print(f" Commune admin Saoû: saou@sejeteralo.fr / saou2024")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(seed())
|
||||
Reference in New Issue
Block a user