diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js index d0d8992444f2e56b9b08065a2da4f83340c2fd1d..98fa78ea8d5fa46ea732592bd5f714e5cf62feee 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'));