statistiques/src/data/checkDataConsistency.ts

64 lines
1.7 KiB
TypeScript
Raw Normal View History

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!.getTime() > family.Sortie!.getTime()) {
2024-06-02 14:34:11 +02:00
consistencyIssues.push({
familyId: family.Titre,
2024-06-02 14:34:11 +02:00
issueType: "startResistsant > endResistant ",
});
}
} else {
if (family.Integration !== null) {
2024-06-02 14:34:11 +02:00
consistencyIssues.push({
familyId: family.Titre,
issueType: family.Statut + " with startResistant",
2024-06-02 14:34:11 +02:00
});
}
if (family.Sortie !== null) {
2024-06-02 14:34:11 +02:00
consistencyIssues.push({
familyId: family.Titre,
issueType: family.Statut + " with endResistant",
2024-06-02 14:34:11 +02:00
});
}
}
return consistencyIssues;
}