Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"jsdom": "^22.0.0",
"json2csv": "^5.0.6",
"jsonwebtoken": "^9.0.0",
"lodash": "^4.17.23",
"mime-types": "^2.1.35",
"mixin-deep": "^2.0.1",
"mjml": "^4.18.0",
Expand Down Expand Up @@ -145,4 +144,4 @@
"lint:all": "eslint --no-error-on-unmatched-pattern --max-warnings=0 --ext .ts server",
"emails:build": "ts-node server/mails/build.ts"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export default async (
title: 'Mise à jour',
properties: [
properties.updatedAt,
properties.populationUpdatedAt,
],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ export default (closingSolutions: ClosingSolution[]) => {
width: COLUMN_WIDTHS.SMALL,
sum: true,
},
populationUpdatedAt: {
title: 'Habitants mis à jour le',
data: ({ populationUpdatedAt }: ShantytownWithFinancedAction) => (populationUpdatedAt ? new Date(populationUpdatedAt * 1000) : null),
width: COLUMN_WIDTHS.SMALL,
},
caravans: {
title: 'Nombre de caravanes',
data: ({ caravans }: ShantytownWithFinancedAction) => caravans,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export type TownInput = {
population_minors_12_16?: number,
population_minors_16_18?: number,
minors_in_school?: number,
population_updated_at?: Date,
caravans?: number,
huts?: number,
tents?: number,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@
import moment from 'moment';
import { Paragraph, TextRun, AlignmentType } from 'docx';
import dateUtils from '#server/utils/date';

const getUpdateTag = (monthsSinceUpdate: number | null): 'red' | 'orange' | 'green' => {
if (monthsSinceUpdate === null || monthsSinceUpdate >= 6) {
return 'red';
}

if (monthsSinceUpdate >= 3) {
return 'orange';
}

return 'green';
};

export default (shantytown) => {
const now = new Date();
const updatedAtDate = shantytown.updatedAt ? new Date(shantytown.updatedAt * 1000) : now;
const populationUpdatedAtDate = shantytown.populationUpdatedAt
? new Date(shantytown.populationUpdatedAt * 1000)
: null;

Comment thread
superfeedboy marked this conversation as resolved.
const currentDate = moment().utc().locale('fr');
const lastUpdate = moment(new Date(shantytown.updatedAt * 1000)).format('DD/MM/YYYY');
const lastUpdate = moment(updatedAtDate).format('DD/MM/YYYY');
const populationLastUpdate = populationUpdatedAtDate
? `mis à jour le ${moment(populationUpdatedAtDate).format('DD/MM/YYYY')}`
: 'non renseigné';
const monthsSincePopulationUpdate = populationUpdatedAtDate
? dateUtils.getMonthDiffBetween(populationUpdatedAtDate, now)
: null;
const monthsSinceLastUpdate = dateUtils.getMonthDiffBetween(updatedAtDate, now);

const colors = {
red: 'AB0000',
orange: 'ffb347',
green: '008800',
};

const populationUpdateTag = getUpdateTag(monthsSincePopulationUpdate);
const lastUpdateTag = getUpdateTag(monthsSinceLastUpdate);

return [
new Paragraph({
Expand Down Expand Up @@ -67,15 +102,23 @@ export default (shantytown) => {
break: 1,
size: 20,
font: 'Arial',
color: 'ff6f4c',
color: colors.red,
}),
new TextRun({
text: `Nombre d'habitants ${populationLastUpdate}`,
bold: false,
break: 1,
size: 20,
font: 'Arial',
color: colors[populationUpdateTag],
}),
new TextRun({
text: `Dernière mise à jour des données le ${lastUpdate}`,
bold: false,
break: 1,
size: 20,
font: 'Arial',
color: 'ff6f4c',
color: colors[lastUpdateTag],
}),
],
}),
Expand Down
3 changes: 3 additions & 0 deletions packages/api/server/services/shantytown/exportTowns.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('services/shantytown.exportTowns()', () => {
[region],
{ exportedSitesStatus: 'open' },
date,
undefined,
);
});

Expand All @@ -72,6 +73,7 @@ describe('services/shantytown.exportTowns()', () => {
[region],
{ exportedSitesStatus: 'open' },
date,
undefined,
);
});

Expand All @@ -87,6 +89,7 @@ describe('services/shantytown.exportTowns()', () => {
allowedLocations,
{ exportedSitesStatus: 'open' },
sinon.match.instanceOf(Date),
undefined,
);
});

Expand Down
59 changes: 39 additions & 20 deletions packages/api/server/utils/excel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,12 +535,14 @@ export default {
const limit = now - SIX_MONTHS_IN_SECONDS;

// 2. Grouper par département
const stats: Record<string, { name: string; total: number; updated: number }> = shantytowns.reduce((acc, town) => {
const stats: Record<string, { name: string; total: number; updated: number, updatedPopulation: number }> = shantytowns.reduce((acc, town) => {
const depCode = town.departement?.code || 'Inconnu';
const depName = town.departement?.name || 'Inconnu';

if (!acc[depCode]) {
acc[depCode] = { name: depName, total: 0, updated: 0 };
acc[depCode] = {
name: depName, total: 0, updated: 0, updatedPopulation: 0,
};
}

acc[depCode].total += 1;
Expand All @@ -549,6 +551,11 @@ export default {
if (town.updatedAt > limit) {
acc[depCode].updated += 1;
}
// Vérification de la date de mise à jour de la population si la date de mise à jour du site est nulle ou ancienne
if (town.populationUpdatedAt && town.populationUpdatedAt > limit) {
acc[depCode].updatedPopulation += 1;
}


return acc;
}, {});
Expand All @@ -562,7 +569,10 @@ export default {
total: data.total,
updatedCount: data.updated,
updateRate: `${((data.updated / data.total) * 100).toFixed(2)}`,
}));
updatedPopulationCount: data.updatedPopulation,
populationUpdateRate: `${((data.updatedPopulation / data.total) * 100).toFixed(2)}`,
}
));
};

const results = analyzeUpdatesByDepartement();
Expand All @@ -573,6 +583,8 @@ export default {
'Nombre de sites',
'Mis à jour < 6 mois',
'Taux de MAJ (%)',
'Habitants mis à jour < 6 mois',
'Taux de MAJ des habitants (%)',
];
headerRow.font = {
color: { argb: 'FFFFFFFF' },
Expand Down Expand Up @@ -604,25 +616,32 @@ export default {
item.total,
item.updatedCount,
Number.parseFloat(item.updateRate),
item.updatedPopulationCount,
Number.parseFloat(item.populationUpdateRate),

];

const rateValue = Number.parseFloat(item.updateRate);
const rateCell = row.getCell(4); // 4ème colonne pour le taux de MAJ

// Logique de colorisation
if (rateValue < 30) {
// ROUGE : Fond clair, texte foncé
rateCell.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFFFC7CE' } }; // Fond rouge clair
rateCell.font = { color: { argb: 'FF9C0006' }, bold: true }; // Texte rouge foncé
} else if (rateValue >= 60) {
// VERT : Fond vert clair, texte vert foncé
rateCell.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFC6EFCE' } };
rateCell.font = { color: { argb: 'FF006100' }, bold: true };
} else {
// ORANGE : Fond orange clair, texte noir
rateCell.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFFFEB9C' } };
rateCell.font = { color: { argb: 'FF000000' }, bold: true };
}
[
{ value: Number.parseFloat(item.updateRate), cell: row.getCell(4) },
{ value: Number.parseFloat(item.populationUpdateRate), cell: row.getCell(6) },
].forEach((rateData) => {
const rateValue = rateData.value;
const rateCell = rateData.cell;

if (rateValue < 30) {
// ROUGE : Fond clair, texte foncé
rateCell.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFFFC7CE' } }; // Fond rouge clair
rateCell.font = { color: { argb: 'FF9C0006' }, bold: true }; // Texte rouge foncé
} else if (rateValue >= 60) {
// VERT : Fond vert clair, texte vert foncé
rateCell.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFC6EFCE' } };
rateCell.font = { color: { argb: 'FF006100' }, bold: true };
} else {
// ORANGE : Fond orange clair, texte noir
rateCell.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFFFEB9C' } };
rateCell.font = { color: { argb: 'FF000000' }, bold: true };
}
});
});
// Largeur des colonnes
sheet2.columns.forEach((_col, index) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const props = defineProps({
},
});
const { action } = toRefs(props);
console.log("Action:", action.value);

const numberOfSites = computed(() => {
return `${action.value.location_shantytowns?.length} site${
Expand Down
Loading