From ab7957b6022eaa3e72b56abdf312b19d48cb8bf2 Mon Sep 17 00:00:00 2001 From: Pietro <ppc19@inf.ufpr.br> Date: Tue, 17 May 2022 12:05:55 -0300 Subject: [PATCH] [wip] start dealing with reduction of percentages --- src/libs/routes/classroomCount.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/libs/routes/classroomCount.js b/src/libs/routes/classroomCount.js index 5c77b66b..c258ba03 100644 --- a/src/libs/routes/classroomCount.js +++ b/src/libs/routes/classroomCount.js @@ -808,7 +808,8 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { let city = result[i]; let obj = { year: city.year, - name: city.name + name: city.name, + count: 1 } if(req.dims.state) { @@ -828,6 +829,16 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { currentObj = obj; } else { // Está ordenado, podemos pegar o último currentObj = reduction[reduction.length - 1]; + currentObj.count++; + } + + if (currentObj.count == 1) + currentObj.percentage_teacher_career = city.percentage_teacher_career + else { + // Incrementa valores percentuais de cada nivel de carreira no objeto atual + currentObj.percentage_teacher_career.forEach((item, ind, thisArr) => { + thisArr[ind].percentage += city.percentage_teacher_career[ind].percentage + }) } // Fazer "merge" do array locations da cidade com o da agregação @@ -974,6 +985,10 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { ++i; } for (let state of reduction){ + state.percentage_teacher_career.forEach((item, ind, thisArr) => { + thisArr[ind] /= state.count; + }) + delete state.count for (let location of state.locations){ for (let educationLevel of location.education_level){ let total = educationLevel.enrollment.integral_time_total; -- GitLab