diff --git a/app/depute/[slug]/page.tsx b/app/depute/[slug]/page.tsx index 2fb3a93..ef1d64e 100644 --- a/app/depute/[slug]/page.tsx +++ b/app/depute/[slug]/page.tsx @@ -1,5 +1,164 @@ import React from "react"; -export default function Page({ params }: { params: { slug: string } }) { - return
Activités
; +import Stack from "@mui/material/Stack"; +import Card from "@mui/material/Card"; +import CardContent from "@mui/material/CardContent"; +import CardHeader from "@mui/material/CardHeader"; + +import { prisma } from "@/prisma"; +import { Box, Typography } from "@mui/material"; + +async function getDeputeStatsUnCached(slug: string) { + try { + return await prisma.acteur.findFirst({ + where: { slug }, + select: { + uid: true, + nombreAmendements: true, + nombreInterventions: true, + nombreQuestions: true, + }, + }); + } catch (error) { + console.error(`Error fetching stats from depute ${slug}:`, error); + throw error; + } +} + +async function getBaselineStatsUnCached() { + try { + return await prisma.stats.findMany({ + select: { + type: true, + id: true, + minimum: true, + maximum: true, + q20: true, + q40: true, + q60: true, + q80: true, + }, + }); + } catch (error) { + console.error(`Error fetching stat baseline:`, error); + throw error; + } +} + +const getDeputeStats = React.cache(getDeputeStatsUnCached); +const getBaselineStats = React.cache(getBaselineStatsUnCached); + +const baselineTypeToDeputeKey: Record< + string, + "nombreAmendements" | "nombreInterventions" | "nombreQuestions" +> = { + questions: "nombreQuestions", + interventions: "nombreInterventions", + amendements: "nombreAmendements", +}; + +const baselineTypeToTitle: RecordActivités
+ {baselineStats.map(({ q20, q40, q60, q80, maximum, type }) => { + if (!baselineTypeToDeputeKey[type as string] || !deputeStats) { + return null; + } + + const value = deputeStats[baselineTypeToDeputeKey[type]]; + + const quantiles = [q20, q40, q60, q80, maximum]; + + // On equality we are kind and put then in the next one. Except for the last one because there is no next one. + const quantileIndex = quantiles.findLastIndex( + (q, index) => index === 0 || value >= q + ); + + return ( +