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] [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