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

Add match queries

parent 50e3c555
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!109Enrollment liquid ratio
...@@ -36,6 +36,8 @@ const rateSchool = require('./rateSchool') ...@@ -36,6 +36,8 @@ const rateSchool = require('./rateSchool')
const glossEnrollmentRatio = require('./glossEnrollmentRatio') const glossEnrollmentRatio = require('./glossEnrollmentRatio')
const liquidEnrollmentRatio = require('./liquidEnrollmentRatio')
const idhm = require('./idhm'); const idhm = require('./idhm');
const idhmr = require('./idhmr'); const idhmr = require('./idhmr');
...@@ -80,6 +82,7 @@ api.use('/pibpercapita', pibpercapita); ...@@ -80,6 +82,7 @@ api.use('/pibpercapita', pibpercapita);
api.use('/population', population); api.use('/population', population);
api.use('/rate_school', rateSchool); api.use('/rate_school', rateSchool);
api.use('/gloss_enrollment_ratio', glossEnrollmentRatio); api.use('/gloss_enrollment_ratio', glossEnrollmentRatio);
api.use('/liquid_enrollment_ratio', liquidEnrollmentRatio);
api.use('/idhml', idhml); api.use('/idhml', idhml);
api.use('/auth/token', oauth2.token); api.use('/auth/token', oauth2.token);
api.use('/verify', verifyToken); api.use('/verify', verifyToken);
......
...@@ -235,6 +235,46 @@ rqf.addField({ ...@@ -235,6 +235,46 @@ rqf.addField({
} }
}); });
function matchQueries(queryTotal, queryPartial) {
let match = [];
queryTotal.forEach((result) => {
let newObj = {};
let keys = Object.keys(result);
keys.forEach((key) => {
newObj[key] = result[key];
});
let index = keys.indexOf('total');
if(index > -1) keys.splice(index, 1);
let objMatch = null;
for(let i = 0; i < queryPartial.length; ++i) {
let partial = queryPartial[i];
let foundMatch = true;
for(let j = 0; j < keys.length; ++j) {
let key = keys[j];
if(partial[key] !== result[key]) {
foundMatch = false;
break;
}
}
if(foundMatch) {
objMatch = partial;
break;
}
}
if(objMatch) {
newObj.total = (objMatch.total / result.total) * 100;
newObj.partial = objMatch.total;
newObj.denominator = result.total
match.push(newObj);
}
});
return match;
}
glossEnrollmentRatioApp.get('/', rqf.parse(),(req, res, next) => { glossEnrollmentRatioApp.get('/', rqf.parse(),(req, res, next) => {
req.numerator = {}; req.numerator = {};
req.denominator = {}; req.denominator = {};
...@@ -327,16 +367,10 @@ glossEnrollmentRatioApp.get('/', rqf.parse(),(req, res, next) => { ...@@ -327,16 +367,10 @@ glossEnrollmentRatioApp.get('/', rqf.parse(),(req, res, next) => {
//division to generate req.result final //division to generate req.result final
req.result = [] req.result = []
for (let i = 0; i < req.numerator.length; i++) { log.debug(Object.keys(req.dims))
for (let j = 0; j < req.denominator.length; j++) { let school_place = matchQueries(req.denominator, req.numerator);
if (req.numerator[i].year == req.denominator[j].year) { req.result = school_place;
req.numerator[i].total = req.numerator[i].total/req.denominator[j].total;
req.result.push(req.numerator[i]);
}
}
}
next(); next();
}, response('glossEnrollmentRatio')); }, response('liquuidEnrollmentRatio'));
module.exports = glossEnrollmentRatioApp; module.exports = glossEnrollmentRatioApp;
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