Skip to content
Snippets Groups Projects
Commit d737e28f authored by Fernando Gbur dos Santos's avatar Fernando Gbur dos Santos
Browse files

[ADD] Route almost ready, some tests needed. Comments added and filters that...

[ADD] Route almost ready, some tests needed. Comments added and filters that were not used were removed
parent 3ec7d063
No related branches found
No related tags found
3 merge requests!417[ADD] Indicator "Taxa de Atendimento Educacional" updated on production!,!416[ADD] Route almost ready, some tests needed. Comments added and filters that...,!414[ADD] Route almost ready, some tests needed. Comments added and filters that...
...@@ -97,16 +97,6 @@ rqf.addField({ ...@@ -97,16 +97,6 @@ rqf.addField({
foreign: 'cod_uf', foreign: 'cod_uf',
foreignTable: 'pnad_novo' 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({ }).addValue({
name: 'bolsa_familia', name: 'bolsa_familia',
table: 'pnad_novo', table: 'pnad_novo',
...@@ -207,39 +197,9 @@ rqf.addField({ ...@@ -207,39 +197,9 @@ rqf.addField({
type: 'integer', type: 'integer',
field: 'faixa_rendimento_aux' 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) { function matchQueries(attendsSchoolObj, populationObj) {
let match = []; let match = [];
...@@ -247,8 +207,6 @@ function matchQueries(attendsSchoolObj, populationObj) { ...@@ -247,8 +207,6 @@ function matchQueries(attendsSchoolObj, populationObj) {
let newObj = attendsSchoolObj[i]; let newObj = attendsSchoolObj[i];
newObj.total = (attendsSchoolObj[i].total / populationObj[i].total) * 100; newObj.total = (attendsSchoolObj[i].total / populationObj[i].total) * 100;
//newObj.faixa_etaria = attendsSchoolObj[i].faixa_etaria;
//newObj.year = attendsSchoolObj[i].year;
match.push(newObj); match.push(newObj);
} }
...@@ -257,8 +215,11 @@ function matchQueries(attendsSchoolObj, populationObj) { ...@@ -257,8 +215,11 @@ function matchQueries(attendsSchoolObj, populationObj) {
} }
rateSchoolNewApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { 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 = [] 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(); let attends_school = req.sql.clone();
attends_school.from('pnad_novo') attends_school.from('pnad_novo')
.field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total') .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) => { ...@@ -272,6 +233,7 @@ rateSchoolNewApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
.order('pnad_novo.ano_ref') .order('pnad_novo.ano_ref')
req.querySet.push(attends_school); 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(); let full_population = req.sql.clone();
full_population.from('pnad_novo') full_population.from('pnad_novo')
.field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total') .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) => { ...@@ -288,6 +250,8 @@ rateSchoolNewApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
next(); next();
}, multiQuery, (req, res, 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]); let newObj = matchQueries(req.result[0], req.result[1]);
req.result = newObj; req.result = newObj;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment