Skip to content
Snippets Groups Projects

Fix dims in rate school

Merged Fernando Erd requested to merge change_rate_school_dims into development
1 file
+ 15
3
Compare changes
  • Side-by-side
  • Inline
@@ -241,6 +241,8 @@ function matchQueries(queryTotal, queryPartial) {
keys.forEach((key) => {
newObj[key] = result[key];
});
console.log('NEW OBJ');
console.log(newObj);
let index = keys.indexOf('total');
if(index > -1) keys.splice(index, 1);
let objMatch = null;
@@ -262,6 +264,7 @@ function matchQueries(queryTotal, queryPartial) {
}
if(objMatch) {
console.log(objMatch);
newObj.denominator = result.total;
newObj.partial = objMatch.total;
newObj.total = (objMatch.total / result.total) * 100;
@@ -277,13 +280,14 @@ rateSchoolApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
req.queryIndex = {};
log.debug(req.sql.toParam());
if ("age_range" in req.filter) {
if ("age_range" in req.filter || "age_range" in req.dims) {
let freq_total = req.sql.clone();
freq_total.field('sum(pnad.peso)', 'total')
.field('pnad.ano_censo','year')
.from('pnad')
.group('pnad.ano_censo')
.order('pnad.ano_censo')
.where('pnad.faixa_etaria_31_03 < 7')
req.queryIndex.freq_total = req.querySet.push(freq_total) - 1;
let freq_nursery = req.sql.clone();
@@ -293,16 +297,24 @@ rateSchoolApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
.group('pnad.ano_censo')
.order('pnad.ano_censo')
.where('pnad.frequenta_escola_creche = 2')
.where('pnad.faixa_etaria_31_03 < 7')
req.queryIndex.freq_nursery = req.querySet.push(freq_nursery) - 1;
}
next();
}, multiQuery, (req, res, next) => {
if ("age_range" in req.filter) {
if ("age_range" in req.filter || "age_range" in req.dims) {
log.debug(req.result[req.queryIndex.freq_total]);
log.debug(req.result[req.queryIndex.freq_nursery])
let school_attendance_rate = matchQueries(req.result[req.queryIndex.freq_total], req.result[req.queryIndex.freq_nursery]);
req.result = school_attendance_rate;
} else {
req.result = [];
res.status(400);
next({
status: 400,
message: 'Wrong/No filter specified'
});
}
log.debug(req.result)
next();
}, id2str.transform(false), response('rateSchool'));
Loading