From 66eb2839f8e964d3b63f4ed05ab794a0746be8fd Mon Sep 17 00:00:00 2001 From: jerem Date: Fri, 20 Dec 2024 11:27:40 +0100 Subject: [PATCH] =?UTF-8?q?graphiques=20en=20historique=20lorsqu'il=20y=20?= =?UTF-8?q?a=20des=20z=C3=A9ros=20#73?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../atlas/components/main/tabs/sectors.tsx | 6 ---- server/src/routes/tableaux/atlas/index.js | 29 ++++++++++++++++++- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/client/src/pages/atlas/components/main/tabs/sectors.tsx b/client/src/pages/atlas/components/main/tabs/sectors.tsx index 4f891153..a8118bc9 100644 --- a/client/src/pages/atlas/components/main/tabs/sectors.tsx +++ b/client/src/pages/atlas/components/main/tabs/sectors.tsx @@ -133,12 +133,6 @@ export function Sectors() { return
Loading...
; } - console.log("data", data, - "dataByYear", dataByYear, - "dataSimilar", dataSimilar, - "dataSectorsMap", dataSectorsMap, - "polygonsData", polygonsData); - const toggleView = () => { if (chartView === "basic") { setChartView("percentage"); diff --git a/server/src/routes/tableaux/atlas/index.js b/server/src/routes/tableaux/atlas/index.js index 23565322..68f6d1d4 100644 --- a/server/src/routes/tableaux/atlas/index.js +++ b/server/src/routes/tableaux/atlas/index.js @@ -781,6 +781,7 @@ router.route("/atlas/number-of-students").get((req, res) => { }); router.route("/atlas/number-of-students-by-year").get((req, res) => { + const startYear = 2001; const filters = {}; if (req.query.geo_id) { filters.geo_id = req.query.geo_id; @@ -835,7 +836,33 @@ router.route("/atlas/number-of-students-by-year").get((req, res) => { return 0; }); - res.json(dataByYear); + // ajout des années manquantes (à zéro) const startYear = "2001"; + const range = []; + for (let year = startYear; year <= dataByYear[dataByYear.length -1].annee_universitaire.substring(0,4); year++) { + range.push(year); + } + + const dataByYearFull = []; + for (let i = 0; i < range.length; i++) { + const currentYear = `${range[i]}-${(range[i] + 1).toString().slice(-2)}`; + if (!dataByYear.find((el) => el.annee_universitaire === currentYear)) { + dataByYearFull.push({ + annee_universitaire: currentYear, + effectif_total: 0, + effectif_pr: 0, + effectif_pu: 0, + effectif_masculin: 0, + effectif_feminin: 0, + effectif_dut: 0, + effectif_form_ens: 0, + effectif_ing: 0, + }); + } else { + dataByYearFull.push(dataByYear.find((el) => el.annee_universitaire === currentYear)); + } + } + + res.json(dataByYearFull); }); });