Commit f2d138f1 authored by Fernando Erd's avatar Fernando Erd
Browse files

Merge branch 'homologa'

Showing with 103 additions and 104 deletions
+103 -104
......@@ -109,17 +109,17 @@ glossEnrollmentRatioApp.get('/source', (req, res, next) => {
next();
}, query, response('source'));
glossEnrollmentRatioApp.get('/education_level_basic', (req, res, next) => {
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'}
{id: 3, name: 'Ensino Fundamental - anos iniciais'},
{id: 4, name: 'Ensino Fundamental - anos finais'},
{id: 5, name: 'Ensino Médio'}
];
next();
}, response('education_level_basic'));
}, response('education_level_short'));
glossEnrollmentRatioApp.get('/gender', (req, res, next) => {
req.result = [
......@@ -240,14 +240,14 @@ rqf.addField({
field: 'localizacao_id'
}
}).addValue({
name: 'education_level_basic',
name: 'education_level_short',
table: 'matricula',
tableField: 'etapas_mod_ensino_segmento_id',
resultField: 'education_level_basic_id',
tableField: 'etapa_resumida',
resultField: 'education_level_short_id',
where: {
relation: '=',
type: 'integer',
field: 'etapas_mod_ensino_segmento_id'
field: 'etapa_resumida'
}
});
......@@ -264,11 +264,11 @@ function matchQueries(queryTotal, queryPartial) {
// remove total
let index = keys.indexOf('total');
if(index > -1) keys.splice(index, 1);
// remove education_level_basic_id
index = keys.indexOf('education_level_basic_id');
// remove education_level_short_id
index = keys.indexOf('education_level_short_id');
if(index > -1) keys.splice(index, 1);
// remove education_level_basic_name
index = keys.indexOf('education_level_basic_name');
// remove education_level_short_name
index = keys.indexOf('education_level_short_name');
if(index > -1) keys.splice(index, 1);
let objMatch = null;
......@@ -316,10 +316,10 @@ glossEnrollmentRatioApp.get('/', rqf.parse(),(req, res, next) => {
.order('matricula.ano_censo')
.where('matricula.tipo <= 3')
if ( "education_level_basic" in req.dims ) {
req.sql.field('matricula.etapas_mod_ensino_segmento_id', 'age_range')
req.sql.where('matricula.etapas_mod_ensino_segmento_id = 1 OR matricula.etapas_mod_ensino_segmento_id = 2 OR matricula.etapas_mod_ensino_segmento_id = 4 OR matricula.etapas_mod_ensino_segmento_id = 5 OR matricula.etapas_mod_ensino_segmento_id = 6')
req.sql.group('matricula.etapas_mod_ensino_segmento_id', 'age_range');
if ( "education_level_short" in req.dims ) {
req.sql.field('matricula.etapa_resumida', 'age_range')
req.sql.where('matricula.etapa_resumida = 1 OR matricula.etapa_resumida = 2 OR matricula.etapa_resumida = 3 OR matricula.etapa_resumida = 4 OR matricula.etapa_resumida = 5')
req.sql.group('matricula.etapa_resumida', 'age_range');
}
next();
}, rqf.build(), query, id2str.transform(), (req, res, next) => {
......@@ -345,19 +345,19 @@ glossEnrollmentRatioApp.get('/', rqf.parse(),(req, res, next) => {
}
}
//remove education_level_basic how filter and add faixa_etaria_31_03 in filter
if ("education_level_basic" in req.filter) {
if (Array.isArray(req.filter.education_level_basic)) {
//remove education_level_short how filter and add faixa_etaria_31_03 in filter
if ("education_level_short" in req.filter) {
if (Array.isArray(req.filter.education_level_short)) {
var string_query = '';
for(let i = 0; i < req.filter.education_level_basic.length - 1; i++) {
string_query = string_query + convert(req.filter.education_level_basic[i]) + ' OR ';
for(let i = 0; i < req.filter.education_level_short.length - 1; i++) {
string_query = string_query + convert(req.filter.education_level_short[i]) + ' OR ';
}
string_query = string_query + convert(req.filter.education_level_basic[req.filter.education_level_basic.length - 1]);
string_query = string_query + convert(req.filter.education_level_short[req.filter.education_level_short.length - 1]);
req.sql.where(string_query);
req.sql.field('pnad.faixa_etaria_31_03','age_range')
req.sql.group('pnad.faixa_etaria_31_03', 'age_range')
}
} else if ( "education_level_basic" in req.dims ) {
} else if ( "education_level_short" in req.dims ) {
req.sql.field('pnad.faixa_etaria_31_03','age_range')
req.sql.where('pnad.faixa_etaria_31_03 = 1 OR pnad.faixa_etaria_31_03 = 2 OR pnad.faixa_etaria_31_03 = 3 OR pnad.faixa_etaria_31_03 = 4 OR pnad.faixa_etaria_31_03 = 5')
req.sql.group('pnad.faixa_etaria_31_03', 'age_range');
......@@ -371,25 +371,15 @@ glossEnrollmentRatioApp.get('/', rqf.parse(),(req, res, next) => {
next();
}, rqf.parse(), (req, res, next) => {
if ("education_level_basic" in req.filter) {
delete req.filter.education_level_basic;
if ("education_level_short" in req.filter) {
delete req.filter.education_level_short;
}
if ("education_level_basic" in req.dims) {
delete req.dims.education_level_basic;
if ("education_level_short" in req.dims) {
delete req.dims.education_level_short;
}
next();
}, rqf.build(), query, id2str.transform(), (req, res, next) => {
req.denominator = req.result;
//change age range in denominator to match with numerator result
for(let i = 0; i < req.denominator.length; i++) {
if (req.denominator[i].age_range > 2) {
req.denominator[i].age_range = req.denominator[i].age_range + 1;
}
}
// log.debug("Numerador");
// log.debug(req.numerator);
// log.debug("Denominador");
// log.debug(req.denominator);
req.result = []
let glossEnrollment = matchQueries(req.denominator, req.numerator);
req.result = glossEnrollment;
......
......@@ -109,17 +109,17 @@ liquidEnrollmentRatioApp.get('/source', (req, res, next) => {
next();
}, query, response('source'));
liquidEnrollmentRatioApp.get('/education_level_basic', (req, res, next) => {
liquidEnrollmentRatioApp.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'}
{id: 3, name: 'Ensino Fundamental - anos iniciais'},
{id: 4, name: 'Ensino Fundamental - anos finais'},
{id: 5, name: 'Ensino Médio'}
];
next();
}, response('education_level_basic'));
}, response('education_level_short'));
liquidEnrollmentRatioApp.get('/gender', (req, res, next) => {
req.result = [
......@@ -240,14 +240,14 @@ rqf.addField({
field: 'localizacao_id'
}
}).addValue({
name: 'education_level_basic',
name: 'education_level_short',
table: 'matricula',
tableField: 'etapas_mod_ensino_segmento_id',
resultField: 'education_level_basic_id',
tableField: 'etapa_resumida',
resultField: 'education_level_short_id',
where: {
relation: '=',
type: 'integer',
field: 'etapas_mod_ensino_segmento_id'
field: 'etapa_resumida'
}
});
......@@ -264,11 +264,11 @@ function matchQueries(queryTotal, queryPartial) {
// remove total
let index = keys.indexOf('total');
if(index > -1) keys.splice(index, 1);
// remove education_level_basic_id
index = keys.indexOf('education_level_basic_id');
// remove education_level_short_id
index = keys.indexOf('education_level_short_id');
if(index > -1) keys.splice(index, 1);
// remove education_level_basic_name
index = keys.indexOf('education_level_basic_name');
// remove education_level_short_name
index = keys.indexOf('education_level_short_name');
if(index > -1) keys.splice(index, 1);
let objMatch = null;
......@@ -304,6 +304,34 @@ function matchQueries(queryTotal, queryPartial) {
return match;
}
function ConvertEnrollment(result) {
if (result == 1) {
return '(matricula.faixa_etaria_31_03 = 1 AND matricula.etapa_resumida = 1)'
} else if (result == 2) {
return '(matricula.faixa_etaria_31_03 = 2 AND matricula.etapa_resumida = 2)'
} else if (result == 4) {
return '(matricula.faixa_etaria_31_03 = 3 AND matricula.etapa_resumida = 3)'
} else if (result == 5) {
return '(matricula.faixa_etaria_31_03 = 4 AND matricula.etapa_resumida = 4)'
} else if (result == 6) {
return '(matricula.faixa_etaria_31_03 = 5 AND matricula.etapa_resumida = 5)'
}
}
function convertPnad(result) {
if (result == 1) {
return 'pnad.faixa_etaria_31_03 = 1'
} else if (result == 2) {
return 'pnad.faixa_etaria_31_03 = 2'
} else if (result == 4) {
return 'pnad.faixa_etaria_31_03 = 3'
} else if (result == 5) {
return 'pnad.faixa_etaria_31_03 = 4'
} else if (result == 6) {
return 'pnad.faixa_etaria_31_03 = 5'
}
}
liquidEnrollmentRatioApp.get('/', rqf.parse(),(req, res, next) => {
req.numerator = {};
......@@ -317,36 +345,27 @@ liquidEnrollmentRatioApp.get('/', rqf.parse(),(req, res, next) => {
.order('matricula.ano_censo')
.where('matricula.tipo <= 3')
function ConvertMatricula(result) {
if (result == 1) {
return '(matricula.faixa_etaria_31_03 = 1 AND matricula.etapas_mod_ensino_segmento_id = 1)'
} else if (result == 2) {
return '(matricula.faixa_etaria_31_03 = 2 AND matricula.etapas_mod_ensino_segmento_id = 2)'
} else if (result == 4) {
return '(matricula.faixa_etaria_31_03 = 3 AND matricula.etapas_mod_ensino_segmento_id = 4)'
} else if (result == 5) {
return '(matricula.faixa_etaria_31_03 = 4 AND matricula.etapas_mod_ensino_segmento_id = 5)'
} else if (result == 6) {
return '(matricula.faixa_etaria_31_03 = 5 AND matricula.etapas_mod_ensino_segmento_id = 6)'
}
}
if ("education_level_basic" in req.filter) {
if (Array.isArray(req.filter.education_level_basic)) {
var string_query_enrollment = '';
for(let i = 0; i < req.filter.education_level_basic.length - 1; i++) {
string_query_enrollment = string_query_enrollment + ConvertMatricula(req.filter.education_level_basic[i]) + ' OR ';
if ("education_level_short" in req.filter) {
if (Array.isArray(req.filter.education_level_short)) {
var stringQuery = '';
for(let i = 0; i < req.filter.education_level_short.length - 1; i++) {
stringQuery = stringQuery + ConvertEnrollment(req.filter.education_level_short[i]) + ' OR ';
}
stringQuery = stringQuery + ConvertEnrollment(req.filter.education_level_short[req.filter.education_level_short.length - 1]);
delete req.filter.education_level_short;
req.sql.where(stringQuery);
req.sql.field('matricula.faixa_etaria_31_03', 'age_range')
req.sql.group('matricula.faixa_etaria_31_03', 'age_range');
}
string_query_enrollment = string_query_enrollment + ConvertMatricula(req.filter.education_level_basic[req.filter.education_level_basic.length - 1]);
delete req.filter.education_level_basic;
req.sql.where(string_query_enrollment);
req.sql.field('matricula.faixa_etaria_31_03', 'age_range')
req.sql.group('matricula.faixa_etaria_31_03', 'age_range');
}
} else if ( "education_level_basic" in req.dims ) {
} else if ( "education_level_short" in req.dims ) {
req.sql.field('matricula.faixa_etaria_31_03', 'age_range')
req.sql.where('(matricula.etapas_mod_ensino_segmento_id = 1 AND matricula.faixa_etaria_31_03 = 1) OR (matricula.etapas_mod_ensino_segmento_id = 2 AND matricula.faixa_etaria_31_03 = 2) OR (matricula.etapas_mod_ensino_segmento_id = 4 AND matricula.faixa_etaria_31_03 = 3) OR (matricula.etapas_mod_ensino_segmento_id = 5 AND matricula.faixa_etaria_31_03 = 4) OR (matricula.etapas_mod_ensino_segmento_id = 6 AND matricula.faixa_etaria_31_03 = 5)');
req.sql.where('(matricula.etapa_resumida = 1 AND matricula.faixa_etaria_31_03 = 1) OR (matricula.etapa_resumida = 2 AND matricula.faixa_etaria_31_03 = 2) OR (matricula.etapa_resumida = 3 AND matricula.faixa_etaria_31_03 = 3) OR (matricula.etapa_resumida = 4 AND matricula.faixa_etaria_31_03 = 4) OR (matricula.etapa_resumida = 5 AND matricula.faixa_etaria_31_03 = 5)');
req.sql.group('matricula.faixa_etaria_31_03', 'age_range');
} else {
res.status(400);
next({
......@@ -365,33 +384,23 @@ liquidEnrollmentRatioApp.get('/', rqf.parse(),(req, res, next) => {
.group('pnad.ano_censo')
.order('pnad.ano_censo')
function convertPnad(result) {
if (result == 1) {
return 'pnad.faixa_etaria_31_03 = 1'
} else if (result == 2) {
return 'pnad.faixa_etaria_31_03 = 2'
} else if (result == 4) {
return 'pnad.faixa_etaria_31_03 = 3'
} else if (result == 5) {
return 'pnad.faixa_etaria_31_03 = 4'
} else if (result == 6) {
return 'pnad.faixa_etaria_31_03 = 5'
}
}
//remove education_level_short how filter and add faixa_etaria_31_03 in filter
if ("education_level_short" in req.filter) {
//remove education_level_basic how filter and add faixa_etaria_31_03 in filter
if ("education_level_basic" in req.filter) {
if (Array.isArray(req.filter.education_level_basic)) {
var string_query = '';
for(let i = 0; i < req.filter.education_level_basic.length - 1; i++) {
string_query = string_query + convertPnad(req.filter.education_level_basic[i]) + ' OR ';
if (Array.isArray(req.filter.education_level_short)) {
var stringQuery = '';
for(let i = 0; i < req.filter.education_level_short.length - 1; i++) {
stringQuery = stringQuery + convertPnad(req.filter.education_level_short[i]) + ' OR ';
}
string_query = string_query + convertPnad(req.filter.education_level_basic[req.filter.education_level_basic.length - 1]);
req.sql.where(string_query);
stringQuery = stringQuery + convertPnad(req.filter.education_level_short[req.filter.education_level_short.length - 1]);
req.sql.where(stringQuery);
}
req.sql.field('pnad.faixa_etaria_31_03', 'age_range')
req.sql.group('pnad.faixa_etaria_31_03', 'age_range');
} else if ( "education_level_basic" in req.dims ) {
} else if ( "education_level_short" in req.dims ) {
req.sql.field('pnad.faixa_etaria_31_03','age_range')
req.sql.where('pnad.faixa_etaria_31_03 = 1 OR pnad.faixa_etaria_31_03 = 2 OR pnad.faixa_etaria_31_03 = 3 OR pnad.faixa_etaria_31_03 = 4 OR pnad.faixa_etaria_31_03 = 5')
req.sql.group('pnad.faixa_etaria_31_03', 'age_range');
......@@ -405,16 +414,16 @@ liquidEnrollmentRatioApp.get('/', rqf.parse(),(req, res, next) => {
next();
}, rqf.parse(), (req, res, next) => {
if ("education_level_basic" in req.filter) {
delete req.filter.education_level_basic;
if ("education_level_short" in req.filter) {
delete req.filter.education_level_short;
}
if ("education_level_basic" in req.dims) {
delete req.dims.education_level_basic;
if ("education_level_short" in req.dims) {
delete req.dims.education_level_short;
}
next();
}, rqf.build(), query, id2str.transform(), (req, res, next) => {
req.denominator = req.result;
//division to generate req.result final
req.result = []
let liquidEnrollment = matchQueries(req.denominator, req.numerator);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment