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/23] [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/23] [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/23] [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/23] [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/23] [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/23] [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/23] [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/23] [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/23] [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/23] [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/23] [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 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 12/23] [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 13/23] [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 14/23] [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 15/23] [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 16/23] [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 17/23] [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 18/23] [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 19/23] [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 20/23] [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 21/23] [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 22/23] [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 23/23] [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