Skip to content
Snippets Groups Projects
Commit 82dcf2ea authored by Fernando Erd's avatar Fernando Erd :ok_hand:
Browse files

Fix years and year_range subroutes

parent 62830c69
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!106Gloss enrollment ratio route
Pipeline #
...@@ -36,24 +36,31 @@ glossEnrollmentRatioApp.use(cache('15 day')); ...@@ -36,24 +36,31 @@ glossEnrollmentRatioApp.use(cache('15 day'));
// Returns a tuple of start and ending years of the complete enrollments dataset. // Returns a tuple of start and ending years of the complete enrollments dataset.
glossEnrollmentRatioApp.get('/year_range', (req, res, next) => { glossEnrollmentRatioApp.get('/year_range', (req, res, next) => {
req.sql.from('pnad') req.sql.from('pnad')
.field('MIN(pnad.ano_censo)', 'start_year') .field('DISTINCT pnad.ano_censo', 'year');
.field('MAX(pnad.ano_censo)', 'end_year');
next(); next();
}, query, (req, res, next) => { }, query, (req, res, next) => {
req.oldResult = req.result;
req.sql = squel.select();
req.sql.from('matricula') req.sql.from('matricula')
.field('MIN(matricula.ano_censo)', 'start_year') .field('DISTINCT matricula.ano_censo', 'year');
.field('MAX(matricula.ano_censo)', 'end_year');
req.old_result = req.result;
next(); next();
}, query, (req, res, next) => { }, query, (req, res, next) => {
if (req.old_result[0].start_year < req.result[0].start_year) { let distinct_years = [];
req.result[0].start_year = req.old_result[0].start_year; let new_result = [];
} for (let i = 0; i < req.oldResult.length; i++) {
if (req.old_result[0].end_year > req.result[0].end_year) { log.debug(req.oldResult[i].year);
req.result[0].end_year = req.old_result[0].old_result; for (let j = 0; j < req.result.length; j++) {
if(req.oldResult[i].year == req.result[j].year) {
distinct_years.push(req.oldResult[i]);
}
}
} }
new_result.push({start_year: distinct_years[distinct_years.length -1].year, end_year: distinct_years[0].year});
req.result = new_result;
next(); next();
}, query, response('range')); }, response('range'));
glossEnrollmentRatioApp.get('/years', (req, res, next) => { glossEnrollmentRatioApp.get('/years', (req, res, next) => {
req.sql.from('pnad') req.sql.from('pnad')
...@@ -68,8 +75,16 @@ glossEnrollmentRatioApp.get('/years', (req, res, next) => { ...@@ -68,8 +75,16 @@ glossEnrollmentRatioApp.get('/years', (req, res, next) => {
.field('DISTINCT matricula.ano_censo', 'year'); .field('DISTINCT matricula.ano_censo', 'year');
next(); next();
}, query, (req, res, next) => { }, query, (req, res, next) => {
let result = Object.assign(req.oldResult, req.result); let new_result = []
req.result = result; for (let i = 0; i < req.oldResult.length; i++) {
log.debug(req.oldResult[i].year);
for (let j = 0; j < req.result.length; j++) {
if(req.oldResult[i].year == req.result[j].year) {
new_result.push(req.oldResult[i]);
}
}
}
req.result = new_result;
next(); next();
}, response('years')); }, response('years'));
...@@ -328,7 +343,7 @@ glossEnrollmentRatioApp.get('/', rqf.parse(),(req, res, next) => { ...@@ -328,7 +343,7 @@ glossEnrollmentRatioApp.get('/', rqf.parse(),(req, res, next) => {
}, rqf.parse(), rqf.build(), query, (req, res, next) => { }, rqf.parse(), rqf.build(), query, (req, res, next) => {
req.numerator = req.result; req.numerator = req.result;
log.debug(req.denominator); log.debug(req.denominator);
log.debug(req.numerator.length); log.debug(req.numerator);
next(); next();
}, response('glossEnrollmentRatio')); }, response('glossEnrollmentRatio'));
......
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