From d622ea609def66eda93a448e32f1df04007e1fcc Mon Sep 17 00:00:00 2001
From: Fernando Gbur <fgs21@inf.ufpr.br>
Date: Wed, 3 Jul 2024 14:34:55 -0400
Subject: [PATCH 01/37] [ADD] First request to create the new attendance_rate
 route

---
 src/libs/routes_v1/api.js           |   3 +
 src/libs/routes_v1/rateSchoolNew.js | 326 ++++++++++++++++++++++++++++
 2 files changed, 329 insertions(+)
 create mode 100644 src/libs/routes_v1/rateSchoolNew.js

diff --git a/src/libs/routes_v1/api.js b/src/libs/routes_v1/api.js
index 53f9e4df..8a0c5c90 100644
--- a/src/libs/routes_v1/api.js
+++ b/src/libs/routes_v1/api.js
@@ -143,6 +143,8 @@ const activity = require(`${libs}/routes_v1/activity`);
 
 const newPnad = require(`${libs}/routes_v1/newPnad`);
 
+const rateSchoolNew = require(`${libs}/routes_v1/rateSchoolNew`)
+
 const email = require(`${libs}/routes_v1/email`);
 
 api.get('/', (req, res) => {
@@ -205,6 +207,7 @@ api.use('/universityLocalOffer', universityLocalOffer);
 api.use('/message', message);
 api.use('/course_students', courseStudents);
 api.use('/new_pnad', newPnad);
+api.use('/rate_school_new', rateSchoolNew)
 
 //Publication 
 api.use('/publication', publication);
diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
new file mode 100644
index 00000000..5b680948
--- /dev/null
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -0,0 +1,326 @@
+/*
+Copyright (C) 2024 Centro de Computacao Cientifica e Software Livre
+Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
+
+This file is part of simcaq-node.
+
+simcaq-node is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+simcaq-node is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with simcaq-node.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+const express = require('express');
+
+const rateSchoolNewApp = express.Router();
+
+const libs = `${process.cwd()}/libs`;
+
+const squel = require('squel');
+
+const query = require(`${libs}/middlewares/query`).query;
+
+const response = require(`${libs}/middlewares/response`);
+
+const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
+
+const id2str = require(`${libs}/middlewares/id2str`);
+
+const config = require(`${libs}/config`); 
+
+const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware;
+
+let rqf = new ReqQueryFields();
+
+rateSchoolNewApp.use(cache('15 day'));
+
+rateSchoolNewApp.get('/years', (req, res, next) => {
+    req.sql.from('pnad_novo')
+    .field('DISTINCT pnad_novo.ano_ref', 'year')
+    next();
+}, query, response('years'));
+
+
+rqf.addField({
+    name: 'filter',
+    field: false,
+    where: true
+}).addField({
+    name: 'dims',
+    field: true,
+    where: false
+}).addValue({
+    name: 'id',
+    table: 'pnad_novo',
+    tableField: 'id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    }
+}).addValue({
+    name: 'state',
+    table: 'estado',
+    tableField: ['id', 'nome'],
+    resultField: ['state_id', 'state_nome'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id',
+    },
+    join: {
+        primary: 'id',
+        foreign: 'cod_uf',
+        foreignTable: 'pnad_novo'
+    }
+}).addValue({
+    name: 'state_not',
+    table: 'estado',
+    tableField: ['nome', 'id'],
+    resultField: ['state_name', 'state_id'],
+    where: {
+        relation: '<>',
+        type: 'integer',
+        field: 'cod_uf',
+        table: 'pnad_novo'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'cod_uf',
+        foreignTable: 'pnad_novo'
+    }
+}).addValue({
+    name: 'years_of_study',
+    table: 'pnad_novo',
+    tableField: 'anos_de_estudo',
+    resultField: 'years_of_study_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'anos_de_estudo'
+    }
+}).addValue({
+    name: 'instruction_level',
+    table: 'pnad_novo',
+    tableField: 'nivel_de_instrucao',
+    resultField: 'instruction_level_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'nivel_de_instrucao'
+    }
+}).addValue({
+    name: 'new_pnad_adm_dependency',
+    table: 'pnad_novo',
+    tableField: 'dependencia_adm',
+    resultField: 'new_pnad_adm_dependency_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'dependencia_adm'
+    }
+}).addValue({
+    name: 'attends_school',
+    table: 'pnad_novo',
+    tableField: 'frequenta_escola',
+    resultField: 'attends_school_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'frequenta_escola'
+    }
+}).addValue({
+    name: 'modality',
+    table: 'pnad_novo',
+    tableField: 'modalidade',
+    resultField: 'modality_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'modalidade'
+    }
+}).addValue({
+    name: 'attended_modality',
+    table: 'pnad_novo',
+    tableField: 'nivel_etapa_modalidade_freq',
+    resultField: 'attended_modality_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'nivel_etapa_modalidade_freq'
+    }
+}).addValue({
+    name: 'illiteracy',
+    table: 'pnad_novo',
+    tableField: 'analfabetismo',
+    resultField: 'illiteracy_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'analfabetismo'
+    }
+}).addValue({
+    name: 'modality_shift',
+    table: 'pnad_novo',
+    tableField: 'turno_nivel_etapa',
+    resultField: 'modality_shift_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'turno_nivel_etapa'
+    }
+}).addValue({
+    name: 'bolsa_familia',
+    table: 'pnad_novo',
+    tableField: 'recebeu_rendimentos_de_programa_bolsa_familia',
+    resultField: 'bolsa_familia_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'recebeu_rendimentos_de_programa_bolsa_familia'
+    }
+}).addValue({
+    name: 'new_pnad_ethnic_group',
+    table: 'pnad_novo',
+    tableField: 'cor_raca',
+    resultField: 'new_pnad_ethnic_group_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cor_raca'
+    }
+}).addValue({
+    name: 'age_range_all',
+    table: 'pnad_novo',
+    tableField: 'faixa_etaria',
+    resultField: 'age_range_all_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'faixa_etaria'
+    }
+}).addValue({
+    name: 'income_range',
+    table: 'pnad_novo',
+    tableField: 'faixa_rendimento_aux',
+    resultField: 'income_range_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'faixa_rendimento_aux'
+    }
+}).addValue({
+    name: 'gender',
+    table: 'pnad_novo',
+    tableField: 'sexo',
+    resultField: 'gender_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'sexo'
+    }
+}).addValue({
+    name: 'cap_code',
+    table: 'pnad_novo',
+    tableField: 'cod_cap',
+    resultField: 'cap_code_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_cap'
+    }
+}).addValue({
+    name: 'region',
+    table: 'pnad_novo',
+    tableField: 'cod_regiao',
+    resultField: 'region_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_regiao'
+    }
+}).addValue({
+    name: 'metro_code',
+    table: 'pnad_novo',
+    tableField: 'cod_rm_ride',
+    resultField: 'metro_code_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_rm_ride'
+    }
+}).addValue({
+    name: 'min_year',
+    table: 'pnad_novo',
+    tableField: 'ano_ref',
+    resultField: 'year',
+    where: {
+        relation: '>=',
+        type: 'integer',
+        field: 'ano_ref'
+    }
+}).addValue({
+    name: 'max_year',
+    table: 'pnad_novo',
+    tableField: '',
+    resultField: 'year',
+    where: {
+        relation: '<=',
+        type: 'integer',
+        field: 'ano_ref'
+    }
+}).addField({
+    name: 'search',
+    field: false,
+    where: true
+}).addValueToField({
+    name: 'name',
+    table: 'pnad_novo',
+    tableField: 'nome',
+    where: {
+        relation: 'LIKE',
+        type: 'string',
+        field: 'nome'
+    }
+}, 'search').addValue({
+    name: 'mesoregion',
+    table: 'pnad_novo',
+    tableField: 'mesorregiao_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'mesorregiao_id'
+    }
+}).addValue({
+    name: 'microregion',
+    table: 'pnad_novo',
+    tableField: 'microrregiao_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'microrregiao_id'
+    }
+});
+
+rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
+    req.sql.from('pnad_novo')
+    .field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total')
+    .field('pnad_novo.faixa_etaria')
+    .field('pnad_novo.ano_ref', 'year')
+    .group('pnad_novo.ano_ref')
+    .group('pnad_novo.faixa_etaria')
+    .order('pnad_novo.ano_ref')
+    .order('pnad_novo.faixa_etaria')
+    console.log(req.sql.toString())
+    next();
+}, query, id2str.transform(false), response('pnad_novo'));
+
+module.exports = rateSchoolNewApp;
-- 
GitLab


From 02fc245e62f19823177273017c283d73378ea8ec Mon Sep 17 00:00:00 2001
From: Fernando Gbur <fgs21@inf.ufpr.br>
Date: Mon, 15 Jul 2024 16:51:04 -0400
Subject: [PATCH 02/37] [ADD] First request updated. Trying to get all the
 people who attend schools

---
 src/libs/routes_v1/rateSchoolNew.js | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index 5b680948..a892c00d 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -315,12 +315,13 @@ rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
     .field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total')
     .field('pnad_novo.faixa_etaria')
     .field('pnad_novo.ano_ref', 'year')
+    .where('pnad_novo.ano_censo >= 2019 AND frequenta_escola = 1')
     .group('pnad_novo.ano_ref')
     .group('pnad_novo.faixa_etaria')
     .order('pnad_novo.ano_ref')
     .order('pnad_novo.faixa_etaria')
     console.log(req.sql.toString())
     next();
-}, query, id2str.transform(false), response('pnad_novo'));
+}, query, id2str.transform(false), response('rate_school_new'));
 
 module.exports = rateSchoolNewApp;
-- 
GitLab


From 3da1b4ce5d7e580380ddcb02ce291da974c13ac5 Mon Sep 17 00:00:00 2001
From: Fernando Gbur <fgs21@inf.ufpr.br>
Date: Mon, 15 Jul 2024 16:57:13 -0400
Subject: [PATCH 03/37] [FIX] updating 'ano_censo' to 'ano_ref'

---
 src/libs/routes_v1/rateSchoolNew.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index a892c00d..6980fd80 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -315,7 +315,7 @@ rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
     .field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total')
     .field('pnad_novo.faixa_etaria')
     .field('pnad_novo.ano_ref', 'year')
-    .where('pnad_novo.ano_censo >= 2019 AND frequenta_escola = 1')
+    .where('pnad_novo.ano_ref >= 2019 AND frequenta_escola = 1')
     .group('pnad_novo.ano_ref')
     .group('pnad_novo.faixa_etaria')
     .order('pnad_novo.ano_ref')
-- 
GitLab


From 767d7ffa7173ac8332addb4af2750d8be4b43d93 Mon Sep 17 00:00:00 2001
From: Fernando Gbur <fgs21@inf.ufpr.br>
Date: Mon, 15 Jul 2024 17:32:31 -0400
Subject: [PATCH 04/37] [ADD] Trying to use multiple queries in the new route

---
 src/libs/routes_v1/rateSchoolNew.js | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index 6980fd80..45c00e65 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -32,6 +32,8 @@ const response = require(`${libs}/middlewares/response`);
 
 const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
 
+const multiQuery = require(`${libs}/middlewares/multiQuery`);
+
 const id2str = require(`${libs}/middlewares/id2str`);
 
 const config = require(`${libs}/config`); 
@@ -311,7 +313,10 @@ rqf.addField({
 });
 
 rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
-    req.sql.from('pnad_novo')
+    req.querySet = []
+    
+    let attends_school = req.sql.clone()
+    attends_school.from('pnad_novo')
     .field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total')
     .field('pnad_novo.faixa_etaria')
     .field('pnad_novo.ano_ref', 'year')
@@ -320,8 +325,22 @@ rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
     .group('pnad_novo.faixa_etaria')
     .order('pnad_novo.ano_ref')
     .order('pnad_novo.faixa_etaria')
-    console.log(req.sql.toString())
+    req.querySet.push(attends_school)
+
+    let full_population = req.sql.clone()
+    full_population.from('pnad_novo')
+    .field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total')
+    .field('pnad_novo.faixa_etaria')
+    .field('pnad_novo.ano_ref', 'year')
+    .where('pnad_novo.ano_ref >= 2019')
+    .group('pnad_novo.ano_ref')
+    .group('pnad_novo.faixa_etaria')
+    .order('pnad_novo.ano_ref')
+    .order('pnad_novo.faixa_etaria')
+
     next();
-}, query, id2str.transform(false), response('rate_school_new'));
+}, multiQuery, (req, res, next) => {
+    console.log(req.result)
+}, id2str.transform(false), response('rateSchoolNew'));
 
 module.exports = rateSchoolNewApp;
-- 
GitLab


From 3b19c2e47558f3fe3e3d8a273e960c261e1d067a Mon Sep 17 00:00:00 2001
From: Fernando Gbur <fgs21@inf.ufpr.br>
Date: Mon, 15 Jul 2024 17:40:21 -0400
Subject: [PATCH 05/37] [FIX] Adding the second query to the list and adding
 next() function

---
 src/libs/routes_v1/rateSchoolNew.js | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index 45c00e65..e673d7f6 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -337,6 +337,7 @@ rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
     .group('pnad_novo.faixa_etaria')
     .order('pnad_novo.ano_ref')
     .order('pnad_novo.faixa_etaria')
+    req.querySet.push(full_population)
 
     next();
 }, multiQuery, (req, res, next) => {
-- 
GitLab


From 9dd752f83280c5f1a050b5d8db99786b1154fbf6 Mon Sep 17 00:00:00 2001
From: Fernando Gbur <fgs21@inf.ufpr.br>
Date: Mon, 15 Jul 2024 17:40:31 -0400
Subject: [PATCH 06/37] [FIX] Adding the second query to the list and adding
 next() function

---
 src/libs/routes_v1/rateSchoolNew.js | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index e673d7f6..ee35cf92 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -342,6 +342,7 @@ rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
     next();
 }, multiQuery, (req, res, next) => {
     console.log(req.result)
+    next();
 }, id2str.transform(false), response('rateSchoolNew'));
 
 module.exports = rateSchoolNewApp;
-- 
GitLab


From b4c6885d0b5195766b1d94084ba0e5ef9b29536c Mon Sep 17 00:00:00 2001
From: Fernando Gbur <fgs21@inf.ufpr.br>
Date: Tue, 16 Jul 2024 16:31:21 -0400
Subject: [PATCH 07/37] [TEST] Trying to iterate through different queries in
 JSON

---
 src/libs/routes_v1/rateSchoolNew.js | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index ee35cf92..d0d89924 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -312,6 +312,19 @@ rqf.addField({
     }
 });
 
+function matchQueries(attendsSchoolObj, populationObj) {
+    let match = []
+
+    for (let i = 0; i < attendsSchoolObj.length; i++) {
+        let newObj = {}
+
+        console.log("====TESTE====")
+        console.log(attendsSchoolObj[i])
+        console.log(populationObj[i])
+        console.log("====TESTE====")
+    }
+}
+
 rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
     req.querySet = []
     
@@ -341,7 +354,10 @@ rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
 
     next();
 }, multiQuery, (req, res, next) => {
-    console.log(req.result)
+    
+    //req.result = matchQueries(req.result[0], req.result[1])
+    matchQueries(req.result[0], req.result[1])
+
     next();
 }, id2str.transform(false), response('rateSchoolNew'));
 
-- 
GitLab


From adea4bfb247541355d5f85ffd6651424810281d4 Mon Sep 17 00:00:00 2001
From: Fernando Gbur <fgs21@inf.ufpr.br>
Date: Tue, 16 Jul 2024 17:19:53 -0400
Subject: [PATCH 08/37] [ADD] Matching queries and trying to make the first
 route version

---
 src/libs/routes_v1/rateSchoolNew.js | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index d0d89924..98fa78ea 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -313,22 +313,25 @@ rqf.addField({
 });
 
 function matchQueries(attendsSchoolObj, populationObj) {
-    let match = []
+    let match = [];
 
     for (let i = 0; i < attendsSchoolObj.length; i++) {
-        let newObj = {}
+        let newObj = {};
 
-        console.log("====TESTE====")
-        console.log(attendsSchoolObj[i])
-        console.log(populationObj[i])
-        console.log("====TESTE====")
+        newObj.total = (attendsSchoolObj.total / populationObj.total) * 100;
+        newObj.faixa_etaria = attendsSchoolObj.faixa_etaria;
+        newObj.year = attendsSchoolObj.year;
+
+        match.push(newObj);
     }
+
+    return match;
 }
 
 rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
     req.querySet = []
     
-    let attends_school = req.sql.clone()
+    let attends_school = req.sql.clone();
     attends_school.from('pnad_novo')
     .field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total')
     .field('pnad_novo.faixa_etaria')
@@ -338,9 +341,9 @@ rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
     .group('pnad_novo.faixa_etaria')
     .order('pnad_novo.ano_ref')
     .order('pnad_novo.faixa_etaria')
-    req.querySet.push(attends_school)
+    req.querySet.push(attends_school);
 
-    let full_population = req.sql.clone()
+    let full_population = req.sql.clone();
     full_population.from('pnad_novo')
     .field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total')
     .field('pnad_novo.faixa_etaria')
@@ -350,13 +353,12 @@ rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
     .group('pnad_novo.faixa_etaria')
     .order('pnad_novo.ano_ref')
     .order('pnad_novo.faixa_etaria')
-    req.querySet.push(full_population)
+    req.querySet.push(full_population);
 
     next();
 }, multiQuery, (req, res, next) => {
     
-    //req.result = matchQueries(req.result[0], req.result[1])
-    matchQueries(req.result[0], req.result[1])
+    req.result = matchQueries(req.result[0], req.result[1]);
 
     next();
 }, id2str.transform(false), response('rateSchoolNew'));
-- 
GitLab


From 058b461a787aa52d25bb6d735b32d938aa4aa53e Mon Sep 17 00:00:00 2001
From: Fernando Gbur <fgs21@inf.ufpr.br>
Date: Tue, 16 Jul 2024 17:33:14 -0400
Subject: [PATCH 09/37] [FIX] Trying to fix the null return in route

---
 src/libs/routes_v1/rateSchoolNew.js | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index 98fa78ea..cd08aedd 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -325,6 +325,8 @@ function matchQueries(attendsSchoolObj, populationObj) {
         match.push(newObj);
     }
 
+    console.log(match)
+
     return match;
 }
 
@@ -358,7 +360,8 @@ rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
     next();
 }, multiQuery, (req, res, next) => {
     
-    req.result = matchQueries(req.result[0], req.result[1]);
+    let newObj = matchQueries(req.result[0], req.result[1]);
+    req.result = newObj;
 
     next();
 }, id2str.transform(false), response('rateSchoolNew'));
-- 
GitLab


From 1f2376a31fe7447b215be4780533ce736ca0c93f Mon Sep 17 00:00:00 2001
From: Fernando Gbur <fgs21@inf.ufpr.br>
Date: Tue, 16 Jul 2024 17:33:17 -0400
Subject: [PATCH 10/37] [FIX] Trying to fix the null return in route

---
 src/libs/routes_v1/rateSchoolNew.js | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index cd08aedd..8b24d67d 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -318,9 +318,9 @@ function matchQueries(attendsSchoolObj, populationObj) {
     for (let i = 0; i < attendsSchoolObj.length; i++) {
         let newObj = {};
 
-        newObj.total = (attendsSchoolObj.total / populationObj.total) * 100;
-        newObj.faixa_etaria = attendsSchoolObj.faixa_etaria;
-        newObj.year = attendsSchoolObj.year;
+        newObj.total = (attendsSchoolObj[i].total / populationObj[i].total) * 100;
+        newObj.faixa_etaria = attendsSchoolObj[i].faixa_etaria;
+        newObj.year = attendsSchoolObj[i].year;
 
         match.push(newObj);
     }
-- 
GitLab


From ae55824037cc0d92a42b7267c32c0ddca63821b4 Mon Sep 17 00:00:00 2001
From: Fernando Gbur <fgs21@inf.ufpr.br>
Date: Wed, 17 Jul 2024 17:16:01 -0400
Subject: [PATCH 11/37] [ADD] Adding filters and dimensions to the route

---
 src/libs/routes_v1/rateSchoolNew.js | 84 -----------------------------
 1 file changed, 84 deletions(-)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index 8b24d67d..4b76e5ee 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -24,8 +24,6 @@ const rateSchoolNewApp = express.Router();
 
 const libs = `${process.cwd()}/libs`;
 
-const squel = require('squel');
-
 const query = require(`${libs}/middlewares/query`).query;
 
 const response = require(`${libs}/middlewares/response`);
@@ -99,36 +97,6 @@ rqf.addField({
         foreign: 'cod_uf',
         foreignTable: 'pnad_novo'
     }
-}).addValue({
-    name: 'years_of_study',
-    table: 'pnad_novo',
-    tableField: 'anos_de_estudo',
-    resultField: 'years_of_study_id',
-    where: {
-        relation: '=',
-        type: 'integer',
-        field: 'anos_de_estudo'
-    }
-}).addValue({
-    name: 'instruction_level',
-    table: 'pnad_novo',
-    tableField: 'nivel_de_instrucao',
-    resultField: 'instruction_level_id',
-    where: {
-        relation: '=',
-        type: 'integer',
-        field: 'nivel_de_instrucao'
-    }
-}).addValue({
-    name: 'new_pnad_adm_dependency',
-    table: 'pnad_novo',
-    tableField: 'dependencia_adm',
-    resultField: 'new_pnad_adm_dependency_id',
-    where: {
-        relation: '=',
-        type: 'integer',
-        field: 'dependencia_adm'
-    }
 }).addValue({
     name: 'attends_school',
     table: 'pnad_novo',
@@ -139,46 +107,6 @@ rqf.addField({
         type: 'integer',
         field: 'frequenta_escola'
     }
-}).addValue({
-    name: 'modality',
-    table: 'pnad_novo',
-    tableField: 'modalidade',
-    resultField: 'modality_id',
-    where: {
-        relation: '=',
-        type: 'integer',
-        field: 'modalidade'
-    }
-}).addValue({
-    name: 'attended_modality',
-    table: 'pnad_novo',
-    tableField: 'nivel_etapa_modalidade_freq',
-    resultField: 'attended_modality_id',
-    where: {
-        relation: '=',
-        type: 'integer',
-        field: 'nivel_etapa_modalidade_freq'
-    }
-}).addValue({
-    name: 'illiteracy',
-    table: 'pnad_novo',
-    tableField: 'analfabetismo',
-    resultField: 'illiteracy_id',
-    where: {
-        relation: '=',
-        type: 'integer',
-        field: 'analfabetismo'
-    }
-}).addValue({
-    name: 'modality_shift',
-    table: 'pnad_novo',
-    tableField: 'turno_nivel_etapa',
-    resultField: 'modality_shift_id',
-    where: {
-        relation: '=',
-        type: 'integer',
-        field: 'turno_nivel_etapa'
-    }
 }).addValue({
     name: 'bolsa_familia',
     table: 'pnad_novo',
@@ -209,16 +137,6 @@ rqf.addField({
         type: 'integer',
         field: 'faixa_etaria'
     }
-}).addValue({
-    name: 'income_range',
-    table: 'pnad_novo',
-    tableField: 'faixa_rendimento_aux',
-    resultField: 'income_range_id',
-    where: {
-        relation: '=',
-        type: 'integer',
-        field: 'faixa_rendimento_aux'
-    }
 }).addValue({
     name: 'gender',
     table: 'pnad_novo',
@@ -325,8 +243,6 @@ function matchQueries(attendsSchoolObj, populationObj) {
         match.push(newObj);
     }
 
-    console.log(match)
-
     return match;
 }
 
-- 
GitLab


From 24dcfc9ff79fb7ed4462ea9646b3f5b9efcc4793 Mon Sep 17 00:00:00 2001
From: Lewis <lgtg20@inf.ufpr.br>
Date: Tue, 23 Jul 2024 16:16:22 -0500
Subject: [PATCH 12/37] Adds initial file for aggragete enrollment

---
 src/libs/routes_v1/api.js                 |   3 +
 src/libs/routes_v1/enrollmentAggregate.js | 279 ++++++++++++++++++++++
 2 files changed, 282 insertions(+)
 create mode 100644 src/libs/routes_v1/enrollmentAggregate.js

diff --git a/src/libs/routes_v1/api.js b/src/libs/routes_v1/api.js
index 53f9e4df..17af8276 100644
--- a/src/libs/routes_v1/api.js
+++ b/src/libs/routes_v1/api.js
@@ -143,6 +143,8 @@ const activity = require(`${libs}/routes_v1/activity`);
 
 const newPnad = require(`${libs}/routes_v1/newPnad`);
 
+const enrollmentAggregate = require(`${libs}/routes_v1/enrollmentAggregate`);
+
 const email = require(`${libs}/routes_v1/email`);
 
 api.get('/', (req, res) => {
@@ -205,6 +207,7 @@ api.use('/universityLocalOffer', universityLocalOffer);
 api.use('/message', message);
 api.use('/course_students', courseStudents);
 api.use('/new_pnad', newPnad);
+api.use('/enrollmentAggregate', enrollmentAggregate);
 
 //Publication 
 api.use('/publication', publication);
diff --git a/src/libs/routes_v1/enrollmentAggregate.js b/src/libs/routes_v1/enrollmentAggregate.js
new file mode 100644
index 00000000..27a8e0fe
--- /dev/null
+++ b/src/libs/routes_v1/enrollmentAggregate.js
@@ -0,0 +1,279 @@
+/*
+Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre
+Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
+
+This file is part of simcaq-node.
+
+simcaq-node is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+simcaq-node is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with simcaq-node.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+const express = require('express');
+const { result } = require('lodash');
+
+const enrollmentAggregateApp = express.Router();
+
+const libs = `${process.cwd()}/libs`;
+
+const log = require(`${libs}/log`)(module);
+
+const squel = require('squel');
+
+const query = require(`${libs}/middlewares/query`).query;
+
+const response = require(`${libs}/middlewares/response`);
+
+const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
+
+const id2str = require(`${libs}/middlewares/id2str`);
+
+const config = require(`${libs}/config`);
+
+const addMissing = require(`${libs}/middlewares/addMissing`);
+
+const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware;
+
+enrollmentAggregateApp.use(cache('15 day'));
+
+let rqf = new ReqQueryFields();
+
+rqf.addField({
+    name: 'filter',
+    field: false,
+    where: true
+}).addField({
+    name: 'dims',
+    field: true,
+    where: false
+}).addValue({
+    name: 'adm_dependency',
+    table: 'escola',
+    tableField: 'dependencia_adm_id',
+    resultField: 'adm_dependency_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'dependencia_adm_id'
+    }
+}).addValue({
+    name: 'adm_dependency_detailed',
+    table: 'escola',
+    tableField: 'dependencia_adm_priv',
+    resultField: 'adm_dependency_detailed_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'dependencia_adm_priv'
+    }
+}).addValue({
+    name: 'education_level_mod',
+    table: 'escola',
+    tableField: 'etapas_mod_ensino_segmento_id',
+    resultField: 'education_level_mod_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'etapas_mod_ensino_segmento_id'
+    }
+}).addValue({
+    name: 'education_level_short',
+    table: 'escola',
+    tableField: 'etapa_resumida',
+    resultField: 'education_level_short_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'etapa_resumida'
+    }
+}).addValue({
+    name: 'region',
+    table: 'regiao',
+    tableField: ['nome', 'id'],
+    resultField: ['region_name', 'region_id'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'regiao_id',
+        foreignTable: 'escola'
+    }
+}).addValue({
+    name: 'mesoregion',
+    table: 'municipio',
+    tableField: ['nome_mesorregiao', 'mesorregiao_id'],
+    resultField: ['mesoregion_name', 'mesoregion_id'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'mesorregiao_id',
+        table: 'municipio'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'municipio_id',
+        foreignTable: 'escola'
+    }
+}).addValue({
+    name: 'microregion',
+    table: 'municipio',
+    tableField: ['nome_microrregiao', 'microrregiao_id'],
+    resultField: ['microregion_name', 'microregion_id'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'microrregiao_id',
+        table: 'municipio'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'municipio_id',
+        foreignTable: 'escola'
+    }
+}).addValueToField({
+    name: 'state',
+    table: 'estado',
+    tableField: ['nome', 'id'],
+    resultField: ['state_name', 'state_id'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'estado_id',
+        foreignTable: 'escola'
+    }
+}, 'dims').addValueToField({
+    name: 'state',
+    table: 'estado',
+    tableField: 'nome',
+    resultField: 'state_name',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'estado_id',
+        foreignTable: 'escola'
+    }
+}, 'filter').addValueToField({
+    name: 'city',
+    table: 'municipio',
+    tableField: ['nome', 'id'],
+    resultField: ['city_name', 'city_id'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'municipio_id',
+        foreignTable: 'escola'
+    }
+}, 'dims').addValueToField({
+    name: 'city',
+    table: 'municipio',
+    tableField: 'nome',
+    resultField: 'city_name',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'municipio_id',
+        foreignTable: 'escola'
+    }
+}, 'filter').addValueToField({
+    name: 'school',
+    table: 'escola',
+    tableField: ['nome_escola', 'id'],
+    resultField: ['school_name', 'school_id'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    },
+    join: {
+        primary: ['id', 'ano_censo'],
+        foreign: ['escola_id', 'ano_censo'],
+        foreignTable: 'escola'
+    }
+}, 'dims').addValueToField({
+    name: 'locale_id',
+    table: 'escola',
+    tableField: 'localizacao_id',
+    resultField: 'locale_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'localizacao_id'
+    }
+}, 'dims').addValueToField({
+    name: 'school_id',
+    table: 'escola',
+    tableField: 'id',
+    resultField: 'school_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    },
+    join: {
+        primary: ['id', 'ano_censo'],
+        foreign: ['escola_id', 'ano_censo'],
+        foreignTable: 'escola'
+    }
+}, 'dims').addValueToField({
+    name: 'school',
+    table: 'escola',
+    tableField: 'nome_escola',
+    resultField: 'school_name',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    },
+    join: {
+        primary: ['id', 'ano_censo'],
+        foreign: ['escola_id', 'ano_censo'],
+        foreignTable: 'escola'
+    }
+}, 'filter').addValue({
+    name: 'location',
+    table: 'escola',
+    tableField: 'localizacao_id',
+    resultField: 'location_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'localizacao_id'
+    }
+});
+
+// Return all cities
+enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
+    req.sql.from('escola')
+    .field('SUM(escola.qt_mat_bas)', 'total')
+    next();
+}, query, response('enrollment_aggregate'));
+
+module.exports = enrollmentAggregateApp;
-- 
GitLab


From 892a5cf7fe45e16ef941d8ab7e3a00bb2167f8cf Mon Sep 17 00:00:00 2001
From: ems19 <ems19@inf.ufpr.br>
Date: Tue, 23 Jul 2024 19:09:58 -0300
Subject: [PATCH 13/37] adds year filter

---
 src/libs/routes_v1/enrollmentAggregate.js | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/libs/routes_v1/enrollmentAggregate.js b/src/libs/routes_v1/enrollmentAggregate.js
index 27a8e0fe..78cfe4e6 100644
--- a/src/libs/routes_v1/enrollmentAggregate.js
+++ b/src/libs/routes_v1/enrollmentAggregate.js
@@ -142,6 +142,26 @@ rqf.addField({
         foreign: 'municipio_id',
         foreignTable: 'escola'
     }
+}).addValue({
+    name: 'min_year',
+    table: 'escola',
+    tableField: 'ano_censo',
+    resultField: 'year',
+    where: {
+        relation: '>=',
+        type: 'integer',
+        field: 'ano_censo',
+    },
+}).addValue({
+    name: 'max_year',
+    table: 'escola',
+    tableField: 'ano_censo',
+    resultField: 'year',
+    where: {
+        relation: '<=',
+        type: 'integer',
+        field: 'ano_censo',
+    },
 }).addValueToField({
     name: 'state',
     table: 'estado',
@@ -273,6 +293,9 @@ rqf.addField({
 enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
     req.sql.from('escola')
     .field('SUM(escola.qt_mat_bas)', 'total')
+	.field('escola.ano_censo', 'year')
+	.group('escola.ano_censo')
+	.order('escola.ano_censo');
     next();
 }, query, response('enrollment_aggregate'));
 
-- 
GitLab


From 7dc4874fef7ed3fcfb6a68368bdd1a439933d999 Mon Sep 17 00:00:00 2001
From: Lewis <lgtg20@inf.ufpr.br>
Date: Tue, 30 Jul 2024 10:17:21 -0500
Subject: [PATCH 14/37] trying

---
 src/libs/routes_v1/enrollmentAggregate.js | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/libs/routes_v1/enrollmentAggregate.js b/src/libs/routes_v1/enrollmentAggregate.js
index 78cfe4e6..e5b877f0 100644
--- a/src/libs/routes_v1/enrollmentAggregate.js
+++ b/src/libs/routes_v1/enrollmentAggregate.js
@@ -291,6 +291,19 @@ rqf.addField({
 
 // Return all cities
 enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
+
+    console.log(req.query);
+
+    if (req.query.dims.includes('gender'))
+    {
+        req.sql.from('escola')
+        .field('SUM(escola.qt_mat_bas_mas)', 'total_mas')
+        .field('SUM(escola.qt_mat_bas_fem)', 'total_fem')
+        .field('escola.ano_censo', 'year')
+        .group('escola.ano_censo')
+        .order('escola.ano_censo');
+    }
+
     req.sql.from('escola')
     .field('SUM(escola.qt_mat_bas)', 'total')
 	.field('escola.ano_censo', 'year')
-- 
GitLab


From 06b9f3d31aa6a3d2b9f76a0e3bb49f07562bb56d Mon Sep 17 00:00:00 2001
From: Lewis <lgtg20@inf.ufpr.br>
Date: Tue, 30 Jul 2024 14:41:22 -0300
Subject: [PATCH 15/37] praying

---
 src/libs/middlewares/aggregateData.js     | 41 +++++++++++++++++++++++
 src/libs/routes_v1/enrollmentAggregate.js | 21 +++++++-----
 2 files changed, 53 insertions(+), 9 deletions(-)
 create mode 100644 src/libs/middlewares/aggregateData.js

diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js
new file mode 100644
index 00000000..a7d24c42
--- /dev/null
+++ b/src/libs/middlewares/aggregateData.js
@@ -0,0 +1,41 @@
+const id2str = require(`./id2str`);
+
+function aggregateData(req, res, next) {
+    const newResult = []
+    const aggregateFields = ['gender']
+    let id;
+    const fields = req.query.dims.split(',');
+    let currentAggregateField;
+    let currentNonAggregateField;
+    fields.forEach(field => {if (aggregateFields.includes(field)) currentAggregateField = field; else currentNonAggregateField = field});
+    if (currentAggregateField) {
+        console.log(currentAggregateField);
+        req.result.forEach((r) => {
+            id = 1;
+            for (const property in r) {
+                if (property.includes("total_")) {
+                    const data = {
+                        total: r[property],
+                        year: r.year,
+                        [`${currentAggregateField}_id`]: id,
+                        [`${currentAggregateField}_name`]: id2str[currentAggregateField](id)
+                    }
+    
+                    if (currentNonAggregateField) {
+                        data[`${currentNonAggregateField}_id`] = r[`${currentNonAggregateField}_id`];
+                        console.log(currentNonAggregateField)
+                        data[`${currentNonAggregateField}_name`] = id2str[`${currentNonAggregateField}_id`](id);
+                    }
+    
+                    newResult.push(data)
+                    ++id;
+                }
+            }
+        })
+        req.result = newResult;
+    }
+    console.log(req.result);
+    next();
+}
+
+module.exports = aggregateData;
\ No newline at end of file
diff --git a/src/libs/routes_v1/enrollmentAggregate.js b/src/libs/routes_v1/enrollmentAggregate.js
index e5b877f0..6f225d65 100644
--- a/src/libs/routes_v1/enrollmentAggregate.js
+++ b/src/libs/routes_v1/enrollmentAggregate.js
@@ -35,6 +35,8 @@ const response = require(`${libs}/middlewares/response`);
 
 const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
 
+const aggregateData = require(`${libs}/middlewares/aggregateData`);
+
 const id2str = require(`${libs}/middlewares/id2str`);
 
 const config = require(`${libs}/config`);
@@ -294,22 +296,23 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
 
     console.log(req.query);
 
-    if (req.query.dims.includes('gender'))
+    if (req.query.dims && req.query.dims.includes('gender'))
     {
         req.sql.from('escola')
-        .field('SUM(escola.qt_mat_bas_mas)', 'total_mas')
+        .field('SUM(escola.qt_mat_bas_masc)', 'total_mas')
         .field('SUM(escola.qt_mat_bas_fem)', 'total_fem')
         .field('escola.ano_censo', 'year')
         .group('escola.ano_censo')
         .order('escola.ano_censo');
     }
-
-    req.sql.from('escola')
-    .field('SUM(escola.qt_mat_bas)', 'total')
-	.field('escola.ano_censo', 'year')
-	.group('escola.ano_censo')
-	.order('escola.ano_censo');
+    else {
+        req.sql.from('escola')
+        .field('SUM(escola.qt_mat_bas)', 'total')
+        .field('escola.ano_censo', 'year')
+        .group('escola.ano_censo')
+        .order('escola.ano_censo');
+    }
     next();
-}, query, response('enrollment_aggregate'));
+}, query, aggregateData, response('enrollment_aggregate'));
 
 module.exports = enrollmentAggregateApp;
-- 
GitLab


From 95c251efdf55e2ae08927927c8a3f830d038c426 Mon Sep 17 00:00:00 2001
From: Lewis <lgtg20@inf.ufpr.br>
Date: Tue, 30 Jul 2024 16:20:17 -0300
Subject: [PATCH 16/37] Apparently working

---
 src/libs/middlewares/aggregateData.js | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js
index a7d24c42..58a098c9 100644
--- a/src/libs/middlewares/aggregateData.js
+++ b/src/libs/middlewares/aggregateData.js
@@ -1,5 +1,9 @@
 const id2str = require(`./id2str`);
 
+const convert = {
+    "adm_dependency_detailed": "admDependencyPriv"
+}
+
 function aggregateData(req, res, next) {
     const newResult = []
     const aggregateFields = ['gender']
@@ -14,7 +18,7 @@ function aggregateData(req, res, next) {
             id = 1;
             for (const property in r) {
                 if (property.includes("total_")) {
-                    const data = {
+                    let data = {
                         total: r[property],
                         year: r.year,
                         [`${currentAggregateField}_id`]: id,
@@ -23,8 +27,7 @@ function aggregateData(req, res, next) {
     
                     if (currentNonAggregateField) {
                         data[`${currentNonAggregateField}_id`] = r[`${currentNonAggregateField}_id`];
-                        console.log(currentNonAggregateField)
-                        data[`${currentNonAggregateField}_name`] = id2str[`${currentNonAggregateField}_id`](id);
+                        data[`${currentNonAggregateField}_name`] = id2str[convert[currentNonAggregateField]](r[`${currentNonAggregateField}_id`]);
                     }
     
                     newResult.push(data)
-- 
GitLab


From 85fb606618123555fdfdb0477d68e681392440e2 Mon Sep 17 00:00:00 2001
From: Lewis <lgtg20@inf.ufpr.br>
Date: Wed, 31 Jul 2024 14:27:04 -0300
Subject: [PATCH 17/37] Almost finished

---
 src/libs/convert/ageRangeAggregate.js     | 38 +++++++++++++++++
 src/libs/convert/educationLevelModAgg.js  | 46 +++++++++++++++++++++
 src/libs/middlewares/aggregateData.js     | 12 ++++--
 src/libs/middlewares/id2str.js            |  7 ++++
 src/libs/routes_v1/enrollmentAggregate.js | 50 +++++++++++++++++++++++
 5 files changed, 149 insertions(+), 4 deletions(-)
 create mode 100644 src/libs/convert/ageRangeAggregate.js
 create mode 100644 src/libs/convert/educationLevelModAgg.js

diff --git a/src/libs/convert/ageRangeAggregate.js b/src/libs/convert/ageRangeAggregate.js
new file mode 100644
index 00000000..850f0038
--- /dev/null
+++ b/src/libs/convert/ageRangeAggregate.js
@@ -0,0 +1,38 @@
+/*
+Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre
+Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
+   
+This file is part of simcaq-node.
+
+simcaq-node is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+simcaq-node is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with simcaq-node.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+module.exports = function ageRangeAggregate(id) {
+    switch (id) {
+        case 1:
+        return '0 a 3 anos';
+        case 2:
+        return '4 a 5 anos';
+        case 3:
+        return '6 a 10 anos';
+        case 4:
+        return '11 a 14 anos';
+        case 5:
+        return '15 a 17 anos';
+        case 6:
+        return '18 anos ou mais';
+        default:
+        return 'Não declarada';
+    }
+};
diff --git a/src/libs/convert/educationLevelModAgg.js b/src/libs/convert/educationLevelModAgg.js
new file mode 100644
index 00000000..c55a7e8f
--- /dev/null
+++ b/src/libs/convert/educationLevelModAgg.js
@@ -0,0 +1,46 @@
+/*
+Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre
+Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
+
+This file is part of simcaq-node.
+
+simcaq-node is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+simcaq-node is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with simcaq-node.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+module.exports = function educationLevelMod(id) {
+    switch (id) {
+        case 1:
+        return 'Creche';
+        case 2:
+        return 'Pré-Escola';
+        case 3:
+        return 'Ensino Fundamental - anos iniciais';
+        case 4:
+        return 'Ensino Fundamental - anos finais';
+        case 5:
+        return 'Ensino Médio';
+        case 6:
+        return 'Ensino Medio Integrado ou Normal - tecnico';
+        case 7:
+        return 'EJA - Ensino Fundamental';
+        case 8:
+        return 'EJA - Ensino Médio';
+        case 9:
+        return 'EJA - EF e EM Integrado - tecnico';
+        case 10:
+        return 'Educacao Profissional - concomitante e subsequente';
+        default:
+        return 'Não classificada';
+    }
+};
diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js
index 58a098c9..41c32836 100644
--- a/src/libs/middlewares/aggregateData.js
+++ b/src/libs/middlewares/aggregateData.js
@@ -1,12 +1,16 @@
 const id2str = require(`./id2str`);
 
 const convert = {
-    "adm_dependency_detailed": "admDependencyPriv"
+    "adm_dependency_detailed": "admDependencyPriv",
+    "age_range": "ageRangeAggregate",
+    "gender": "gender",
+    "ethnic_group": "ethnicGroup",
+    "education_level_mod_agg": "educationLevelModAgg"
 }
 
 function aggregateData(req, res, next) {
     const newResult = []
-    const aggregateFields = ['gender']
+    const aggregateFields = ['gender', 'age_range', 'ethnic_group', 'education_level_mod_agg']
     let id;
     const fields = req.query.dims.split(',');
     let currentAggregateField;
@@ -15,14 +19,14 @@ function aggregateData(req, res, next) {
     if (currentAggregateField) {
         console.log(currentAggregateField);
         req.result.forEach((r) => {
-            id = 1;
+            id = currentAggregateField === 'ethnic_group' ? 0 : 1;
             for (const property in r) {
                 if (property.includes("total_")) {
                     let data = {
                         total: r[property],
                         year: r.year,
                         [`${currentAggregateField}_id`]: id,
-                        [`${currentAggregateField}_name`]: id2str[currentAggregateField](id)
+                        [`${currentAggregateField}_name`]: id2str[convert[currentAggregateField]](id)
                     }
     
                     if (currentNonAggregateField) {
diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js
index 02273a8b..0a48e4ce 100644
--- a/src/libs/middlewares/id2str.js
+++ b/src/libs/middlewares/id2str.js
@@ -32,6 +32,7 @@ const agreement = require(`${libs}/convert/agreement`);
 const booleanVariable = require(`${libs}/convert/booleanVariable`);
 const educationLevel = require(`${libs}/convert/educationLevel`);
 const educationLevelMod = require(`${libs}/convert/educationLevelMod`);
+const educationLevelModAgg = require(`${libs}/convert/educationLevelModAgg`);
 const educationLevelShort = require(`${libs}/convert/educationLevelShort`);
 const educationType = require(`${libs}/convert/educationType`);
 const citySize = require(`${libs}/convert/citySize`);
@@ -114,6 +115,8 @@ const regionCode = require(`${libs}/convert/regionCode`);
 const metroCode =  require(`${libs}/convert/metroCode`);
 const modalityShift = require(`${libs}/convert/modalityShift`);
 const incomeRange = require(`${libs}/convert/incomeRange`);
+const ageRangeAggregate = require(`${libs}/convert/ageRangeAggregate`);
+
 
 const ids = {
     gender_id: gender,
@@ -122,6 +125,7 @@ const ids = {
     education_level_id: educationLevel,
     education_level_basic_id: educationLevelBasic,
     education_level_mod_id: educationLevelMod,
+    education_level_mod_agg_id: educationLevelModAgg,
     education_level_short_id: educationLevelShort,
     adm_dependency_id: admDependency,
     adm_dependency_detailed_id: admDependencyPriv,
@@ -149,6 +153,7 @@ const ids = {
     ethnic_group_pnad_id: ethnicGroupPnad,
     age_range_id: ageRange,
     age_range_all_id: ageRangeAll,
+    age_range_aggregate_id: ageRangeAggregate,
     full_age_range_id: fullAgeRange,
     gender_pnad_id: genderPnad,
     fifth_household_income_id: fifthHouseholdIncome,
@@ -267,6 +272,7 @@ module.exports = {
     educationLevel,
     educationLevelBasic,
     educationLevelMod,
+    educationLevelModAgg,
     educationLevelShort,
     educationLevelSchoolYear,
     admDependency,
@@ -284,6 +290,7 @@ module.exports = {
     contractType,
     ethnicGroupPnad,
     ageRange,
+    ageRangeAggregate,
     ageRangeAll,
     ageStudentCode,
     fullAgeRange,
diff --git a/src/libs/routes_v1/enrollmentAggregate.js b/src/libs/routes_v1/enrollmentAggregate.js
index 6f225d65..95de1c25 100644
--- a/src/libs/routes_v1/enrollmentAggregate.js
+++ b/src/libs/routes_v1/enrollmentAggregate.js
@@ -88,6 +88,16 @@ rqf.addField({
         field: 'etapas_mod_ensino_segmento_id'
     }
 }).addValue({
+    name:'integral_time',
+    table: 'escola',
+    tableField: 'tempo_integral',
+    resultField: 'integral_time_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'tempo_integral'
+    }
+  }).addValue({
     name: 'education_level_short',
     table: 'escola',
     tableField: 'etapa_resumida',
@@ -305,6 +315,46 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
         .group('escola.ano_censo')
         .order('escola.ano_censo');
     }
+    else if (req.query.dims && req.query.dims.includes('age_range')) {
+        req.sql.from('escola')
+        .field('SUM(escola.qt_mat_bas_0_3)', 'total_0_3')
+        .field('SUM(escola.qt_mat_bas_4_5)', 'total_4_5')
+        .field('SUM(escola.qt_mat_bas_6_10)', 'total_6_10')
+        .field('SUM(escola.qt_mat_bas_11_14)', 'total_11_14')
+        .field('SUM(escola.qt_mat_bas_15_17)', 'total_15_17')
+        .field('SUM(escola.qt_mat_bas_18_mais)', 'total_18_mais')
+        .field('escola.ano_censo', 'year')
+        .group('escola.ano_censo')
+        .order('escola.ano_censo');
+    }
+    else if (req.query.dims && req.query.dims.includes('ethnic_group')) {
+        req.sql.from('escola')
+        .field('SUM(escola.qt_mat_bas_nd)', 'total_nd')
+        .field('SUM(escola.qt_mat_bas_branca)', 'total_branca')
+        .field('SUM(escola.qt_mat_bas_preta)', 'total_preta')
+        .field('SUM(escola.qt_mat_bas_parda)', 'total_parda')
+        .field('SUM(escola.qt_mat_bas_amarela)', 'total_amarela')
+        .field('SUM(escola.qt_mat_bas_indigena)', 'total_indigena')
+        .field('escola.ano_censo', 'year')
+        .group('escola.ano_censo')
+        .order('escola.ano_censo');
+    }
+    else if (req.query.dims && req.query.dims.includes('education_level_mod_agg')) {
+        req.sql.from('escola')
+        .field('SUM(escola.qt_mat_inf_cre)', 'total_cre')
+        .field('SUM(escola.qt_mat_inf_pre)', 'total_pre')
+        .field('SUM(escola.qt_mat_fund_ai)', 'total_fund_ai')
+        .field('SUM(escola.qt_mat_fund_af)', 'total_fund_af')
+        .field('SUM(escola.qt_mat_med_agg)', 'total_med')
+        .field('SUM(escola.qt_mat_med_ct + escola.qt_mat_med_nm)', 'total_med_in')
+        .field('SUM(escola.qt_mat_eja_fund_agg)', 'total_eja_fund')
+        .field('SUM(escola.qt_mat_eja_med_agg)', 'total_eja_med')
+        .field('SUM(escola.qt_mat_eja_fund_fic + escola.qt_mat_eja_med_fic + escola.qt_mat_eja_med_tec)', 'total_tec')
+        .field('SUM(escola.qt_mat_prof_agg)', 'total_prof')
+        .field('escola.ano_censo', 'year')
+        .group('escola.ano_censo')
+        .order('escola.ano_censo');
+    }
     else {
         req.sql.from('escola')
         .field('SUM(escola.qt_mat_bas)', 'total')
-- 
GitLab


From 959f9a125ac27f51a5a5ae502d3480ae6399d94d Mon Sep 17 00:00:00 2001
From: Lewis <lgtg20@inf.ufpr.br>
Date: Thu, 1 Aug 2024 17:25:36 -0300
Subject: [PATCH 18/37] integral_time filter working

---
 src/libs/middlewares/aggregateData.js     |  7 ++++---
 src/libs/routes_v1/enrollmentAggregate.js | 11 +++++++++++
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js
index 41c32836..f0378d0b 100644
--- a/src/libs/middlewares/aggregateData.js
+++ b/src/libs/middlewares/aggregateData.js
@@ -5,12 +5,13 @@ const convert = {
     "age_range": "ageRangeAggregate",
     "gender": "gender",
     "ethnic_group": "ethnicGroup",
-    "education_level_mod_agg": "educationLevelModAgg"
+    "education_level_mod_agg": "educationLevelModAgg",
+    'integral_time_agg': 'integralTime'
 }
 
 function aggregateData(req, res, next) {
     const newResult = []
-    const aggregateFields = ['gender', 'age_range', 'ethnic_group', 'education_level_mod_agg']
+    const aggregateFields = ['gender', 'age_range', 'ethnic_group', 'education_level_mod_agg', 'integral_time_agg']
     let id;
     const fields = req.query.dims.split(',');
     let currentAggregateField;
@@ -19,7 +20,7 @@ function aggregateData(req, res, next) {
     if (currentAggregateField) {
         console.log(currentAggregateField);
         req.result.forEach((r) => {
-            id = currentAggregateField === 'ethnic_group' ? 0 : 1;
+            id = ['ethnic_group', 'integral_time_agg'].includes(currentAggregateField) ? 0 : 1;
             for (const property in r) {
                 if (property.includes("total_")) {
                     let data = {
diff --git a/src/libs/routes_v1/enrollmentAggregate.js b/src/libs/routes_v1/enrollmentAggregate.js
index 95de1c25..c12329cd 100644
--- a/src/libs/routes_v1/enrollmentAggregate.js
+++ b/src/libs/routes_v1/enrollmentAggregate.js
@@ -355,6 +355,17 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
         .group('escola.ano_censo')
         .order('escola.ano_censo');
     }
+    else if (req.query.dims && req.query.dims.includes('integral_time_agg')) {
+
+        req.sql.from('turma,escola')
+        .field('SUM(CASE WHEN turma.tempo_integral=0 then turma.num_matricula ELSE 0 END)', 'total_int_nao')
+        .field('SUM(CASE WHEN turma.tempo_integral=1 then turma.num_matricula ELSE 0 END)', 'total_int')
+        .field('SUM(CASE WHEN turma.tempo_integral=2 then turma.num_matricula ELSE 0 END)', 'total_int_nao_aplica')
+        .field('escola.ano_censo', 'year')
+        .group('escola.ano_censo')
+        .order('escola.ano_censo')
+        .where('turma.tipo_atendimento_id <= 2 and turma.escola_id = escola.id and turma.ano_censo = escola.ano_censo');
+    }
     else {
         req.sql.from('escola')
         .field('SUM(escola.qt_mat_bas)', 'total')
-- 
GitLab


From ecd2aed68f22e46878bd42266fe8f430d7027b6c Mon Sep 17 00:00:00 2001
From: Lewis <lgtg20@inf.ufpr.br>
Date: Thu, 1 Aug 2024 23:06:54 -0300
Subject: [PATCH 19/37] all filters completed

---
 src/libs/middlewares/aggregateData.js     |  5 +++--
 src/libs/routes_v1/enrollmentAggregate.js | 25 +++++++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js
index f0378d0b..265e973c 100644
--- a/src/libs/middlewares/aggregateData.js
+++ b/src/libs/middlewares/aggregateData.js
@@ -6,12 +6,13 @@ const convert = {
     "gender": "gender",
     "ethnic_group": "ethnicGroup",
     "education_level_mod_agg": "educationLevelModAgg",
-    'integral_time_agg': 'integralTime'
+    'integral_time_agg': 'integralTime',
+    'period_agg': 'period'
 }
 
 function aggregateData(req, res, next) {
     const newResult = []
-    const aggregateFields = ['gender', 'age_range', 'ethnic_group', 'education_level_mod_agg', 'integral_time_agg']
+    const aggregateFields = ['gender', 'age_range', 'ethnic_group', 'education_level_mod_agg', 'integral_time_agg', 'period_agg']
     let id;
     const fields = req.query.dims.split(',');
     let currentAggregateField;
diff --git a/src/libs/routes_v1/enrollmentAggregate.js b/src/libs/routes_v1/enrollmentAggregate.js
index c12329cd..feae2681 100644
--- a/src/libs/routes_v1/enrollmentAggregate.js
+++ b/src/libs/routes_v1/enrollmentAggregate.js
@@ -366,6 +366,31 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
         .order('escola.ano_censo')
         .where('turma.tipo_atendimento_id <= 2 and turma.escola_id = escola.id and turma.ano_censo = escola.ano_censo');
     }
+    else if (req.query.dims && req.query.dims.includes('period_agg')) {
+
+        req.sql.from('turma,escola')
+        .field('SUM(CASE WHEN turma.turma_turno_id=1 then turma.num_matricula ELSE 0 END)', 'total_qt_mat_bas_matutino')
+        .field('SUM(CASE WHEN turma.turma_turno_id=2 then turma.num_matricula ELSE 0 END)', 'total_qt_mat_bas_vespertino')
+        .field('SUM(CASE WHEN turma.turma_turno_id=3 then turma.num_matricula ELSE 0 END)', 'total_qt_mat_bas_noturno')
+        .field('SUM(CASE WHEN turma.turma_turno_id=4 then turma.num_matricula ELSE 0 END)', 'total_qt_mat_bas_integral')
+        .field('SUM(CASE WHEN turma.turma_turno_id=99 then turma.num_matricula ELSE 0 END)', 'total_qt_mat_bas_semi_ead')
+        .field('escola.ano_censo', 'year')
+        .group('escola.ano_censo')
+        .order('escola.ano_censo')
+        .where('turma.tipo_atendimento_id <= 2 and turma.escola_id = escola.id and turma.ano_censo = escola.ano_censo');
+    }
+    else if (req.query.dims && req.query.dims.includes('modality_integral_time')) {
+
+        req.sql.from('escola')
+        .field('SUM(escola.qt_mat_inf_cre_int)', 'total_qt_mat_inf_cre_int')
+        .field('SUM(escola.qt_mat_inf_pre_int)', 'total_qt_mat_inf_pre_int')
+        .field('SUM(escola.qt_mat_fund_ai_int)', 'total_qt_mat_fund_ai_int')
+        .field('SUM(escola.qt_mat_fund_af_int)', 'total_qt_mat_fund_af_int')
+        .field('SUM(escola.qt_mat_med_int)', 'total_qt_mat_med_int')
+        .field('escola.ano_censo', 'year')
+        .group('escola.ano_censo')
+        .order('escola.ano_censo')
+    }
     else {
         req.sql.from('escola')
         .field('SUM(escola.qt_mat_bas)', 'total')
-- 
GitLab


From adbb6ade766216a0cc67f202e16d42c5367e67e6 Mon Sep 17 00:00:00 2001
From: Lewis <lgtg20@inf.ufpr.br>
Date: Fri, 2 Aug 2024 00:22:12 -0300
Subject: [PATCH 20/37] Everything implemented

---
 src/libs/convert/especialEducation.js     |  31 ++++
 src/libs/middlewares/aggregateData.js     |  19 ++-
 src/libs/middlewares/id2str.js            |   8 +-
 src/libs/routes_v1/enrollmentAggregate.js | 199 +++++++++++++++++++++-
 4 files changed, 247 insertions(+), 10 deletions(-)
 create mode 100644 src/libs/convert/especialEducation.js

diff --git a/src/libs/convert/especialEducation.js b/src/libs/convert/especialEducation.js
new file mode 100644
index 00000000..46349784
--- /dev/null
+++ b/src/libs/convert/especialEducation.js
@@ -0,0 +1,31 @@
+/*
+Copyright (C) 2022 Centro de Computacao Cientifica e Software Livre
+Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
+
+This file is part of simcaq-node.
+
+simcaq-node is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+simcaq-node is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with simcaq-node.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+module.exports = function especialEducation(id) {
+    switch (id) {
+        case 1:
+        return 'Inclusiva';
+        case 2:
+        return 'Exclusiva';
+        default:
+        return 'Não definido';
+    }
+};
+  
diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js
index 265e973c..a721bb1b 100644
--- a/src/libs/middlewares/aggregateData.js
+++ b/src/libs/middlewares/aggregateData.js
@@ -1,5 +1,12 @@
 const id2str = require(`./id2str`);
 
+/*
+    Middleware que tem como função formatar dados agregados.
+    Dados agregados não podem ser "puxados" do banco de dados da mesma maneira que os dados tradicioanis, dessa maneira é
+    necessário formatá-los para que sigam o padrão.
+*/
+
+// Faz o mapeamento dos filtros com seus respectivos "id2str"
 const convert = {
     "adm_dependency_detailed": "admDependencyPriv",
     "age_range": "ageRangeAggregate",
@@ -7,22 +14,28 @@ const convert = {
     "ethnic_group": "ethnicGroup",
     "education_level_mod_agg": "educationLevelModAgg",
     'integral_time_agg': 'integralTime',
-    'period_agg': 'period'
+    'period_agg': 'period',
+    'modality_integral_time': 'educationLevelBasic',
+    'especial_education': 'especialEducation'
 }
 
 function aggregateData(req, res, next) {
     const newResult = []
-    const aggregateFields = ['gender', 'age_range', 'ethnic_group', 'education_level_mod_agg', 'integral_time_agg', 'period_agg']
+    const aggregateFields = ['gender', 'age_range', 'ethnic_group', 'education_level_mod_agg', 'integral_time_agg', 'period_agg', 'modality_integral_time', 'especial_education']
     let id;
     const fields = req.query.dims.split(',');
     let currentAggregateField;
     let currentNonAggregateField;
+
+    // Verifica se o filtro passado está presente nos filtros agregados
     fields.forEach(field => {if (aggregateFields.includes(field)) currentAggregateField = field; else currentNonAggregateField = field});
+    console.log(convert[currentAggregateField])
     if (currentAggregateField) {
-        console.log(currentAggregateField);
         req.result.forEach((r) => {
+            // Alguns filtros começam com o id = 0 outros id = 1
             id = ['ethnic_group', 'integral_time_agg'].includes(currentAggregateField) ? 0 : 1;
             for (const property in r) {
+                // Dados agregados são identificados com a substring "total_" em sua chave
                 if (property.includes("total_")) {
                     let data = {
                         total: r[property],
diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js
index 0a48e4ce..06f24488 100644
--- a/src/libs/middlewares/id2str.js
+++ b/src/libs/middlewares/id2str.js
@@ -116,7 +116,7 @@ const metroCode =  require(`${libs}/convert/metroCode`);
 const modalityShift = require(`${libs}/convert/modalityShift`);
 const incomeRange = require(`${libs}/convert/incomeRange`);
 const ageRangeAggregate = require(`${libs}/convert/ageRangeAggregate`);
-
+const especialEducation = require(`${libs}/convert/especialEducation`);
 
 const ids = {
     gender_id: gender,
@@ -225,7 +225,8 @@ const ids = {
     region_id: regionCode,
     metro_code_id: metroCode,
     modality_shift_id: modalityShift,
-    income_range_id: incomeRange
+    income_range_id: incomeRange,
+    especial_education: especialEducation
 };
 
 function transform(removeId=false) {
@@ -356,5 +357,6 @@ module.exports = {
     regionCode,
     metroCode,
     modalityShift,
-    incomeRange
+    incomeRange,
+    especialEducation
 };
diff --git a/src/libs/routes_v1/enrollmentAggregate.js b/src/libs/routes_v1/enrollmentAggregate.js
index feae2681..e7de586c 100644
--- a/src/libs/routes_v1/enrollmentAggregate.js
+++ b/src/libs/routes_v1/enrollmentAggregate.js
@@ -49,6 +49,182 @@ enrollmentAggregateApp.use(cache('15 day'));
 
 let rqf = new ReqQueryFields();
 
+enrollmentAggregateApp.get('/years', (req, res, next) => {
+    req.sql.from('escola')
+    .field('DISTINCT escola.ano_censo', 'year')
+    .where('escola.ano_censo >= 2021')
+    next();
+}, query, response('years'));
+
+enrollmentAggregateApp.get('/adm_dependency', (req, res, next) => {
+    req.result = []
+
+    for (let i = 1; i <= 5; i++) {
+        req.result.push({
+            id: i, name: id2str.admDependency(i)
+        });
+    }
+    next();
+}, response('adm_dependency'));
+
+enrollmentAggregateApp.get('/adm_dependency_detailed', (req, res, next) => {
+    req.result = []
+
+    for (let i = 1; i <= 9; i++) {
+        req.result.push({
+            id: i, name: id2str.admDependencyPriv(i)
+        });
+    }
+    next();
+}, response('adm_dependency_detailed'));
+
+enrollmentAggregateApp.get('/education_level_mod', (req, res, next) => {
+    req.result = []
+
+    for (let i = 1; i <= 13; i++) {
+        req.result.push({
+            id: i, name: id2str.educationLevelMod(i)
+        });
+    }
+    next();
+}, response('education_level_mod'));
+
+enrollmentAggregateApp.get('/integral_time', (req, res, next) => {
+    req.result = []
+
+    for (let i = 0; i <= 3; i++) {
+        req.result.push({
+            id: i, name: id2str.integralTime(i)
+        });
+    }
+    next();
+}, response('education_level_mod')); 
+
+enrollmentAggregateApp.get('/location', (req, res, next) => {
+    req.result = []
+
+    for (let i = 1; i <= 2; i++) {
+        req.result.push({
+            id: i, name: id2str.location(i)
+        });
+    }
+    next();
+}, response('location'));
+
+enrollmentAggregateApp.get('/diff_location', (req, res, next) => {
+    req.result = []
+
+    for (let i = 0; i <= 4; i++) {
+        req.result.push({
+            id: i, name: id2str.diffLocation(i)
+        });
+    }
+
+    req.result.push({
+        id: 8, name: 'Área onde se localizam povos e comunidades tradicionais'
+    })
+
+    next();
+}, response('diff_location'));
+
+enrollmentAggregateApp.get('/modality_integral_time', (req, res, next) => {
+    req.result = []
+
+    for (let i = 0; i <= 7; i++) {
+        req.result.push({
+            id: i, name: id2str.educationLevelBasic(i)
+        });
+    }
+
+    next();
+}, response('modality_integral_time'));
+
+enrollmentAggregateApp.get('/gender', (req, res, next) => {
+    req.result = []
+
+    for (let i = 1; i <= 2; i++) {
+        req.result.push({
+            id: i, name: id2str.gender(i)
+        });
+    }
+
+    next();
+}, response('gender'));
+
+enrollmentAggregateApp.get('/age_range', (req, res, next) => {
+    req.result = []
+
+    for (let i = 1; i <= 7; i++) {
+        req.result.push({
+            id: i, name: id2str.ageRangeAggregate(i)
+        });
+    }
+
+    next();
+}, response('age_range'));
+
+enrollmentAggregateApp.get('/ethnic_group', (req, res, next) => {
+    req.result = []
+
+    for (let i = 0; i <= 6; i++) {
+        req.result.push({
+            id: i, name: id2str.ethnicGroup(i)
+        });
+    }
+
+    next();
+}, response('ethnic_group'));
+
+enrollmentAggregateApp.get('/period_agg', (req, res, next) => {
+    req.result = []
+
+    for (let i = 0; i <= 5; i++) {
+        req.result.push({
+            id: i, name: id2str.period(i)
+        });
+    }
+
+    next();
+}, response('period_agg'));
+
+enrollmentAggregateApp.get('/region', (req, res, next) => {
+    req.result = []
+
+    for (let i = 0; i <= 5; i++) {
+        req.result.push({
+            id: i, name: id2str.regionCode(i)
+        });
+    }
+
+    next();
+}, response('period_agg'));
+
+enrollmentAggregateApp.get('/state', (req, res, next) => {
+    req.result = []
+    for (let i = 11; i < 54; i++) {
+        if (id2str.stateName(i) !== 'Não declarada') {
+            req.result.push({
+                id: i, name: id2str.stateName(i)
+            });
+        }
+    }
+
+    next();
+}, response('state'));
+
+enrollmentAggregateApp.get('/especial_education', (req, res, next) => {
+    req.result = []
+
+    for (let i = 1; i <= 2; i++) {
+        req.result.push({
+            id: i, name: id2str.especialEducation(i)
+        });
+    }
+
+    next();
+}, response('especial_education'));
+
+
 rqf.addField({
     name: 'filter',
     field: false,
@@ -299,6 +475,16 @@ rqf.addField({
         type: 'integer',
         field: 'localizacao_id'
     }
+}).addValue({
+    name: 'diff_location',
+    table: 'escola',
+    tableField: 'localizacao_diferenciada_par',
+    resultField: 'diff_location_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'localizacao_diferenciada_par'
+    }
 });
 
 // Return all cities
@@ -356,7 +542,6 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
         .order('escola.ano_censo');
     }
     else if (req.query.dims && req.query.dims.includes('integral_time_agg')) {
-
         req.sql.from('turma,escola')
         .field('SUM(CASE WHEN turma.tempo_integral=0 then turma.num_matricula ELSE 0 END)', 'total_int_nao')
         .field('SUM(CASE WHEN turma.tempo_integral=1 then turma.num_matricula ELSE 0 END)', 'total_int')
@@ -367,7 +552,6 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
         .where('turma.tipo_atendimento_id <= 2 and turma.escola_id = escola.id and turma.ano_censo = escola.ano_censo');
     }
     else if (req.query.dims && req.query.dims.includes('period_agg')) {
-
         req.sql.from('turma,escola')
         .field('SUM(CASE WHEN turma.turma_turno_id=1 then turma.num_matricula ELSE 0 END)', 'total_qt_mat_bas_matutino')
         .field('SUM(CASE WHEN turma.turma_turno_id=2 then turma.num_matricula ELSE 0 END)', 'total_qt_mat_bas_vespertino')
@@ -380,7 +564,6 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
         .where('turma.tipo_atendimento_id <= 2 and turma.escola_id = escola.id and turma.ano_censo = escola.ano_censo');
     }
     else if (req.query.dims && req.query.dims.includes('modality_integral_time')) {
-
         req.sql.from('escola')
         .field('SUM(escola.qt_mat_inf_cre_int)', 'total_qt_mat_inf_cre_int')
         .field('SUM(escola.qt_mat_inf_pre_int)', 'total_qt_mat_inf_pre_int')
@@ -391,6 +574,14 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
         .group('escola.ano_censo')
         .order('escola.ano_censo')
     }
+    else if (req.query.dims && req.query.dims.includes('especial_education')) {
+        req.sql.from('escola')
+        .field('SUM(escola.qt_mat_esp_cc)', 'total_qt_mat_esp_cc')
+        .field('SUM(escola.qt_mat_esp_ce)', 'total_qt_mat_esp_ce')
+        .field('escola.ano_censo', 'year')
+        .group('escola.ano_censo')
+        .order('escola.ano_censo')
+    }
     else {
         req.sql.from('escola')
         .field('SUM(escola.qt_mat_bas)', 'total')
@@ -399,6 +590,6 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
         .order('escola.ano_censo');
     }
     next();
-}, query, aggregateData, response('enrollment_aggregate'));
+}, query, aggregateData, id2str.transform(false), response('enrollment_aggregate'));
 
 module.exports = enrollmentAggregateApp;
-- 
GitLab


From 56fdb6d210ecda66c088b1f2c1605f0d7bb25545 Mon Sep 17 00:00:00 2001
From: Lewis <lgtg20@inf.ufpr.br>
Date: Fri, 2 Aug 2024 00:36:22 -0300
Subject: [PATCH 21/37] fix split problem

---
 src/libs/middlewares/aggregateData.js | 67 ++++++++++++++-------------
 1 file changed, 34 insertions(+), 33 deletions(-)

diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js
index a721bb1b..73fb93a7 100644
--- a/src/libs/middlewares/aggregateData.js
+++ b/src/libs/middlewares/aggregateData.js
@@ -20,43 +20,44 @@ const convert = {
 }
 
 function aggregateData(req, res, next) {
-    const newResult = []
-    const aggregateFields = ['gender', 'age_range', 'ethnic_group', 'education_level_mod_agg', 'integral_time_agg', 'period_agg', 'modality_integral_time', 'especial_education']
-    let id;
-    const fields = req.query.dims.split(',');
-    let currentAggregateField;
-    let currentNonAggregateField;
-
-    // Verifica se o filtro passado está presente nos filtros agregados
-    fields.forEach(field => {if (aggregateFields.includes(field)) currentAggregateField = field; else currentNonAggregateField = field});
-    console.log(convert[currentAggregateField])
-    if (currentAggregateField) {
-        req.result.forEach((r) => {
-            // Alguns filtros começam com o id = 0 outros id = 1
-            id = ['ethnic_group', 'integral_time_agg'].includes(currentAggregateField) ? 0 : 1;
-            for (const property in r) {
-                // Dados agregados são identificados com a substring "total_" em sua chave
-                if (property.includes("total_")) {
-                    let data = {
-                        total: r[property],
-                        year: r.year,
-                        [`${currentAggregateField}_id`]: id,
-                        [`${currentAggregateField}_name`]: id2str[convert[currentAggregateField]](id)
-                    }
+    if (req.query.dims) {
+        const newResult = []
+        const aggregateFields = ['gender', 'age_range', 'ethnic_group', 'education_level_mod_agg', 'integral_time_agg', 'period_agg', 'modality_integral_time', 'especial_education']
+        let id;
+        const fields = req.query.dims.split(',');
+        let currentAggregateField;
+        let currentNonAggregateField;
     
-                    if (currentNonAggregateField) {
-                        data[`${currentNonAggregateField}_id`] = r[`${currentNonAggregateField}_id`];
-                        data[`${currentNonAggregateField}_name`] = id2str[convert[currentNonAggregateField]](r[`${currentNonAggregateField}_id`]);
+        // Verifica se o filtro passado está presente nos filtros agregados
+        fields.forEach(field => {if (aggregateFields.includes(field)) currentAggregateField = field; else currentNonAggregateField = field});
+        console.log(convert[currentAggregateField])
+        if (currentAggregateField) {
+            req.result.forEach((r) => {
+                // Alguns filtros começam com o id = 0 outros id = 1
+                id = ['ethnic_group', 'integral_time_agg'].includes(currentAggregateField) ? 0 : 1;
+                for (const property in r) {
+                    // Dados agregados são identificados com a substring "total_" em sua chave
+                    if (property.includes("total_")) {
+                        let data = {
+                            total: r[property],
+                            year: r.year,
+                            [`${currentAggregateField}_id`]: id,
+                            [`${currentAggregateField}_name`]: id2str[convert[currentAggregateField]](id)
+                        }
+        
+                        if (currentNonAggregateField) {
+                            data[`${currentNonAggregateField}_id`] = r[`${currentNonAggregateField}_id`];
+                            data[`${currentNonAggregateField}_name`] = id2str[convert[currentNonAggregateField]](r[`${currentNonAggregateField}_id`]);
+                        }
+        
+                        newResult.push(data)
+                        ++id;
                     }
-    
-                    newResult.push(data)
-                    ++id;
                 }
-            }
-        })
-        req.result = newResult;
+            })
+            req.result = newResult;
+        }
     }
-    console.log(req.result);
     next();
 }
 
-- 
GitLab


From c6553bc17f35397d63567538797647125e01ff4d Mon Sep 17 00:00:00 2001
From: Lewis <lgtg20@inf.ufpr.br>
Date: Fri, 2 Aug 2024 12:28:48 -0300
Subject: [PATCH 22/37] Adds keys for non aggregate fields in the convert obj

---
 src/libs/middlewares/aggregateData.js | 31 +++++++++++++++------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js
index 73fb93a7..c20f3d55 100644
--- a/src/libs/middlewares/aggregateData.js
+++ b/src/libs/middlewares/aggregateData.js
@@ -2,21 +2,25 @@ const id2str = require(`./id2str`);
 
 /*
     Middleware que tem como função formatar dados agregados.
-    Dados agregados não podem ser "puxados" do banco de dados da mesma maneira que os dados tradicioanis, dessa maneira é
+    Dados agregados não podem ser 'puxados' do banco de dados da mesma maneira que os dados tradicioanis, dessa maneira é
     necessário formatá-los para que sigam o padrão.
 */
 
-// Faz o mapeamento dos filtros com seus respectivos "id2str"
+// Faz o mapeamento dos filtros com seus respectivos 'id2str'
 const convert = {
-    "adm_dependency_detailed": "admDependencyPriv",
-    "age_range": "ageRangeAggregate",
-    "gender": "gender",
-    "ethnic_group": "ethnicGroup",
-    "education_level_mod_agg": "educationLevelModAgg",
-    'integral_time_agg': 'integralTime',
-    'period_agg': 'period',
-    'modality_integral_time': 'educationLevelBasic',
-    'especial_education': 'especialEducation'
+    adm_dependency_detailed: 'admDependencyPriv',
+    location: 'location',
+    diff_location: 'diffLocation',
+    region: 'regionCode',
+    state: 'stateName',
+    age_range: 'ageRangeAggregate',
+    gender: 'gender',
+    ethnic_group: 'ethnicGroup',
+    education_level_mod_agg: 'educationLevelModAgg',
+    integral_time_agg: 'integralTime',
+    period_agg: 'period',
+    modality_integral_time: 'educationLevelBasic',
+    especial_education: 'especialEducation'
 }
 
 function aggregateData(req, res, next) {
@@ -30,14 +34,13 @@ function aggregateData(req, res, next) {
     
         // Verifica se o filtro passado está presente nos filtros agregados
         fields.forEach(field => {if (aggregateFields.includes(field)) currentAggregateField = field; else currentNonAggregateField = field});
-        console.log(convert[currentAggregateField])
         if (currentAggregateField) {
             req.result.forEach((r) => {
                 // Alguns filtros começam com o id = 0 outros id = 1
                 id = ['ethnic_group', 'integral_time_agg'].includes(currentAggregateField) ? 0 : 1;
                 for (const property in r) {
-                    // Dados agregados são identificados com a substring "total_" em sua chave
-                    if (property.includes("total_")) {
+                    // Dados agregados são identificados com a substring 'total_' em sua chave
+                    if (property.includes('total_')) {
                         let data = {
                             total: r[property],
                             year: r.year,
-- 
GitLab


From c2ccc44ad0b91ae222a299f2ad095cf3a4f021a8 Mon Sep 17 00:00:00 2001
From: Lewis <lgtg20@inf.ufpr.br>
Date: Fri, 2 Aug 2024 13:49:02 -0300
Subject: [PATCH 23/37] Fix filters and names

---
 ...{especialEducation.js => specialEducation.js} |  2 +-
 src/libs/middlewares/aggregateData.js            |  4 ++--
 src/libs/middlewares/id2str.js                   |  6 +++---
 src/libs/routes_v1/enrollmentAggregate.js        | 16 ++++++++--------
 4 files changed, 14 insertions(+), 14 deletions(-)
 rename src/libs/convert/{especialEducation.js => specialEducation.js} (95%)

diff --git a/src/libs/convert/especialEducation.js b/src/libs/convert/specialEducation.js
similarity index 95%
rename from src/libs/convert/especialEducation.js
rename to src/libs/convert/specialEducation.js
index 46349784..aac420d2 100644
--- a/src/libs/convert/especialEducation.js
+++ b/src/libs/convert/specialEducation.js
@@ -18,7 +18,7 @@ You should have received a copy of the GNU General Public License
 along with simcaq-node.  If not, see <https://www.gnu.org/licenses/>.
 */
 
-module.exports = function especialEducation(id) {
+module.exports = function specialEducation(id) {
     switch (id) {
         case 1:
         return 'Inclusiva';
diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js
index c20f3d55..714830df 100644
--- a/src/libs/middlewares/aggregateData.js
+++ b/src/libs/middlewares/aggregateData.js
@@ -20,13 +20,13 @@ const convert = {
     integral_time_agg: 'integralTime',
     period_agg: 'period',
     modality_integral_time: 'educationLevelBasic',
-    especial_education: 'especialEducation'
+    special_education: 'specialEducation'
 }
 
 function aggregateData(req, res, next) {
     if (req.query.dims) {
         const newResult = []
-        const aggregateFields = ['gender', 'age_range', 'ethnic_group', 'education_level_mod_agg', 'integral_time_agg', 'period_agg', 'modality_integral_time', 'especial_education']
+        const aggregateFields = ['gender', 'age_range', 'ethnic_group', 'education_level_mod_agg', 'integral_time_agg', 'period_agg', 'modality_integral_time', 'special_education']
         let id;
         const fields = req.query.dims.split(',');
         let currentAggregateField;
diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js
index 06f24488..1d7b3de4 100644
--- a/src/libs/middlewares/id2str.js
+++ b/src/libs/middlewares/id2str.js
@@ -116,7 +116,7 @@ const metroCode =  require(`${libs}/convert/metroCode`);
 const modalityShift = require(`${libs}/convert/modalityShift`);
 const incomeRange = require(`${libs}/convert/incomeRange`);
 const ageRangeAggregate = require(`${libs}/convert/ageRangeAggregate`);
-const especialEducation = require(`${libs}/convert/especialEducation`);
+const specialEducation = require(`${libs}/convert/specialEducation`);
 
 const ids = {
     gender_id: gender,
@@ -226,7 +226,7 @@ const ids = {
     metro_code_id: metroCode,
     modality_shift_id: modalityShift,
     income_range_id: incomeRange,
-    especial_education: especialEducation
+    special_education: specialEducation
 };
 
 function transform(removeId=false) {
@@ -358,5 +358,5 @@ module.exports = {
     metroCode,
     modalityShift,
     incomeRange,
-    especialEducation
+    specialEducation
 };
diff --git a/src/libs/routes_v1/enrollmentAggregate.js b/src/libs/routes_v1/enrollmentAggregate.js
index e7de586c..d266d240 100644
--- a/src/libs/routes_v1/enrollmentAggregate.js
+++ b/src/libs/routes_v1/enrollmentAggregate.js
@@ -78,7 +78,7 @@ enrollmentAggregateApp.get('/adm_dependency_detailed', (req, res, next) => {
     next();
 }, response('adm_dependency_detailed'));
 
-enrollmentAggregateApp.get('/education_level_mod', (req, res, next) => {
+enrollmentAggregateApp.get('/education_level_mod_agg', (req, res, next) => {
     req.result = []
 
     for (let i = 1; i <= 13; i++) {
@@ -87,9 +87,9 @@ enrollmentAggregateApp.get('/education_level_mod', (req, res, next) => {
         });
     }
     next();
-}, response('education_level_mod'));
+}, response('education_level_mod_agg'));
 
-enrollmentAggregateApp.get('/integral_time', (req, res, next) => {
+enrollmentAggregateApp.get('/integral_time_agg', (req, res, next) => {
     req.result = []
 
     for (let i = 0; i <= 3; i++) {
@@ -98,7 +98,7 @@ enrollmentAggregateApp.get('/integral_time', (req, res, next) => {
         });
     }
     next();
-}, response('education_level_mod')); 
+}, response('integral_time_agg')); 
 
 enrollmentAggregateApp.get('/location', (req, res, next) => {
     req.result = []
@@ -212,17 +212,17 @@ enrollmentAggregateApp.get('/state', (req, res, next) => {
     next();
 }, response('state'));
 
-enrollmentAggregateApp.get('/especial_education', (req, res, next) => {
+enrollmentAggregateApp.get('/special_education', (req, res, next) => {
     req.result = []
 
     for (let i = 1; i <= 2; i++) {
         req.result.push({
-            id: i, name: id2str.especialEducation(i)
+            id: i, name: id2str.specialEducation(i)
         });
     }
 
     next();
-}, response('especial_education'));
+}, response('special_education'));
 
 
 rqf.addField({
@@ -574,7 +574,7 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
         .group('escola.ano_censo')
         .order('escola.ano_censo')
     }
-    else if (req.query.dims && req.query.dims.includes('especial_education')) {
+    else if (req.query.dims && req.query.dims.includes('special_education')) {
         req.sql.from('escola')
         .field('SUM(escola.qt_mat_esp_cc)', 'total_qt_mat_esp_cc')
         .field('SUM(escola.qt_mat_esp_ce)', 'total_qt_mat_esp_ce')
-- 
GitLab


From 96a81833ae481019732dbce0b4e10f5f0ddcac99 Mon Sep 17 00:00:00 2001
From: fgs21 <fgs21@inf.ufpr.br>
Date: Wed, 7 Aug 2024 10:35:23 -0300
Subject: [PATCH 24/37] [FIX] Copying the original object to save its
 dimensions

---
 src/libs/routes_v1/rateSchoolNew.js | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index 4b76e5ee..bf8719e5 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -234,11 +234,11 @@ function matchQueries(attendsSchoolObj, populationObj) {
     let match = [];
 
     for (let i = 0; i < attendsSchoolObj.length; i++) {
-        let newObj = {};
+        let newObj = attendsSchoolObj;
 
         newObj.total = (attendsSchoolObj[i].total / populationObj[i].total) * 100;
-        newObj.faixa_etaria = attendsSchoolObj[i].faixa_etaria;
-        newObj.year = attendsSchoolObj[i].year;
+        //newObj.faixa_etaria = attendsSchoolObj[i].faixa_etaria;
+        //newObj.year = attendsSchoolObj[i].year;
 
         match.push(newObj);
     }
-- 
GitLab


From adb07050df0b3d50c57ea9eedcea6a51615afd5f Mon Sep 17 00:00:00 2001
From: fgs21 <fgs21@inf.ufpr.br>
Date: Wed, 7 Aug 2024 10:47:01 -0300
Subject: [PATCH 25/37] [FIX] Cloning the right object

---
 src/libs/routes_v1/rateSchoolNew.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index bf8719e5..b2fbf5cb 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -234,7 +234,7 @@ function matchQueries(attendsSchoolObj, populationObj) {
     let match = [];
 
     for (let i = 0; i < attendsSchoolObj.length; i++) {
-        let newObj = attendsSchoolObj;
+        let newObj = attendsSchoolObj[i];
 
         newObj.total = (attendsSchoolObj[i].total / populationObj[i].total) * 100;
         //newObj.faixa_etaria = attendsSchoolObj[i].faixa_etaria;
-- 
GitLab


From 480af7a80f5d329603b4e8f48e403d8474ab31d3 Mon Sep 17 00:00:00 2001
From: fgs21 <fgs21@inf.ufpr.br>
Date: Wed, 7 Aug 2024 11:33:34 -0300
Subject: [PATCH 26/37] [FIX] Switching the order by order in the first
 requests

---
 src/libs/routes_v1/rateSchoolNew.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index b2fbf5cb..bad8e3ae 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -257,8 +257,8 @@ rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
     .where('pnad_novo.ano_ref >= 2019 AND frequenta_escola = 1')
     .group('pnad_novo.ano_ref')
     .group('pnad_novo.faixa_etaria')
-    .order('pnad_novo.ano_ref')
     .order('pnad_novo.faixa_etaria')
+    .order('pnad_novo.ano_ref')
     req.querySet.push(attends_school);
 
     let full_population = req.sql.clone();
@@ -269,8 +269,8 @@ rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
     .where('pnad_novo.ano_ref >= 2019')
     .group('pnad_novo.ano_ref')
     .group('pnad_novo.faixa_etaria')
-    .order('pnad_novo.ano_ref')
     .order('pnad_novo.faixa_etaria')
+    .order('pnad_novo.ano_ref')
     req.querySet.push(full_population);
 
     next();
-- 
GitLab


From 5cf13d89c7492b7b8034e0cb1dd8f5379d51c8d5 Mon Sep 17 00:00:00 2001
From: fgs21 <fgs21@inf.ufpr.br>
Date: Fri, 9 Aug 2024 10:27:41 -0300
Subject: [PATCH 27/37] [FIX] Limiting the age range possibilities

---
 src/libs/routes_v1/rateSchoolNew.js | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index bad8e3ae..9673ed11 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -255,6 +255,7 @@ rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
     .field('pnad_novo.faixa_etaria')
     .field('pnad_novo.ano_ref', 'year')
     .where('pnad_novo.ano_ref >= 2019 AND frequenta_escola = 1')
+    .where('pnad_novo.faixa_etaria < 7')
     .group('pnad_novo.ano_ref')
     .group('pnad_novo.faixa_etaria')
     .order('pnad_novo.faixa_etaria')
@@ -267,6 +268,7 @@ rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
     .field('pnad_novo.faixa_etaria')
     .field('pnad_novo.ano_ref', 'year')
     .where('pnad_novo.ano_ref >= 2019')
+    .where('pnad_novo.faixa_etaria < 7')
     .group('pnad_novo.ano_ref')
     .group('pnad_novo.faixa_etaria')
     .order('pnad_novo.faixa_etaria')
-- 
GitLab


From 3ec7d063035463599603560d13fb0c64c7264341 Mon Sep 17 00:00:00 2001
From: fgs21 <fgs21@inf.ufpr.br>
Date: Fri, 9 Aug 2024 10:45:17 -0300
Subject: [PATCH 28/37] [ADD] Adding income_range filter/dimension

---
 src/libs/routes_v1/rateSchoolNew.js | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index 9673ed11..7aa52500 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -197,6 +197,16 @@ rqf.addField({
         type: 'integer',
         field: 'ano_ref'
     }
+}).addValue({
+    name: 'income_range',
+    table: 'pnad_novo',
+    tableField: 'faixa_rendimento_aux',
+    resultField: 'income_range_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'faixa_rendimento_aux'
+    }
 }).addField({
     name: 'search',
     field: false,
-- 
GitLab


From d737e28fe19d98526c5a6e958fb55c586d7eeb4b Mon Sep 17 00:00:00 2001
From: fgs21 <fgs21@inf.ufpr.br>
Date: Fri, 9 Aug 2024 11:12:19 -0300
Subject: [PATCH 29/37] [ADD] Route almost ready, some tests needed. Comments
 added and filters that were not used were removed

---
 src/libs/routes_v1/rateSchoolNew.js | 50 ++++-------------------------
 1 file changed, 7 insertions(+), 43 deletions(-)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index 7aa52500..fcfeaa13 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -97,16 +97,6 @@ rqf.addField({
         foreign: 'cod_uf',
         foreignTable: 'pnad_novo'
     }
-}).addValue({
-    name: 'attends_school',
-    table: 'pnad_novo',
-    tableField: 'frequenta_escola',
-    resultField: 'attends_school_id',
-    where: {
-        relation: '=',
-        type: 'integer',
-        field: 'frequenta_escola'
-    }
 }).addValue({
     name: 'bolsa_familia',
     table: 'pnad_novo',
@@ -207,39 +197,9 @@ rqf.addField({
         type: 'integer',
         field: 'faixa_rendimento_aux'
     }
-}).addField({
-    name: 'search',
-    field: false,
-    where: true
-}).addValueToField({
-    name: 'name',
-    table: 'pnad_novo',
-    tableField: 'nome',
-    where: {
-        relation: 'LIKE',
-        type: 'string',
-        field: 'nome'
-    }
-}, 'search').addValue({
-    name: 'mesoregion',
-    table: 'pnad_novo',
-    tableField: 'mesorregiao_id',
-    where: {
-        relation: '=',
-        type: 'integer',
-        field: 'mesorregiao_id'
-    }
-}).addValue({
-    name: 'microregion',
-    table: 'pnad_novo',
-    tableField: 'microrregiao_id',
-    where: {
-        relation: '=',
-        type: 'integer',
-        field: 'microrregiao_id'
-    }
 });
 
+// The queries are matched and the total is calculated
 function matchQueries(attendsSchoolObj, populationObj) {
     let match = [];
 
@@ -247,8 +207,6 @@ function matchQueries(attendsSchoolObj, populationObj) {
         let newObj = attendsSchoolObj[i];
 
         newObj.total = (attendsSchoolObj[i].total / populationObj[i].total) * 100;
-        //newObj.faixa_etaria = attendsSchoolObj[i].faixa_etaria;
-        //newObj.year = attendsSchoolObj[i].year;
 
         match.push(newObj);
     }
@@ -257,8 +215,11 @@ function matchQueries(attendsSchoolObj, populationObj) {
 }
 
 rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
+    // As we will need to do two requests, they'll be stored in a list
     req.querySet = []
     
+    // Create an object that will store the first request (the sum of all people that attend school)
+    // and are below a certain age (in this case, 24 yeas)
     let attends_school = req.sql.clone();
     attends_school.from('pnad_novo')
     .field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total')
@@ -272,6 +233,7 @@ rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
     .order('pnad_novo.ano_ref')
     req.querySet.push(attends_school);
 
+    // Then, the second object is created and stores the sum of all people below a certain age (24 years)
     let full_population = req.sql.clone();
     full_population.from('pnad_novo')
     .field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total')
@@ -288,6 +250,8 @@ rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
     next();
 }, multiQuery, (req, res, next) => {
     
+    // The multiple requests are made. Then we need to calculate the percetange. So the function
+    // below is used
     let newObj = matchQueries(req.result[0], req.result[1]);
     req.result = newObj;
 
-- 
GitLab


From 9924c5ed0003373f9e63707e74c7f032acc2c6fe Mon Sep 17 00:00:00 2001
From: fgs21 <fgs21@inf.ufpr.br>
Date: Mon, 12 Aug 2024 11:43:50 -0300
Subject: [PATCH 30/37] [FIX] Changing 'faixa_etaria' filter to 'age_range_id'

---
 src/libs/routes_v1/rateSchoolNew.js | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index fcfeaa13..0b20900a 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -118,10 +118,10 @@ rqf.addField({
         field: 'cor_raca'
     }
 }).addValue({
-    name: 'age_range_all',
+    name: 'age_range',
     table: 'pnad_novo',
     tableField: 'faixa_etaria',
-    resultField: 'age_range_all_id',
+    resultField: 'age_range_id',
     where: {
         relation: '=',
         type: 'integer',
@@ -208,6 +208,9 @@ function matchQueries(attendsSchoolObj, populationObj) {
 
         newObj.total = (attendsSchoolObj[i].total / populationObj[i].total) * 100;
 
+        newObj.age_range_id = newObj.faixa_etaria;
+        delete newObj.faixa_etaria;
+
         match.push(newObj);
     }
 
-- 
GitLab


From 986c7ecb418245a250419665f272fc185c3ed6d4 Mon Sep 17 00:00:00 2001
From: fgs21 <fgs21@inf.ufpr.br>
Date: Tue, 13 Aug 2024 10:13:58 -0300
Subject: [PATCH 31/37] [ADD] Filters route options added

---
 src/libs/routes_v1/rateSchoolNew.js | 85 +++++++++++++++++++++++++++++
 1 file changed, 85 insertions(+)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index 0b20900a..7e1bb60b 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -45,9 +45,94 @@ rateSchoolNewApp.use(cache('15 day'));
 rateSchoolNewApp.get('/years', (req, res, next) => {
     req.sql.from('pnad_novo')
     .field('DISTINCT pnad_novo.ano_ref', 'year')
+    .where('pnad_novo.ano_ref> 2018')
     next();
 }, query, response('years'));
 
+PnadNovoApp.get('/region', (req, res, next) => {
+    req.result = []
+    for (let i = 1; i < 6; i++) {
+        req.result.push({
+            id: i, name: id2str.regionCode(i)
+        });
+    }
+
+    next();
+}, response('region'));
+
+PnadNovoApp.get('/cap_code', (req, res, next) => {
+    req.result = []
+    for (let i = 11; i < 54; i++) {
+        if (id2str.capitalCode(i) !== 'Não informado') {
+        req.result.push({
+            id: i, name: id2str.capitalCode(i)
+        });
+        }
+    }
+    req.result.push({id: 99, name: id2str.capitalCode(99)});
+
+    next();
+}, response('cap_code'));
+
+PnadNovoApp.get('/metro_code', (req, res, next) => {
+    req.result = []
+    for (let i = 13; i < 53; i++) {
+        if (id2str.metroCode(i) !== 'Não informado') {
+        req.result.push({
+            id: i, name: id2str.metroCode(i)
+        });
+        }
+    }
+    req.result.push({id: 99, name: id2str.metroCode(99)});
+
+    next();
+}, response('metro_code'));
+
+PnadNovoApp.get('/gender', (req, res, next) => {
+    req.result = []
+    for (let i = 1; i < 3; i++) {
+        req.result.push({
+            id: i, name: id2str.gender(i)
+        });
+    }
+    next();
+}, response('gender'));
+
+PnadNovoApp.get('/bolsa_familia', (req, res, next) => {
+    req.result = []
+    for (let i = 1; i < 3; i++) {
+        req.result.push({
+            id: i, name: id2str.attendsSchool(i)
+        });
+    }
+    req.result.push({id: 9, name: id2str.attendsSchool(9)});
+    next();
+}, response('bolsa_familia'));
+
+PnadNovoApp.get('/state', (req, res, next) => {
+    req.result = []
+    for (let i = 11; i < 54; i++) {
+        if (id2str.stateName(i) !== 'Não declarada') {
+            req.result.push({
+                id: i, name: id2str.stateName(i)
+            });
+        }
+    }
+    req.result.push({id: 99, name: id2str.stateName(99)});
+
+    next();
+}, response('state'));
+
+PnadNovoApp.get('/income_range', (req, res, next) => {
+    req.result = []
+    for (let i = 1; i < 8; i++) {
+        req.result.push({
+            id: i, name: id2str.incomeRange(i)
+        });
+    }
+    req.result.push({id: 9, name: id2str.incomeRange(9)});
+    next();
+}, response('income_range'));
 
 rqf.addField({
     name: 'filter',
-- 
GitLab


From 8d6d6985be346c708417e913bd923d42741f43f4 Mon Sep 17 00:00:00 2001
From: fgs21 <fgs21@inf.ufpr.br>
Date: Tue, 13 Aug 2024 10:26:09 -0300
Subject: [PATCH 32/37] [FIX] Route object fixed

---
 src/libs/routes_v1/rateSchoolNew.js | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index 7e1bb60b..d10fb239 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -49,7 +49,7 @@ rateSchoolNewApp.get('/years', (req, res, next) => {
     next();
 }, query, response('years'));
 
-PnadNovoApp.get('/region', (req, res, next) => {
+rateSchoolNewApp.get('/region', (req, res, next) => {
     req.result = []
     for (let i = 1; i < 6; i++) {
         req.result.push({
@@ -60,7 +60,7 @@ PnadNovoApp.get('/region', (req, res, next) => {
     next();
 }, response('region'));
 
-PnadNovoApp.get('/cap_code', (req, res, next) => {
+rateSchoolNewApp.get('/cap_code', (req, res, next) => {
     req.result = []
     for (let i = 11; i < 54; i++) {
         if (id2str.capitalCode(i) !== 'Não informado') {
@@ -74,7 +74,7 @@ PnadNovoApp.get('/cap_code', (req, res, next) => {
     next();
 }, response('cap_code'));
 
-PnadNovoApp.get('/metro_code', (req, res, next) => {
+rateSchoolNewApp.get('/metro_code', (req, res, next) => {
     req.result = []
     for (let i = 13; i < 53; i++) {
         if (id2str.metroCode(i) !== 'Não informado') {
@@ -88,7 +88,7 @@ PnadNovoApp.get('/metro_code', (req, res, next) => {
     next();
 }, response('metro_code'));
 
-PnadNovoApp.get('/gender', (req, res, next) => {
+rateSchoolNewApp.get('/gender', (req, res, next) => {
     req.result = []
     for (let i = 1; i < 3; i++) {
         req.result.push({
@@ -98,7 +98,7 @@ PnadNovoApp.get('/gender', (req, res, next) => {
     next();
 }, response('gender'));
 
-PnadNovoApp.get('/bolsa_familia', (req, res, next) => {
+rateSchoolNewApp.get('/bolsa_familia', (req, res, next) => {
     req.result = []
     for (let i = 1; i < 3; i++) {
         req.result.push({
@@ -109,7 +109,7 @@ PnadNovoApp.get('/bolsa_familia', (req, res, next) => {
     next();
 }, response('bolsa_familia'));
 
-PnadNovoApp.get('/state', (req, res, next) => {
+rateSchoolNewApp.get('/state', (req, res, next) => {
     req.result = []
     for (let i = 11; i < 54; i++) {
         if (id2str.stateName(i) !== 'Não declarada') {
@@ -123,7 +123,7 @@ PnadNovoApp.get('/state', (req, res, next) => {
     next();
 }, response('state'));
 
-PnadNovoApp.get('/income_range', (req, res, next) => {
+rateSchoolNewApp.get('/income_range', (req, res, next) => {
     req.result = []
     for (let i = 1; i < 8; i++) {
         req.result.push({
-- 
GitLab


From ca41345632ad29822148410f16610feeb0ff8e6f Mon Sep 17 00:00:00 2001
From: fgs21 <fgs21@inf.ufpr.br>
Date: Tue, 13 Aug 2024 10:57:33 -0300
Subject: [PATCH 33/37] [TEST] Trying to change the 'order by' in request

---
 src/libs/routes_v1/rateSchoolNew.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index d10fb239..74688eea 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -317,8 +317,8 @@ rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
     .where('pnad_novo.faixa_etaria < 7')
     .group('pnad_novo.ano_ref')
     .group('pnad_novo.faixa_etaria')
-    .order('pnad_novo.faixa_etaria')
     .order('pnad_novo.ano_ref')
+    .order('pnad_novo.faixa_etaria')
     req.querySet.push(attends_school);
 
     // Then, the second object is created and stores the sum of all people below a certain age (24 years)
@@ -331,8 +331,8 @@ rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
     .where('pnad_novo.faixa_etaria < 7')
     .group('pnad_novo.ano_ref')
     .group('pnad_novo.faixa_etaria')
-    .order('pnad_novo.faixa_etaria')
     .order('pnad_novo.ano_ref')
+    .order('pnad_novo.faixa_etaria')
     req.querySet.push(full_population);
 
     next();
-- 
GitLab


From b944747265b3e62e77090363e061ee6135c6c730 Mon Sep 17 00:00:00 2001
From: fgs21 <fgs21@inf.ufpr.br>
Date: Tue, 13 Aug 2024 11:29:06 -0300
Subject: [PATCH 34/37] [ADD] Age range dimension/filter is now required to use
 the indicator

---
 src/libs/routes_v1/rateSchoolNew.js | 93 ++++++++++++++++++-----------
 1 file changed, 57 insertions(+), 36 deletions(-)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index 74688eea..a35a1fca 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -134,6 +134,18 @@ rateSchoolNewApp.get('/income_range', (req, res, next) => {
     next();
 }, response('income_range'));
 
+rateSchoolNewApp.get('/age_range', (req, res, next) => {
+    req.result = [
+        {id: 1, name: '0 a 3 anos'},
+        {id: 2, name: '4 a 5 anos'},
+        {id: 3, name: '6 a 10 anos'},
+        {id: 4, name: '11 a 14 anos'},
+        {id: 5, name: '15 a 17 anos'},
+        {id: 6, name: '18 a 24 anos'}
+    ];
+    next();
+}, response('age_range'));
+
 rqf.addField({
     name: 'filter',
     field: false,
@@ -303,46 +315,55 @@ function matchQueries(attendsSchoolObj, populationObj) {
 }
 
 rateSchoolNewApp.get('/', rqf.parse(), rqf.build(),  (req, res, next) => {
-    // As we will need to do two requests, they'll be stored in a list
-    req.querySet = []
     
-    // Create an object that will store the first request (the sum of all people that attend school)
-    // and are below a certain age (in this case, 24 yeas)
-    let attends_school = req.sql.clone();
-    attends_school.from('pnad_novo')
-    .field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total')
-    .field('pnad_novo.faixa_etaria')
-    .field('pnad_novo.ano_ref', 'year')
-    .where('pnad_novo.ano_ref >= 2019 AND frequenta_escola = 1')
-    .where('pnad_novo.faixa_etaria < 7')
-    .group('pnad_novo.ano_ref')
-    .group('pnad_novo.faixa_etaria')
-    .order('pnad_novo.ano_ref')
-    .order('pnad_novo.faixa_etaria')
-    req.querySet.push(attends_school);
-
-    // Then, the second object is created and stores the sum of all people below a certain age (24 years)
-    let full_population = req.sql.clone();
-    full_population.from('pnad_novo')
-    .field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total')
-    .field('pnad_novo.faixa_etaria')
-    .field('pnad_novo.ano_ref', 'year')
-    .where('pnad_novo.ano_ref >= 2019')
-    .where('pnad_novo.faixa_etaria < 7')
-    .group('pnad_novo.ano_ref')
-    .group('pnad_novo.faixa_etaria')
-    .order('pnad_novo.ano_ref')
-    .order('pnad_novo.faixa_etaria')
-    req.querySet.push(full_population);
+    if ("age_range" in req.filter || "age_range" in req.dims) {
+        // As we will need to do two requests, they'll be stored in a list
+        req.querySet = []
+        
+        // Create an object that will store the first request (the sum of all people that attend school)
+        // and are below a certain age (in this case, 24 yeas)
+        let attends_school = req.sql.clone();
+        attends_school.from('pnad_novo')
+        .field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total')
+        .field('pnad_novo.faixa_etaria')
+        .field('pnad_novo.ano_ref', 'year')
+        .where('pnad_novo.ano_ref >= 2019 AND frequenta_escola = 1')
+        .where('pnad_novo.faixa_etaria < 7')
+        .group('pnad_novo.ano_ref')
+        .group('pnad_novo.faixa_etaria')
+        .order('pnad_novo.ano_ref')
+        .order('pnad_novo.faixa_etaria')
+        req.querySet.push(attends_school);
+
+        // Then, the second object is created and stores the sum of all people below a certain age (24 years)
+        let full_population = req.sql.clone();
+        full_population.from('pnad_novo')
+        .field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total')
+        .field('pnad_novo.faixa_etaria')
+        .field('pnad_novo.ano_ref', 'year')
+        .where('pnad_novo.ano_ref >= 2019')
+        .where('pnad_novo.faixa_etaria < 7')
+        .group('pnad_novo.ano_ref')
+        .group('pnad_novo.faixa_etaria')
+        .order('pnad_novo.ano_ref')
+        .order('pnad_novo.faixa_etaria')
+        req.querySet.push(full_population);
+    }
 
     next();
 }, multiQuery, (req, res, next) => {
-    
-    // The multiple requests are made. Then we need to calculate the percetange. So the function
-    // below is used
-    let newObj = matchQueries(req.result[0], req.result[1]);
-    req.result = newObj;
-
+    if ("age_range" in req.filter || "age_range" in req.dims) {
+        // The multiple requests are made. Then we need to calculate the percetange. So the function
+        // below is used
+        let newObj = matchQueries(req.result[0], req.result[1]);
+        req.result = newObj;
+    } else {
+        res.status(400);
+        next({
+            status: 400,
+            message: 'Wrong/No filter specified'
+        });
+    }
     next();
 }, id2str.transform(false), response('rateSchoolNew'));
 
-- 
GitLab


From 921afccba7f9e453620b0787af665976adb4ad88 Mon Sep 17 00:00:00 2001
From: fgs21 <fgs21@inf.ufpr.br>
Date: Tue, 13 Aug 2024 11:56:41 -0300
Subject: [PATCH 35/37] [ADD] Ethnic group route added

---
 src/libs/routes_v1/rateSchoolNew.js | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js
index a35a1fca..a6ae0218 100644
--- a/src/libs/routes_v1/rateSchoolNew.js
+++ b/src/libs/routes_v1/rateSchoolNew.js
@@ -123,6 +123,18 @@ rateSchoolNewApp.get('/state', (req, res, next) => {
     next();
 }, response('state'));
 
+rateSchoolNewApp.get('/new_pnad_ethnic_group', (req, res, next) => {
+    req.result = []
+    for (let i = 1; i < 6; i++) {
+        req.result.push({
+            id: i, name: id2str.ethnicGroupNewPnad(i)
+        });
+    }
+    req.result.push({id: 9, name: id2str.ethnicGroupNewPnad(9)});
+    next();
+}, response('new_pnad_ethnic_group'));
+
+
 rateSchoolNewApp.get('/income_range', (req, res, next) => {
     req.result = []
     for (let i = 1; i < 8; i++) {
-- 
GitLab


From 9ba6c0287315a5c4d86a16827ac85bb80f3af468 Mon Sep 17 00:00:00 2001
From: Lewis <lgtg20@inf.ufpr.br>
Date: Tue, 13 Aug 2024 14:43:28 -0300
Subject: [PATCH 36/37] employees aggregate

---
 src/libs/convert/educationLevelModDoc.js |  42 +++
 src/libs/convert/specialEducationDoc.js  |  31 ++
 src/libs/middlewares/aggregateData.js    |  17 +-
 src/libs/middlewares/id2str.js           |  11 +-
 src/libs/routes_v1/api.js                |   4 +
 src/libs/routes_v1/employeesAggregate.js | 414 +++++++++++++++++++++++
 6 files changed, 515 insertions(+), 4 deletions(-)
 create mode 100644 src/libs/convert/educationLevelModDoc.js
 create mode 100644 src/libs/convert/specialEducationDoc.js
 create mode 100644 src/libs/routes_v1/employeesAggregate.js

diff --git a/src/libs/convert/educationLevelModDoc.js b/src/libs/convert/educationLevelModDoc.js
new file mode 100644
index 00000000..2113df92
--- /dev/null
+++ b/src/libs/convert/educationLevelModDoc.js
@@ -0,0 +1,42 @@
+/*
+Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre
+Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
+
+This file is part of simcaq-node.
+
+simcaq-node is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+simcaq-node is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with simcaq-node.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+module.exports = function educationLevelModDoc(id) {
+    switch (id) {
+        case 1:
+        return 'Creche';
+        case 2:
+        return 'Pré-Escola';
+        case 3:
+        return 'Ensino Fundamental - anos iniciais';
+        case 4:
+        return 'Ensino Fundamental - anos finais';
+        case 5:
+        return 'Ensino Médio';
+        case 6:
+        return 'Profissional';
+        case 7:
+        return 'EJA - Ensino Fundamental';
+        case 8:
+        return 'EJA - Ensino Médio';
+        default:
+        return 'Não classificada';
+    }
+};
diff --git a/src/libs/convert/specialEducationDoc.js b/src/libs/convert/specialEducationDoc.js
new file mode 100644
index 00000000..7ec9335c
--- /dev/null
+++ b/src/libs/convert/specialEducationDoc.js
@@ -0,0 +1,31 @@
+/*
+Copyright (C) 2022 Centro de Computacao Cientifica e Software Livre
+Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
+
+This file is part of simcaq-node.
+
+simcaq-node is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+simcaq-node is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with simcaq-node.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+module.exports = function specialEducationDoc(id) {
+    switch (id) {
+        case 1:
+        return 'Classe Comum';
+        case 2:
+        return 'Classe Especial';
+        default:
+        return 'Não definido';
+    }
+};
+  
diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js
index 714830df..3ea93de3 100644
--- a/src/libs/middlewares/aggregateData.js
+++ b/src/libs/middlewares/aggregateData.js
@@ -20,13 +20,26 @@ const convert = {
     integral_time_agg: 'integralTime',
     period_agg: 'period',
     modality_integral_time: 'educationLevelBasic',
-    special_education: 'specialEducation'
+    special_education: 'specialEducation',
+    special_education_doc: 'specialEducationDoc',
+    education_level_mod_doc: 'educationLevelModDoc'
 }
 
 function aggregateData(req, res, next) {
     if (req.query.dims) {
         const newResult = []
-        const aggregateFields = ['gender', 'age_range', 'ethnic_group', 'education_level_mod_agg', 'integral_time_agg', 'period_agg', 'modality_integral_time', 'special_education']
+        const aggregateFields = [
+            'gender', 
+            'age_range', 
+            'ethnic_group', 
+            'education_level_mod_agg',
+            'education_level_mod_doc',
+            'integral_time_agg', 
+            'period_agg', 
+            'modality_integral_time', 
+            'special_education',
+            'special_education_doc'
+        ]
         let id;
         const fields = req.query.dims.split(',');
         let currentAggregateField;
diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js
index 1d7b3de4..1971d0a0 100644
--- a/src/libs/middlewares/id2str.js
+++ b/src/libs/middlewares/id2str.js
@@ -117,6 +117,9 @@ const modalityShift = require(`${libs}/convert/modalityShift`);
 const incomeRange = require(`${libs}/convert/incomeRange`);
 const ageRangeAggregate = require(`${libs}/convert/ageRangeAggregate`);
 const specialEducation = require(`${libs}/convert/specialEducation`);
+const specialEducationDoc = require(`${libs}/convert/specialEducationDoc`);
+const educationLevelModDoc = require(`${libs}/convert/educationLevelModDoc`);
+
 
 const ids = {
     gender_id: gender,
@@ -226,7 +229,9 @@ const ids = {
     metro_code_id: metroCode,
     modality_shift_id: modalityShift,
     income_range_id: incomeRange,
-    special_education: specialEducation
+    special_education: specialEducation,
+    special_education_doc: specialEducationDoc,
+    education_level_mod_doc: educationLevelModDoc
 };
 
 function transform(removeId=false) {
@@ -358,5 +363,7 @@ module.exports = {
     metroCode,
     modalityShift,
     incomeRange,
-    specialEducation
+    specialEducation,
+    specialEducationDoc,
+    educationLevelModDoc
 };
diff --git a/src/libs/routes_v1/api.js b/src/libs/routes_v1/api.js
index 17af8276..4e1d3e8e 100644
--- a/src/libs/routes_v1/api.js
+++ b/src/libs/routes_v1/api.js
@@ -145,6 +145,8 @@ const newPnad = require(`${libs}/routes_v1/newPnad`);
 
 const enrollmentAggregate = require(`${libs}/routes_v1/enrollmentAggregate`);
 
+const employeesAggregate = require(`${libs}/routes_v1/employeesAggregate`);
+
 const email = require(`${libs}/routes_v1/email`);
 
 api.get('/', (req, res) => {
@@ -208,6 +210,8 @@ api.use('/message', message);
 api.use('/course_students', courseStudents);
 api.use('/new_pnad', newPnad);
 api.use('/enrollmentAggregate', enrollmentAggregate);
+api.use('/employeesAggregate', employeesAggregate);
+
 
 //Publication 
 api.use('/publication', publication);
diff --git a/src/libs/routes_v1/employeesAggregate.js b/src/libs/routes_v1/employeesAggregate.js
new file mode 100644
index 00000000..14654df9
--- /dev/null
+++ b/src/libs/routes_v1/employeesAggregate.js
@@ -0,0 +1,414 @@
+/*
+Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre
+Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
+
+This file is part of simcaq-node.
+
+simcaq-node is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+simcaq-node is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with simcaq-node.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+const express = require('express');
+const { result } = require('lodash');
+
+const employeesAggregateApp = express.Router();
+
+const libs = `${process.cwd()}/libs`;
+
+const log = require(`${libs}/log`)(module);
+
+const squel = require('squel');
+
+const query = require(`${libs}/middlewares/query`).query;
+
+const response = require(`${libs}/middlewares/response`);
+
+const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
+
+const aggregateData = require(`${libs}/middlewares/aggregateData`);
+
+const id2str = require(`${libs}/middlewares/id2str`);
+
+const config = require(`${libs}/config`);
+
+const addMissing = require(`${libs}/middlewares/addMissing`);
+
+const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware;
+
+employeesAggregateApp.use(cache('15 day'));
+
+let rqf = new ReqQueryFields();
+
+employeesAggregateApp.get('/years', (req, res, next) => {
+    req.sql.from('escola')
+    .field('DISTINCT escola.ano_censo', 'year')
+    .where('escola.ano_censo >= 2021')
+    next();
+}, query, response('years'));
+
+employeesAggregateApp.get('/education_level_mod_doc', (req, res, next) => {
+    req.result = []
+
+    for (let i = 1; i <= 13; i++) {
+        req.result.push({
+            id: i, name: id2str.educationLevelModDoc(i)
+        });
+    }
+    next();
+}, response('education_level_mod_doc'));
+
+employeesAggregateApp.get('/region', (req, res, next) => {
+    req.result = []
+
+    for (let i = 0; i <= 5; i++) {
+        req.result.push({
+            id: i, name: id2str.regionCode(i)
+        });
+    }
+
+    next();
+}, response('period_agg'));
+
+employeesAggregateApp.get('/state', (req, res, next) => {
+    req.result = []
+    for (let i = 11; i < 54; i++) {
+        if (id2str.stateName(i) !== 'Não declarada') {
+            req.result.push({
+                id: i, name: id2str.stateName(i)
+            });
+        }
+    }
+
+    next();
+}, response('state'));
+
+employeesAggregateApp.get('/special_education_doc', (req, res, next) => {
+    req.result = []
+
+    for (let i = 1; i <= 2; i++) {
+        req.result.push({
+            id: i, name: id2str.specialEducationDoc(i)
+        });
+    }
+
+    next();
+}, response('special_education_doc'));
+
+
+rqf.addField({
+    name: 'filter',
+    field: false,
+    where: true
+}).addField({
+    name: 'dims',
+    field: true,
+    where: false
+}).addValue({
+    name: 'adm_dependency',
+    table: 'escola',
+    tableField: 'dependencia_adm_id',
+    resultField: 'adm_dependency_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'dependencia_adm_id'
+    }
+}).addValue({
+    name: 'adm_dependency_detailed',
+    table: 'escola',
+    tableField: 'dependencia_adm_priv',
+    resultField: 'adm_dependency_detailed_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'dependencia_adm_priv'
+    }
+}).addValue({
+    name: 'education_level_mod',
+    table: 'escola',
+    tableField: 'etapas_mod_ensino_segmento_id',
+    resultField: 'education_level_mod_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'etapas_mod_ensino_segmento_id'
+    }
+}).addValue({
+    name:'integral_time',
+    table: 'escola',
+    tableField: 'tempo_integral',
+    resultField: 'integral_time_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'tempo_integral'
+    }
+  }).addValue({
+    name: 'education_level_short',
+    table: 'escola',
+    tableField: 'etapa_resumida',
+    resultField: 'education_level_short_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'etapa_resumida'
+    }
+}).addValue({
+    name: 'region',
+    table: 'regiao',
+    tableField: ['nome', 'id'],
+    resultField: ['region_name', 'region_id'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'regiao_id',
+        foreignTable: 'escola'
+    }
+}).addValue({
+    name: 'mesoregion',
+    table: 'municipio',
+    tableField: ['nome_mesorregiao', 'mesorregiao_id'],
+    resultField: ['mesoregion_name', 'mesoregion_id'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'mesorregiao_id',
+        table: 'municipio'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'municipio_id',
+        foreignTable: 'escola'
+    }
+}).addValue({
+    name: 'microregion',
+    table: 'municipio',
+    tableField: ['nome_microrregiao', 'microrregiao_id'],
+    resultField: ['microregion_name', 'microregion_id'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'microrregiao_id',
+        table: 'municipio'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'municipio_id',
+        foreignTable: 'escola'
+    }
+}).addValue({
+    name: 'min_year',
+    table: 'escola',
+    tableField: 'ano_censo',
+    resultField: 'year',
+    where: {
+        relation: '>=',
+        type: 'integer',
+        field: 'ano_censo',
+    },
+}).addValue({
+    name: 'max_year',
+    table: 'escola',
+    tableField: 'ano_censo',
+    resultField: 'year',
+    where: {
+        relation: '<=',
+        type: 'integer',
+        field: 'ano_censo',
+    },
+}).addValueToField({
+    name: 'state',
+    table: 'estado',
+    tableField: ['nome', 'id'],
+    resultField: ['state_name', 'state_id'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'estado_id',
+        foreignTable: 'escola'
+    }
+}, 'dims').addValueToField({
+    name: 'state',
+    table: 'estado',
+    tableField: 'nome',
+    resultField: 'state_name',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'estado_id',
+        foreignTable: 'escola'
+    }
+}, 'filter').addValueToField({
+    name: 'city',
+    table: 'municipio',
+    tableField: ['nome', 'id'],
+    resultField: ['city_name', 'city_id'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'municipio_id',
+        foreignTable: 'escola'
+    }
+}, 'dims').addValueToField({
+    name: 'city',
+    table: 'municipio',
+    tableField: 'nome',
+    resultField: 'city_name',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'municipio_id',
+        foreignTable: 'escola'
+    }
+}, 'filter').addValueToField({
+    name: 'school',
+    table: 'escola',
+    tableField: ['nome_escola', 'id'],
+    resultField: ['school_name', 'school_id'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    },
+    join: {
+        primary: ['id', 'ano_censo'],
+        foreign: ['escola_id', 'ano_censo'],
+        foreignTable: 'escola'
+    }
+}, 'dims').addValueToField({
+    name: 'locale_id',
+    table: 'escola',
+    tableField: 'localizacao_id',
+    resultField: 'locale_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'localizacao_id'
+    }
+}, 'dims').addValueToField({
+    name: 'school_id',
+    table: 'escola',
+    tableField: 'id',
+    resultField: 'school_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    },
+    join: {
+        primary: ['id', 'ano_censo'],
+        foreign: ['escola_id', 'ano_censo'],
+        foreignTable: 'escola'
+    }
+}, 'dims').addValueToField({
+    name: 'school',
+    table: 'escola',
+    tableField: 'nome_escola',
+    resultField: 'school_name',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    },
+    join: {
+        primary: ['id', 'ano_censo'],
+        foreign: ['escola_id', 'ano_censo'],
+        foreignTable: 'escola'
+    }
+}, 'filter').addValue({
+    name: 'location',
+    table: 'escola',
+    tableField: 'localizacao_id',
+    resultField: 'location_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'localizacao_id'
+    }
+}).addValue({
+    name: 'diff_location',
+    table: 'escola',
+    tableField: 'localizacao_diferenciada_par',
+    resultField: 'diff_location_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'localizacao_diferenciada_par'
+    }
+});
+
+// Return all cities
+employeesAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
+
+    if (req.query.filter && !req.query.filter.includes('school'))
+        return;
+
+    if (req.query.filter == undefined)
+        return;
+
+    if (req.query.dims && req.query.dims.includes('education_level_mod_doc')) {
+        req.sql.from('escola')
+        .field('SUM(escola.qt_doc_inf_cre)', 'total_cre')
+        .field('SUM(escola.qt_doc_inf_pre)', 'total_pre')
+        .field('SUM(escola.qt_doc_fund_ai)', 'total_fund_ai')
+        .field('SUM(escola.qt_doc_fund_af)', 'total_fund_af')
+        .field('SUM(escola.qt_doc_med)', 'total_med')
+        .field('SUM(escola.qt_doc_prof)', 'total_prof')
+        .field('SUM(escola.qt_doc_eja_fund)', 'total_eja_fund')
+        .field('SUM(escola.qt_doc_eja_med)', 'total_eja_med')
+        .field('escola.ano_censo', 'year')
+        .group('escola.ano_censo')
+        .order('escola.ano_censo')
+        .where('escola.situacao_funcionamento_pareada = 1 and (escola.ensino_regular = 1 or escola.ensino_eja = 1 or escola.educacao_profissional = 1)');
+    }
+    else if (req.query.dims && req.query.dims.includes('special_education_doc')) {
+        req.sql.from('escola')
+        .field('SUM(escola.qt_doc_esp_cc)', 'total_esp_cc')
+        .field('SUM(escola.qt_doc_esp_ce)', 'total_esp_ce')
+        .field('escola.ano_censo', 'year')
+        .group('escola.ano_censo')
+        .order('escola.ano_censo')
+        .where('escola.situacao_funcionamento_pareada = 1 and (escola.ensino_regular = 1 or escola.ensino_eja = 1 or escola.educacao_profissional = 1)');
+    }
+    else {
+        req.sql.from('escola')
+        .field('SUM(escola.qt_doc_bas)', 'total')
+        .field('escola.ano_censo', 'year')
+        .group('escola.ano_censo')
+        .order('escola.ano_censo')
+        .where('escola.situacao_funcionamento_pareada = 1 and (escola.ensino_regular = 1 or escola.ensino_eja = 1 or escola.educacao_profissional = 1)');
+    }
+    next();
+}, query, aggregateData, id2str.transform(false), response('enrollment_aggregate'));
+
+module.exports = employeesAggregateApp;
-- 
GitLab


From 113dd143fcbf0e1648a5861284dde7d25dae90d6 Mon Sep 17 00:00:00 2001
From: Lewis <lgtg20@inf.ufpr.br>
Date: Wed, 14 Aug 2024 12:46:53 -0300
Subject: [PATCH 37/37] Working

---
 src/libs/routes_v1/employeesAggregate.js | 108 ++---------------------
 1 file changed, 5 insertions(+), 103 deletions(-)

diff --git a/src/libs/routes_v1/employeesAggregate.js b/src/libs/routes_v1/employeesAggregate.js
index 14654df9..ab5102ce 100644
--- a/src/libs/routes_v1/employeesAggregate.js
+++ b/src/libs/routes_v1/employeesAggregate.js
@@ -59,7 +59,7 @@ employeesAggregateApp.get('/years', (req, res, next) => {
 employeesAggregateApp.get('/education_level_mod_doc', (req, res, next) => {
     req.result = []
 
-    for (let i = 1; i <= 13; i++) {
+    for (let i = 1; i <= 8; i++) {
         req.result.push({
             id: i, name: id2str.educationLevelModDoc(i)
         });
@@ -67,31 +67,6 @@ employeesAggregateApp.get('/education_level_mod_doc', (req, res, next) => {
     next();
 }, response('education_level_mod_doc'));
 
-employeesAggregateApp.get('/region', (req, res, next) => {
-    req.result = []
-
-    for (let i = 0; i <= 5; i++) {
-        req.result.push({
-            id: i, name: id2str.regionCode(i)
-        });
-    }
-
-    next();
-}, response('period_agg'));
-
-employeesAggregateApp.get('/state', (req, res, next) => {
-    req.result = []
-    for (let i = 11; i < 54; i++) {
-        if (id2str.stateName(i) !== 'Não declarada') {
-            req.result.push({
-                id: i, name: id2str.stateName(i)
-            });
-        }
-    }
-
-    next();
-}, response('state'));
-
 employeesAggregateApp.get('/special_education_doc', (req, res, next) => {
     req.result = []
 
@@ -113,56 +88,6 @@ rqf.addField({
     name: 'dims',
     field: true,
     where: false
-}).addValue({
-    name: 'adm_dependency',
-    table: 'escola',
-    tableField: 'dependencia_adm_id',
-    resultField: 'adm_dependency_id',
-    where: {
-        relation: '=',
-        type: 'integer',
-        field: 'dependencia_adm_id'
-    }
-}).addValue({
-    name: 'adm_dependency_detailed',
-    table: 'escola',
-    tableField: 'dependencia_adm_priv',
-    resultField: 'adm_dependency_detailed_id',
-    where: {
-        relation: '=',
-        type: 'integer',
-        field: 'dependencia_adm_priv'
-    }
-}).addValue({
-    name: 'education_level_mod',
-    table: 'escola',
-    tableField: 'etapas_mod_ensino_segmento_id',
-    resultField: 'education_level_mod_id',
-    where: {
-        relation: '=',
-        type: 'integer',
-        field: 'etapas_mod_ensino_segmento_id'
-    }
-}).addValue({
-    name:'integral_time',
-    table: 'escola',
-    tableField: 'tempo_integral',
-    resultField: 'integral_time_id',
-    where: {
-        relation: '=',
-        type: 'integer',
-        field: 'tempo_integral'
-    }
-  }).addValue({
-    name: 'education_level_short',
-    table: 'escola',
-    tableField: 'etapa_resumida',
-    resultField: 'education_level_short_id',
-    where: {
-        relation: '=',
-        type: 'integer',
-        field: 'etapa_resumida'
-    }
 }).addValue({
     name: 'region',
     table: 'regiao',
@@ -345,36 +270,13 @@ rqf.addField({
         foreign: ['escola_id', 'ano_censo'],
         foreignTable: 'escola'
     }
-}, 'filter').addValue({
-    name: 'location',
-    table: 'escola',
-    tableField: 'localizacao_id',
-    resultField: 'location_id',
-    where: {
-        relation: '=',
-        type: 'integer',
-        field: 'localizacao_id'
-    }
-}).addValue({
-    name: 'diff_location',
-    table: 'escola',
-    tableField: 'localizacao_diferenciada_par',
-    resultField: 'diff_location_id',
-    where: {
-        relation: '=',
-        type: 'integer',
-        field: 'localizacao_diferenciada_par'
-    }
-});
+}, 'filter');
 
 // Return all cities
 employeesAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
 
-    if (req.query.filter && !req.query.filter.includes('school'))
-        return;
-
-    if (req.query.filter == undefined)
-        return;
+    if ((req.query.filter && !req.query.filter.includes('school')) || req.query.filter == undefined)
+        throw 'Filtro escola deve ser selecionado.';
 
     if (req.query.dims && req.query.dims.includes('education_level_mod_doc')) {
         req.sql.from('escola')
@@ -409,6 +311,6 @@ employeesAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
         .where('escola.situacao_funcionamento_pareada = 1 and (escola.ensino_regular = 1 or escola.ensino_eja = 1 or escola.educacao_profissional = 1)');
     }
     next();
-}, query, aggregateData, id2str.transform(false), response('enrollment_aggregate'));
+}, query, aggregateData, id2str.transform(false), response('employees_aggregate'));
 
 module.exports = employeesAggregateApp;
-- 
GitLab