Add interactive citizen page with sidebar, display settings, and adaptive CSS
Major rework of the citizen-facing page: - Chart + sidebar layout (auth/vote/countdown in right sidebar) - DisplaySettings component (font size, chart density, color palettes) - Adaptive CSS with clamp() throughout, responsive breakpoints at 480/768/1024 - Baseline charts zoomed on first tier for small consumption detail - Marginal price chart with dual Y-axes (foyers left, €/m³ right) - Key metrics banner (5 columns: recettes, palier, prix palier, prix médian, mon prix) - Client-side p0/impacts computation, draggable median price bar - Household dots toggle, vote overlay curves - Auth returns volume_m3, vote captures submitted_at - Cleaned header nav (removed Accueil/Super Admin for public visitors) - Terminology: foyer for bills, électeur for votes - 600m³ added to impact reference volumes - Realistic seed votes (50 votes, 3 profiles) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,13 +2,16 @@ from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select, delete
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from app.database import get_db
|
||||
from app.models import Commune, TariffParams, Household, Vote, CommuneContent, AdminUser, admin_commune_table
|
||||
from app.schemas import (
|
||||
CommuneCreate, CommuneUpdate, CommuneOut,
|
||||
TariffParamsUpdate, TariffParamsOut,
|
||||
TariffParamsUpdate, TariffParamsOut, PublishCurveRequest,
|
||||
)
|
||||
from app.services.auth_service import get_current_admin, require_super_admin
|
||||
from app.engine.pricing import HouseholdData, compute_p0
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -128,3 +131,49 @@ async def update_params(
|
||||
await db.commit()
|
||||
await db.refresh(params)
|
||||
return params
|
||||
|
||||
|
||||
@router.post("/{slug}/params/publish", response_model=TariffParamsOut)
|
||||
async def publish_curve(
|
||||
slug: str,
|
||||
data: PublishCurveRequest,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
admin: AdminUser = Depends(get_current_admin),
|
||||
):
|
||||
"""Admin publishes a Bézier curve as the commune's reference."""
|
||||
result = await db.execute(
|
||||
select(TariffParams).join(Commune).where(Commune.slug == slug)
|
||||
)
|
||||
params = result.scalar_one_or_none()
|
||||
if not params:
|
||||
raise HTTPException(status_code=404, detail="Paramètres introuvables")
|
||||
|
||||
# Compute p0 for this curve
|
||||
hh_result = await db.execute(
|
||||
select(Household).join(Commune).where(Commune.slug == slug)
|
||||
)
|
||||
households_db = hh_result.scalars().all()
|
||||
households = [
|
||||
HouseholdData(volume_m3=h.volume_m3, status=h.status, price_paid_eur=h.price_paid_eur)
|
||||
for h in households_db
|
||||
]
|
||||
|
||||
p0 = compute_p0(
|
||||
households,
|
||||
recettes=params.recettes, abop=params.abop, abos=params.abos,
|
||||
vinf=data.vinf, vmax=params.vmax, pmax=params.pmax,
|
||||
a=data.a, b=data.b, c=data.c, d=data.d, e=data.e,
|
||||
)
|
||||
|
||||
params.published_vinf = data.vinf
|
||||
params.published_a = data.a
|
||||
params.published_b = data.b
|
||||
params.published_c = data.c
|
||||
params.published_d = data.d
|
||||
params.published_e = data.e
|
||||
params.published_p0 = p0
|
||||
params.published_at = datetime.utcnow()
|
||||
|
||||
await db.commit()
|
||||
await db.refresh(params)
|
||||
return params
|
||||
|
||||
Reference in New Issue
Block a user