rend + simple à lire la page des statistiques

This commit is contained in:
Yannick Le Duc
2025-09-22 09:05:57 +02:00
parent d38c21944a
commit c840470521
3 changed files with 17 additions and 9 deletions

View File

@@ -31,6 +31,7 @@ export interface PropositionStats {
participationRate: number; participationRate: number;
voteDistribution: number; voteDistribution: number;
consensusScore: number; consensusScore: number;
averagePerTotalVoters: number;
} }
type SortOption = type SortOption =
@@ -247,25 +248,25 @@ export function StatsDisplay({
</div> </div>
<div className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4"> <div className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4">
<div className="text-center">
<p className="text-2xl font-bold text-purple-600 dark:text-purple-400">
{stat.averagePerTotalVoters}
</p>
<p className="text-xs text-slate-500 dark:text-slate-400">Moyenne / total votants</p>
</div>
<div className="text-center"> <div className="text-center">
<p className="text-2xl font-bold text-blue-600 dark:text-blue-400"> <p className="text-2xl font-bold text-blue-600 dark:text-blue-400">
{stat.voteCount} {stat.voteCount}
</p> </p>
<p className="text-xs text-slate-500 dark:text-slate-400"> <p className="text-xs text-slate-500 dark:text-slate-400">
{stat.voteCount === 1 ? 'Votant' : 'Votants'} {stat.voteCount === 1 ? 'Soutien' : 'Soutiens'}
</p> </p>
</div> </div>
<div className="text-center"> <div className="text-center">
<p className="text-2xl font-bold text-green-600 dark:text-green-400"> <p className="text-2xl font-bold text-green-600 dark:text-green-400">
{stat.averageAmount} {stat.averageAmount}
</p> </p>
<p className="text-xs text-slate-500 dark:text-slate-400">Moyenne</p> <p className="text-xs text-slate-500 dark:text-slate-400">Moyenne des soutiens</p>
</div>
<div className="text-center">
<p className="text-2xl font-bold text-purple-600 dark:text-purple-400">
{stat.totalAmount}
</p>
<p className="text-xs text-slate-500 dark:text-slate-400">Total</p>
</div> </div>
<div className="text-center"> <div className="text-center">
<p className="text-2xl font-bold text-orange-600 dark:text-orange-400"> <p className="text-2xl font-bold text-orange-600 dark:text-orange-400">

View File

@@ -31,6 +31,11 @@ export function useStatsCalculation(
// Calculer la répartition des votes (nombre de montants différents) // Calculer la répartition des votes (nombre de montants différents)
const uniqueAmounts = new Set(amounts).size; const uniqueAmounts = new Set(amounts).size;
// Calculer la moyenne par rapport au nombre total de votants
const averagePerTotalVoters = participants.length > 0
? Math.round(totalAmount / participants.length)
: 0;
return { return {
proposition, proposition,
voteCount: propositionVotes.length, voteCount: propositionVotes.length,
@@ -40,7 +45,8 @@ export function useStatsCalculation(
totalAmount, totalAmount,
participationRate: Math.round(participationRate * 100) / 100, participationRate: Math.round(participationRate * 100) / 100,
voteDistribution: uniqueAmounts, voteDistribution: uniqueAmounts,
consensusScore: Math.round(consensusScore * 100) / 100 consensusScore: Math.round(consensusScore * 100) / 100,
averagePerTotalVoters
}; };
}); });
}, [campaign, participants, propositions, votes]); }, [campaign, participants, propositions, votes]);

View File

@@ -39,6 +39,7 @@ export interface PropositionStats {
participationRate: number; participationRate: number;
voteDistribution: number; voteDistribution: number;
consensusScore: number; consensusScore: number;
averagePerTotalVoters: number;
} }
export async function generateVoteExport(data: ExportData): Promise<{ data: Uint8Array | string; format: ExportFileFormat }> { export async function generateVoteExport(data: ExportData): Promise<{ data: Uint8Array | string; format: ExportFileFormat }> {