mirror of
https://framagit.org/enfance-libre/statistiques
synced 2025-12-07 07:23:44 +00:00
fix: améliore la gestion des données manquante
This commit is contained in:
parent
998714105b
commit
456cb3279d
17 changed files with 65 additions and 28 deletions
|
|
@ -1,9 +1,13 @@
|
|||
import { StatsValue } from "../statistiques/v2/desc/StatsDesc";
|
||||
import { ValueFormatOptions } from "./ValueFormatOptions";
|
||||
|
||||
export function formatValue(
|
||||
value: number,
|
||||
value: StatsValue,
|
||||
valueFormatOptions: ValueFormatOptions
|
||||
) {
|
||||
if (value === undefined) {
|
||||
return "Pas de données";
|
||||
}
|
||||
const valueStr = value.toLocaleString("fr-FR", {
|
||||
useGrouping: false,
|
||||
maximumFractionDigits:
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { formatValue } from "../../../format/formatValue";
|
||||
import { ValueFormatOptions } from "../../../format/ValueFormatOptions";
|
||||
import { StatsData } from "../../../statistiques/v2/desc/StatsDesc";
|
||||
import { chunk, isNumber } from "lodash";
|
||||
import { StatsData, StatsValue } from "../../../statistiques/v2/desc/StatsDesc";
|
||||
import { chunk, isObject } from "lodash";
|
||||
import { BlockObjectRequest } from "@notionhq/client/build/src/api-endpoints";
|
||||
|
||||
export function createSingleValueStatListItemBlock(
|
||||
|
|
@ -9,7 +9,7 @@ export function createSingleValueStatListItemBlock(
|
|||
formatOptions: ValueFormatOptions,
|
||||
data: StatsData
|
||||
): BlockObjectRequest {
|
||||
if (isNumber(data)) {
|
||||
if (!isObject(data)) {
|
||||
return bulletedListNumberData(label, data, formatOptions);
|
||||
} else if (data.relatedPageIds.length === 0) {
|
||||
return bulletedListNumberData(label, data.value, formatOptions);
|
||||
|
|
@ -50,7 +50,7 @@ export function createSingleValueStatListItemBlock(
|
|||
|
||||
function bulletedListNumberData(
|
||||
label: string,
|
||||
data: number,
|
||||
data: StatsValue,
|
||||
formatOptions: ValueFormatOptions
|
||||
): BlockObjectRequest {
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -65,7 +65,11 @@ export function isMultiValueStatDesc(x: StatDesc): x is MultiValueStatDesc {
|
|||
return "type" in x && x.type === "multi";
|
||||
}
|
||||
|
||||
export type StatsData = number | { value: number; relatedPageIds: string[] };
|
||||
export type StatsValue = number | undefined;
|
||||
|
||||
export type StatsData =
|
||||
| StatsValue
|
||||
| { value: StatsValue; relatedPageIds: string[] };
|
||||
|
||||
export type StatType<T extends StatDesc> = T extends StatGroupListDesc
|
||||
? Record<
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ import {
|
|||
isExResistant,
|
||||
isResistant,
|
||||
} from "../../../data/Famille";
|
||||
import { average } from "../../../utils/math/average";
|
||||
import { median } from "../../../utils/math/median";
|
||||
import { average } from "../math/average";
|
||||
import { median } from "../math/median";
|
||||
import { StatsGenerales } from "./StatsGenerales";
|
||||
import _, { countBy, uniq } from "lodash";
|
||||
import { isIntegrationEnCours } from "../../../data/StatutFamille";
|
||||
|
|
|
|||
7
src/statistiques/v2/math/average.ts
Normal file
7
src/statistiques/v2/math/average.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { StatsValue } from "../desc/StatsDesc";
|
||||
|
||||
export function average(values: number[]): StatsValue {
|
||||
if (values.length === 0) return undefined;
|
||||
|
||||
return values.reduce((a, b) => a + b) / values.length;
|
||||
}
|
||||
7
src/statistiques/v2/math/max.ts
Normal file
7
src/statistiques/v2/math/max.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { StatsValue } from "../desc/StatsDesc";
|
||||
|
||||
export function max(values: number[]): StatsValue {
|
||||
if (values.length === 0) return undefined;
|
||||
|
||||
return Math.max(...values);
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
export function median(values: number[]): number {
|
||||
if (values.length === 0) return NaN;
|
||||
import { StatsValue } from "../desc/StatsDesc";
|
||||
|
||||
export function median(values: number[]): StatsValue {
|
||||
if (values.length === 0) return undefined;
|
||||
|
||||
const sorted = [...values].sort((a, b) => a - b);
|
||||
|
||||
7
src/statistiques/v2/math/min.ts
Normal file
7
src/statistiques/v2/math/min.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { StatsValue } from "../desc/StatsDesc";
|
||||
|
||||
export function min(values: number[]): StatsValue {
|
||||
if (values.length === 0) return undefined;
|
||||
|
||||
return Math.min(...values);
|
||||
}
|
||||
8
src/statistiques/v2/math/percent.ts
Normal file
8
src/statistiques/v2/math/percent.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import { StatsValue } from "../desc/StatsDesc";
|
||||
|
||||
export function percent(value: StatsValue, total: StatsValue): StatsValue {
|
||||
if (value === undefined || total === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
return (100 * value) / total;
|
||||
}
|
||||
|
|
@ -3,6 +3,8 @@ import { Famille } from "../../../data/Famille";
|
|||
import { NamedStatsType } from "../desc/StatsDesc";
|
||||
import { statsAmendesDesc } from "./StatsPenales";
|
||||
import { isEvtProcedurePenale } from "../../../data/EvenementFamille";
|
||||
import { max } from "../math/max";
|
||||
import { min } from "../math/min";
|
||||
|
||||
export function computeStatsAmendes(
|
||||
familles: Famille[]
|
||||
|
|
@ -38,10 +40,10 @@ export function computeStatsAmendes(
|
|||
.map((a) => a.Montant);
|
||||
|
||||
const stats = {
|
||||
amendeMinAvecSursi: Math.min(...montantsAvecSursi),
|
||||
amendeMaxAvecSursi: Math.max(...montantsAvecSursi),
|
||||
amendeMinFerme: Math.min(...montantsFerme),
|
||||
amendeMaxFerme: Math.max(...montantsFerme),
|
||||
amendeMinAvecSursi: min(montantsAvecSursi),
|
||||
amendeMaxAvecSursi: max(montantsAvecSursi),
|
||||
amendeMinFerme: min(montantsFerme),
|
||||
amendeMaxFerme: max(montantsFerme),
|
||||
};
|
||||
return [evtType, stats];
|
||||
})
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import {
|
|||
} from "./computeFamilleAvecInfosProceduresPenales";
|
||||
import { computeIntervalMedGendarmerieOuProcureur } from "./intervals/computeIntervalMedGendarmerieOuProcureur";
|
||||
import { groupBy } from "lodash";
|
||||
import { percent } from "../../../utils/math/percent";
|
||||
import { percent } from "../math/percent";
|
||||
import { isEvtTypeProcedurePenaleHorsGendarmerie } from "../../../data/TypeEvenementsPenal";
|
||||
import { computeStatsAmendes } from "./computeStatsAmendes";
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ import {
|
|||
FamilleAvecInfosProceduresPenales,
|
||||
InfosProcedurePenale,
|
||||
} from "../computeFamilleAvecInfosProceduresPenales";
|
||||
import { StatsValue } from "../../desc/StatsDesc";
|
||||
|
||||
export function computeIntervalGendarmerieProcureur(
|
||||
familles: FamilleAvecInfosProceduresPenales[]
|
||||
): number {
|
||||
): StatsValue {
|
||||
return computeIntervalProcedurePenale(
|
||||
familles,
|
||||
(procPenal: InfosProcedurePenale): number | undefined => {
|
||||
|
|
|
|||
|
|
@ -5,10 +5,11 @@ import {
|
|||
} from "../computeFamilleAvecInfosProceduresPenales";
|
||||
import { computeIntervalProcedurePenale } from "./computeIntervalProcedurePenale";
|
||||
import { min } from "lodash";
|
||||
import { StatsValue } from "../../desc/StatsDesc";
|
||||
|
||||
export function computeIntervalMedGendarmerieOuProcureur(
|
||||
familles: FamilleAvecInfoProceduresPenales[]
|
||||
): number {
|
||||
): StatsValue {
|
||||
return computeIntervalProcedurePenale(
|
||||
familles,
|
||||
(procPenal: InfosProcedurePenale): number | undefined => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { Famille } from "../../../../data/Famille";
|
||||
import { average } from "../../../../utils/math/average";
|
||||
import { StatsValue } from "../../desc/StatsDesc";
|
||||
import { average } from "../../math/average";
|
||||
import {
|
||||
FamilleAvecInfosProceduresPenales as FamilleAvecInfoProceduresPenales,
|
||||
InfosProcedurePenale,
|
||||
|
|
@ -13,7 +14,7 @@ export function computeIntervalProcedurePenale(
|
|||
famille: Famille
|
||||
) => number | undefined,
|
||||
intervalName: string
|
||||
): number {
|
||||
): StatsValue {
|
||||
const intervals: number[] = famillesAvecInfoProceduresPenales.flatMap((f) => {
|
||||
return f.proceduresPenales
|
||||
.map((pp) => {
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ import {
|
|||
FamilleAvecInfosProceduresPenales,
|
||||
InfosProcedurePenale,
|
||||
} from "../computeFamilleAvecInfosProceduresPenales";
|
||||
import { StatsValue } from "../../desc/StatsDesc";
|
||||
|
||||
export function computeIntervalProcureurTribunalCorrectionnel(
|
||||
familles: FamilleAvecInfosProceduresPenales[]
|
||||
): number {
|
||||
): StatsValue {
|
||||
return computeIntervalProcedurePenale(
|
||||
familles,
|
||||
(procPenal: InfosProcedurePenale): number | undefined => {
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
export function average(values: number[]): number {
|
||||
if (values.length === 0) return NaN;
|
||||
|
||||
return values.reduce((a, b) => a + b) / values.length;
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
export function percent(value: number, total: number): number {
|
||||
return (100 * value) / total;
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue