mirror of
https://framagit.org/enfance-libre/statistiques
synced 2025-12-07 13:03:44 +00:00
feat: nbFamillesResistantesAyantAssumeDesMissionsEL, nbResistantsAssumantDesMissionsEL, nbResistantsAyantAssumeDesMissionsEL
This commit is contained in:
parent
4433ae466f
commit
980a44d551
6 changed files with 52 additions and 1 deletions
|
|
@ -3,5 +3,7 @@ import { Mission } from "./Mission";
|
||||||
export type Contact = {
|
export type Contact = {
|
||||||
notionId: string;
|
notionId: string;
|
||||||
notionIdFamille: string;
|
notionIdFamille: string;
|
||||||
|
Nom: string;
|
||||||
Missions: Mission[];
|
Missions: Mission[];
|
||||||
|
AExercéUneMission: boolean;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import {
|
||||||
import { StatutSocial } from "./StatutSocial";
|
import { StatutSocial } from "./StatutSocial";
|
||||||
import { StatutPenal } from "./StatutPenal";
|
import { StatutPenal } from "./StatutPenal";
|
||||||
import { Mission } from "./Mission";
|
import { Mission } from "./Mission";
|
||||||
|
import { Contact } from "./Contact";
|
||||||
|
|
||||||
export type Famille = Readonly<{
|
export type Famille = Readonly<{
|
||||||
notionId: string;
|
notionId: string;
|
||||||
|
|
@ -36,6 +37,7 @@ export type Famille = Readonly<{
|
||||||
|
|
||||||
DerniereModification: Date;
|
DerniereModification: Date;
|
||||||
Missions: Mission[];
|
Missions: Mission[];
|
||||||
|
Contacts: Contact[];
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export function periodOfResistance(
|
export function periodOfResistance(
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ import { StatutSocial } from "../../data/StatutSocial";
|
||||||
import { Contact } from "../../data/Contact";
|
import { Contact } from "../../data/Contact";
|
||||||
import { Mission } from "../../data/Mission";
|
import { Mission } from "../../data/Mission";
|
||||||
import { relationPropertyToPageIds } from "../utils/properties/relationPropertyToPageIds";
|
import { relationPropertyToPageIds } from "../utils/properties/relationPropertyToPageIds";
|
||||||
|
import { checkboxPropertyToBoolean } from "../utils/properties/checkboxPropertyToBoolean";
|
||||||
|
|
||||||
type Departement = {
|
type Departement = {
|
||||||
notionId: string;
|
notionId: string;
|
||||||
|
|
@ -106,8 +107,12 @@ export async function fetchFamiliesWithEventsFromNotion(
|
||||||
|
|
||||||
const contacts: Contact[] = contactPages.map((page) => ({
|
const contacts: Contact[] = contactPages.map((page) => ({
|
||||||
notionId: page.id,
|
notionId: page.id,
|
||||||
name: titlePropertyToText(page.properties, "Nom"),
|
|
||||||
notionIdFamille: relationPropertyToPageId(page.properties, "Famille")!,
|
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)),
|
Missions: missions.filter((m) => m.ContactsNotionIds.includes(page.id)),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
@ -183,6 +188,7 @@ function buildFamily(
|
||||||
Missions: contacts
|
Missions: contacts
|
||||||
.filter((c) => c.notionIdFamille === page.id)
|
.filter((c) => c.notionIdFamille === page.id)
|
||||||
.flatMap((c) => c.Missions),
|
.flatMap((c) => c.Missions),
|
||||||
|
Contacts: contacts.filter((c) => c.notionIdFamille === page.id),
|
||||||
};
|
};
|
||||||
return family;
|
return family;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
15
src/notion/utils/properties/checkboxPropertyToBoolean.ts
Normal file
15
src/notion/utils/properties/checkboxPropertyToBoolean.ts
Normal 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;
|
||||||
|
}
|
||||||
|
|
@ -44,6 +44,15 @@ export const statsGeneralesDesc = {
|
||||||
nbFamillesResistantesAssumantDesMissionsEL: {
|
nbFamillesResistantesAssumantDesMissionsEL: {
|
||||||
label: "Nb familles résistantes assumant des missions EL",
|
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;
|
} as const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,18 @@ export function computeStatsGenerales(familles: Famille[]): StatsGenerales {
|
||||||
const famillesResistantesAssumantDesMissionsEL = famillesResistantes.filter(
|
const famillesResistantesAssumantDesMissionsEL = famillesResistantes.filter(
|
||||||
(f) => f.Missions.length > 0
|
(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 = {
|
const statsGenerales: StatsGenerales = {
|
||||||
nbFamillesResistantesActuelles:
|
nbFamillesResistantesActuelles:
|
||||||
nbFamillesAvecPagesLiees(famillesResistantes),
|
nbFamillesAvecPagesLiees(famillesResistantes),
|
||||||
|
|
@ -55,6 +67,11 @@ export function computeStatsGenerales(familles: Famille[]): StatsGenerales {
|
||||||
nbFicheFamillesParStatut: sortByKey(countBy(familles, (f) => f.Statut)),
|
nbFicheFamillesParStatut: sortByKey(countBy(familles, (f) => f.Statut)),
|
||||||
nbFamillesResistantesAssumantDesMissionsEL:
|
nbFamillesResistantesAssumantDesMissionsEL:
|
||||||
famillesResistantesAssumantDesMissionsEL.length,
|
famillesResistantesAssumantDesMissionsEL.length,
|
||||||
|
nbFamillesResistantesAyantAssumeDesMissionsEL:
|
||||||
|
famillesResistantesAyantAssumeDesMissionsEL.length,
|
||||||
|
nbResistantsAssumantDesMissionsEL: resistantesAssumantDesMissionsEL.length,
|
||||||
|
nbResistantsAyantAssumeDesMissionsEL:
|
||||||
|
resistantesAyantAssumeDesMissionsEL.length,
|
||||||
};
|
};
|
||||||
return statsGenerales;
|
return statsGenerales;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue