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

Add foreach in condition

parent a34f9e1c
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!106Gloss enrollment ratio route
Pipeline #
......@@ -93,32 +93,45 @@ glossEnrollmentRatioApp.get('/source', (req, res, next) => {
next();
}, query, response('source'));
glossEnrollmentRatioApp.get('/location', (req, res, next) => {
glossEnrollmentRatioApp.get('/education_level_short', (req, res, next) => {
req.result = [
{id: 1, name: 'Urbana'},
{id: 2, name: 'Rural'}
{id: null, name: 'Não classificada'},
{id: 1, name: 'Creche'},
{id: 2, name: 'Pré-Escola'},
{id: 4, name: 'Ensino Fundamental - anos iniciais'},
{id: 5, name: 'Ensino Fundamental - anos finais'},
{id: 6, name: 'Ensino Médio'}
];
next();
}, response('location'));
}, response('education_level_short'));
glossEnrollmentRatioApp.get('/ethnic_group_pnad', (req, res, next) => {
glossEnrollmentRatioApp.get('/gender', (req, res, next) => {
req.result = [
{id: 0, name: 'Indígena'},
{id: 1, name: 'Branca e amarela'},
{id: 2, name: 'Preta e parda'},
{id: 9, name: 'Sem declaração'}
{id: 1, name: 'Masculino'},
{id: 2, name: 'Feminino'}
];
next();
}, response('ethnic_group_pnad'));
glossEnrollmentRatioApp.get('/gender', (req, res, next) => {
req.result = [
{id: 2, name: 'Masculino'},
{id: 4, name: 'Feminino'}
];
next();
}, response('gender'));
glossEnrollmentRatioApp.get('/ethnic_group', (req, res, next) => {
req.result = [
{id: 0, name: 'Sem declaração'},
{id: 1, name: 'Branca'},
{id: 2, name: 'Preta'},
{id: 3, name: 'Parda'},
{id: 4, name: 'Amarela'},
{id: 5, name: 'Indígena'}
];
next();
}, response('ethnic_group'));
glossEnrollmentRatioApp.get('/location', (req, res, next) => {
req.result = [
{id: 1, name: 'Urbana'},
{id: 2, name: 'Rural'}
];
next();
}, response('location'));
glossEnrollmentRatioApp.get('/fifth_household_income', (req, res, next) => {
req.result = [
......@@ -141,19 +154,6 @@ glossEnrollmentRatioApp.get('/extremes_household_income', (req, res, next) => {
next();
}, response('extremes_household_income'));
glossEnrollmentRatioApp.get('/education_level_short', (req, res, next) => {
req.result = [
{id: null, name: 'Não classificada'},
{id: 1, name: 'Creche'},
{id: 2, name: 'Pré-Escola'},
{id: 4, name: 'Ensino Fundamental - anos iniciais'},
{id: 5, name: 'Ensino Fundamental - anos finais'},
{id: 6, name: 'Ensino Médio'}
];
next();
}, response('education_level_short'));
rqf.addField({
name: 'filter',
field: false,
......@@ -193,14 +193,14 @@ rqf.addField({
foreignTable: 'pnad'
}
}).addValue({
name: 'ethnic_group_pnad',
table: 'pnad',
name: 'ethnic_group',
table: '@',
tableField: 'cor_raca_id',
resultField: 'ethnic_group_pnad_id',
resultField: 'ethnic_group_id',
where: {
relation: '=',
type: 'integer',
field: 'cor_raca_id'
field: 'cor_raca'
}
}).addValue({
name: 'min_year',
......@@ -276,46 +276,6 @@ 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.denominator = result.total;
newObj.partial = objMatch.total;
newObj.total = (objMatch.total / result.total) * 100;
match.push(newObj);
}
});
return match;
}
glossEnrollmentRatioApp.get('/', rqf.parse(),(req, res, next) => {
req.numerator = {};
req.denominator = {};
......@@ -327,7 +287,11 @@ glossEnrollmentRatioApp.get('/', rqf.parse(),(req, res, next) => {
.field('matricula.ano_censo', 'year')
.group('matricula.ano_censo')
.order('matricula.ano_censo')
if ("fifth_household_income" in req.filter) {
delete req.filter.fifth_household_income;
} else if ("extremes_household_income" in req.filter) {
delete req.filter.extremes_household_income;
}
next();
}, rqf.build(), query, (req, res, next) => {
req.numerator = req.result;
......@@ -339,21 +303,23 @@ glossEnrollmentRatioApp.get('/', rqf.parse(),(req, res, next) => {
.group('pnad.ano_censo')
.order('pnad.ano_censo')
if ("education_level_short" in req.filter) {
if (req.filter.education_level_short == 1) {
req.sql.where('pnad.faixa_etaria_31_03 = 1')
}
else if (req.filter.education_level_short == 2) {
req.sql.where('pnad.faixa_etaria_31_03 = 2')
}
else if (req.filter.education_level_short == 4) {
req.sql.where('pnad.faixa_etaria_31_03 = 3')
}
else if (req.filter.education_level_short == 5) {
req.sql.where('pnad.faixa_etaria_31_03 = 4')
}
else if (req.filter.education_level_short == 6) {
req.sql.where('pnad.faixa_etaria_31_03 = 5')
}
req.filter.education_level_short.forEach((result) => {
if (result == 1) {
req.sql.where('pnad.faixa_etaria_31_03 = 1')
}
else if (result == 2) {
req.sql.where('pnad.faixa_etaria_31_03 = 2')
}
else if (result == 4) {
req.sql.where('pnad.faixa_etaria_31_03 = 3')
}
else if (result == 5) {
req.sql.where('pnad.faixa_etaria_31_03 = 4')
}
else if (result == 6) {
req.sql.where('pnad.faixa_etaria_31_03 = 5')
}
});
}
next();
......@@ -366,11 +332,11 @@ glossEnrollmentRatioApp.get('/', rqf.parse(),(req, res, next) => {
req.denominator = req.result;
log.debug(req.numerator);
log.debug(req.denominator);
for (let i = 0; i < req.numerator.length; i++) {
req.numerator[i].total = req.numerator[i].total/req.denominator[i].total;
}
req.result = req.numerator;
next();
}, 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