From b6e1b80c53f40900c8e59333bcf176f7018b33f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rialland?= Date: Wed, 14 Sep 2022 18:51:41 +0200 Subject: [PATCH] Add api stats cumulation --- site/source/pages/Stats/Chart.tsx | 2 +- site/source/pages/Stats/Stats.tsx | 67 ++++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/site/source/pages/Stats/Chart.tsx b/site/source/pages/Stats/Chart.tsx index c5c10a633..cf45f4f56 100644 --- a/site/source/pages/Stats/Chart.tsx +++ b/site/source/pages/Stats/Chart.tsx @@ -30,7 +30,7 @@ export type Data> = { export type DataStacked = Data> export const isDataStacked = (data: Data): data is DataStacked => - typeof data[0].nombre !== 'number' + typeof data[0]?.nombre !== 'number' export interface VisitsChartProps { period: Period diff --git a/site/source/pages/Stats/Stats.tsx b/site/source/pages/Stats/Stats.tsx index 1a9727d2c..65bf8ef0c 100644 --- a/site/source/pages/Stats/Stats.tsx +++ b/site/source/pages/Stats/Stats.tsx @@ -24,6 +24,7 @@ import GlobalStats, { BigIndicator } from './GlobalStats' import SatisfactionChart from './SatisfactionChart' import { Page, PageChapter2, PageSatisfaction, StatsStruct } from './types' import { formatDay, formatMonth } from './utils' +import { Message } from '@/design-system' type Period = 'mois' | 'jours' type Chapter2 = PageChapter2 | 'PAM' | 'api-rest' @@ -136,7 +137,10 @@ const StatsDetail = ({ stats }: StatsDetailProps) => { return rawData.site } if (chapter2 === 'api-rest') { - return rawData.api.map(({ date, ...nombre }) => ({ date, nombre })) + return (rawData.api ?? []).map(({ date, ...nombre }) => ({ + date, + nombre, + })) } return filterByChapter2(rawData.pages as Pageish[], chapter2) @@ -186,6 +190,21 @@ const StatsDetail = ({ stats }: StatsDetailProps) => { 'PAM', ] + type ApiData = { + date: string + nombre: { evaluate: number; rules: number; rule: number } + } + const apiCumul = + chapter2 === 'api-rest' && + (slicedVisits as ApiData[]).reduce( + (acc, { nombre }) => ({ + evaluate: acc.evaluate + nombre.evaluate, + rules: acc.rules + nombre.rules, + rule: acc.rule + nombre.rule, + }), + { evaluate: 0, rules: 0, rule: 0 } + ) + return ( <>

Statistiques détaillées

@@ -222,14 +241,18 @@ const StatsDetail = ({ stats }: StatsDetailProps) => {

Visites

- + {visites.length ? ( + + ) : ( + Aucune donnée disponible. + )} {slicedVisits.length > 0 && (

@@ -248,12 +271,24 @@ const StatsDetail = ({ stats }: StatsDetailProps) => { )} - + {apiCumul ? ( + <> + + + + + ) : ( + + )} + {typeof totals !== 'number' && 'simulation_commencee' in totals && ( <> {' '} @@ -320,6 +355,8 @@ export default function Stats() { {statsAvailable ? ( <> + +

Statistiques globales

) : loading ? (