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

[ADD] Age range dimension/filter is now required to use the indicator

parent ca413456
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...
......@@ -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'));
......
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