statistiques/src/data/checkDataConsistency.ts

70 lines
2 KiB
TypeScript
Raw Normal View History

2024-06-05 21:35:55 +02:00
import { isValidEvenementFamille } from "./EvenementFamille";
import { Famille } from "./Famille";
2024-06-02 14:34:11 +02:00
export function checkDataConsistency(families: Famille[]): ConsistencyIssue[] {
2024-06-02 14:34:11 +02:00
return families.flatMap((family) => {
return checkFamilyDataConsistency(family);
});
}
export type ConsistencyIssue = {
issueType: string;
familyId: string;
canIgnore?: boolean;
2024-06-02 14:34:11 +02:00
};
function checkFamilyDataConsistency(family: Famille) {
2024-06-02 14:34:11 +02:00
const consistencyIssues: ConsistencyIssue[] = [];
if (family.Statut === "Résistant.e") {
if (family.Integration === null) {
2024-06-02 14:34:11 +02:00
consistencyIssues.push({
familyId: family.Titre,
2024-06-02 14:34:11 +02:00
issueType: "Résistant.e without startResistant",
});
}
if (family.Sortie !== null) {
2024-06-02 14:34:11 +02:00
consistencyIssues.push({
familyId: family.Titre,
2024-06-02 14:34:11 +02:00
issueType: "Résistant.e with endResistant!!",
});
}
} else if (family.Statut === "Ex résistant·e·s") {
if (family.Integration === null) {
2024-06-02 14:34:11 +02:00
consistencyIssues.push({
familyId: family.Titre,
2024-06-02 14:34:11 +02:00
issueType: "Ex résistant.e.s without startResistant",
});
}
if (family.Sortie === null) {
2024-06-02 14:34:11 +02:00
consistencyIssues.push({
familyId: family.Titre,
2024-06-02 14:34:11 +02:00
issueType: "Ex résistant.e.s without endResistant",
});
}
if (family.Integration! > family.Sortie!) {
2024-06-02 14:34:11 +02:00
consistencyIssues.push({
familyId: family.Titre,
2024-06-02 14:34:11 +02:00
issueType: "startResistsant > endResistant ",
});
}
}
2024-06-05 21:35:55 +02:00
consistencyIssues.push(
...family.Evenements.filter((e) => !isValidEvenementFamille(e.Type)).map(
(e) => ({
familyId: family.Titre,
issueType: `Event ${e.notionId} has unknown event Type "${e.Type}"`,
})
)
);
consistencyIssues.push(
...family.Evenements.filter((e) => e.Type !== null && e.Date === null).map(
(e) => ({
familyId: family.Titre,
issueType: `Event ${e.notionId} with non null Type "${e.Type}" but null Date`,
canIgnore: true,
2024-06-05 21:35:55 +02:00
})
)
);
2024-06-02 14:34:11 +02:00
return consistencyIssues;
}