feat: nbFamillesResistantesAyantAssumeDesMissionsEL, nbResistantsAssumantDesMissionsEL, nbResistantsAyantAssumeDesMissionsEL

This commit is contained in:
Sébastien Arod 2025-05-30 00:06:05 +02:00
parent 4433ae466f
commit 980a44d551
6 changed files with 52 additions and 1 deletions

View file

@ -3,5 +3,7 @@ import { Mission } from "./Mission";
export type Contact = {
notionId: string;
notionIdFamille: string;
Nom: string;
Missions: Mission[];
AExercéUneMission: boolean;
};

View file

@ -12,6 +12,7 @@ import {
import { StatutSocial } from "./StatutSocial";
import { StatutPenal } from "./StatutPenal";
import { Mission } from "./Mission";
import { Contact } from "./Contact";
export type Famille = Readonly<{
notionId: string;
@ -36,6 +37,7 @@ export type Famille = Readonly<{
DerniereModification: Date;
Missions: Mission[];
Contacts: Contact[];
}>;
export function periodOfResistance(

View file

@ -30,6 +30,7 @@ import { StatutSocial } from "../../data/StatutSocial";
import { Contact } from "../../data/Contact";
import { Mission } from "../../data/Mission";
import { relationPropertyToPageIds } from "../utils/properties/relationPropertyToPageIds";
import { checkboxPropertyToBoolean } from "../utils/properties/checkboxPropertyToBoolean";
type Departement = {
notionId: string;
@ -106,8 +107,12 @@ export async function fetchFamiliesWithEventsFromNotion(
const contacts: Contact[] = contactPages.map((page) => ({
notionId: page.id,
name: titlePropertyToText(page.properties, "Nom"),
notionIdFamille: relationPropertyToPageId(page.properties, "Famille")!,
Nom: titlePropertyToText(page.properties, "Nom"),
AExercéUneMission: checkboxPropertyToBoolean(
page.properties,
"A exercé une mission"
),
Missions: missions.filter((m) => m.ContactsNotionIds.includes(page.id)),
}));
@ -183,6 +188,7 @@ function buildFamily(
Missions: contacts
.filter((c) => c.notionIdFamille === page.id)
.flatMap((c) => c.Missions),
Contacts: contacts.filter((c) => c.notionIdFamille === page.id),
};
return family;
}

View file

@ -0,0 +1,15 @@
import { PageProperties } from "../types/PageProperties";
import { extractPagePropertyValue } from "./extractPagePropertyValue";
export function checkboxPropertyToBoolean(
pageProperties: PageProperties,
propName: string
): boolean {
const propValue = extractPagePropertyValue(pageProperties, propName);
if (propValue.type !== "checkbox") {
throw new Error(
`Property ${propName} was expected to have type "checkbox" but got "${propValue.type}".`
);
}
return propValue.checkbox;
}

View file

@ -44,6 +44,15 @@ export const statsGeneralesDesc = {
nbFamillesResistantesAssumantDesMissionsEL: {
label: "Nb familles résistantes assumant des missions EL",
},
nbFamillesResistantesAyantAssumeDesMissionsEL: {
label: "Nb familles résistantes ayant assumé des missions EL",
},
nbResistantsAssumantDesMissionsEL: {
label: "Nb résistant.e.s assumant des missions EL",
},
nbResistantsAyantAssumeDesMissionsEL: {
label: "Nb résistant.e.s ayant assumé des missions EL",
},
},
} as const;

View file

@ -28,6 +28,18 @@ export function computeStatsGenerales(familles: Famille[]): StatsGenerales {
const famillesResistantesAssumantDesMissionsEL = famillesResistantes.filter(
(f) => f.Missions.length > 0
);
const famillesResistantesAyantAssumeDesMissionsEL =
famillesResistantes.filter(
(f) =>
f.Missions.length === 0 &&
f.Contacts.filter((c) => c.AExercéUneMission).length > 0
);
const resistantesAssumantDesMissionsEL = famillesResistantes
.flatMap((f) => f.Contacts)
.filter((c) => c.Missions.length > 0);
const resistantesAyantAssumeDesMissionsEL = famillesResistantes
.flatMap((f) => f.Contacts)
.filter((c) => c.Missions.length === 0 && c.AExercéUneMission === true);
const statsGenerales: StatsGenerales = {
nbFamillesResistantesActuelles:
nbFamillesAvecPagesLiees(famillesResistantes),
@ -55,6 +67,11 @@ export function computeStatsGenerales(familles: Famille[]): StatsGenerales {
nbFicheFamillesParStatut: sortByKey(countBy(familles, (f) => f.Statut)),
nbFamillesResistantesAssumantDesMissionsEL:
famillesResistantesAssumantDesMissionsEL.length,
nbFamillesResistantesAyantAssumeDesMissionsEL:
famillesResistantesAyantAssumeDesMissionsEL.length,
nbResistantsAssumantDesMissionsEL: resistantesAssumantDesMissionsEL.length,
nbResistantsAyantAssumeDesMissionsEL:
resistantesAyantAssumeDesMissionsEL.length,
};
return statsGenerales;
}