statistiques/src/data/checkDataConsistency.ts

60 lines
1.7 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;
};
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: "Unknown event Type: " + e.Type,
})
)
);
2024-06-02 14:34:11 +02:00
return consistencyIssues;
}