Skip to content
Snippets Groups Projects
Commit 9e0225bb authored by lgtg20's avatar lgtg20
Browse files

Add federative entity route

parent f489d386
Branches
No related tags found
3 merge requests!434Homologa,!422Development,!420Ente federativo
/*
Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre
Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
This file is part of simcaq-node.
simcaq-node is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
simcaq-node is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with simcaq-node. If not, see <https://www.gnu.org/licenses/>.
*/
module.exports = function educationLevelShort(id) {
switch (id) {
case 1:
return 'Creche';
case 2:
return 'Pré-Escola';
case 3:
return 'Ensino Fundamental - anos iniciais';
case 4:
return 'Ensino Fundamental - anos finais';
case 5:
return 'Ensino Médio Propedêutico';
case 6:
return 'Ensino Médio Normal Magistério';
case 7:
return 'Ensino Médio Integrado';
case 8:
return 'Educação Profissional Técnica - Associado ao Nível Médio';
case 9:
return 'Educação Profissional Técnica - Concomitante';
case 10:
return 'Educação Profissional Técnica - Subsequente';
case 11:
return 'Educação Profissional - Misto';
case 12:
return 'Educação Profissional FIC Concomitante';
case 13:
return 'Educacao Profissional FIC Integrado EJA';
case 14:
return 'EJA Ensino Fundamental';
case 15:
return 'EJA Ensino Médio';
default:
return 'Não classificada';
}
};
/*
Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre
Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
This file is part of simcaq-node.
simcaq-node is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
simcaq-node is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with simcaq-node. If not, see <https://www.gnu.org/licenses/>.
*/
module.exports = function educationLevelShort(id) {
switch (id) {
case 1:
return 'Educação Infantil';
case 2:
return 'Ensino Fundamental';
case 3:
return 'Ensino Médio';
case 4:
return 'Educação Profissional';
case 5:
return 'Educação Profissional Técnica de Nível Médio';
case 6:
return 'Educação Profissional FIC';
case 7:
return 'EJA';
default:
return 'Não classificada';
}
};
...@@ -22,7 +22,9 @@ const convert = { ...@@ -22,7 +22,9 @@ const convert = {
modality_integral_time: 'educationLevelBasic', modality_integral_time: 'educationLevelBasic',
special_education: 'specialEducation', special_education: 'specialEducation',
special_education_doc: 'specialEducationDoc', special_education_doc: 'specialEducationDoc',
education_level_mod_doc: 'educationLevelModDoc' education_level_mod_doc: 'educationLevelModDoc',
education_level_mod_entity_seg: 'educationLevelModEntitySeg',
education_level_mod_entity_agg: 'educationLevelModEntityAgg'
} }
function aggregateData(req, res, next) { function aggregateData(req, res, next) {
...@@ -38,7 +40,9 @@ function aggregateData(req, res, next) { ...@@ -38,7 +40,9 @@ function aggregateData(req, res, next) {
'period_agg', 'period_agg',
'modality_integral_time', 'modality_integral_time',
'special_education', 'special_education',
'special_education_doc' 'special_education_doc',
'education_level_mod_entity_seg',
'education_level_mod_entity_agg'
] ]
let id; let id;
const fields = req.query.dims.split(','); const fields = req.query.dims.split(',');
......
...@@ -119,7 +119,8 @@ const ageRangeAggregate = require(`${libs}/convert/ageRangeAggregate`); ...@@ -119,7 +119,8 @@ const ageRangeAggregate = require(`${libs}/convert/ageRangeAggregate`);
const specialEducation = require(`${libs}/convert/specialEducation`); const specialEducation = require(`${libs}/convert/specialEducation`);
const specialEducationDoc = require(`${libs}/convert/specialEducationDoc`); const specialEducationDoc = require(`${libs}/convert/specialEducationDoc`);
const educationLevelModDoc = require(`${libs}/convert/educationLevelModDoc`); const educationLevelModDoc = require(`${libs}/convert/educationLevelModDoc`);
const educationLevelModEntitySeg = require(`${libs}/convert/educationLevelModEntitySeg`);
const educationLevelModEntityAgg = require(`${libs}/convert/educationLevelModEntityAgg`);
const ids = { const ids = {
gender_id: gender, gender_id: gender,
...@@ -231,7 +232,9 @@ const ids = { ...@@ -231,7 +232,9 @@ const ids = {
income_range_id: incomeRange, income_range_id: incomeRange,
special_education: specialEducation, special_education: specialEducation,
special_education_doc: specialEducationDoc, special_education_doc: specialEducationDoc,
education_level_mod_doc: educationLevelModDoc education_level_mod_doc: educationLevelModDoc,
education_level_mod_entity_seg: educationLevelModEntitySeg,
education_level_mod_entity_agg: educationLevelModEntityAgg
}; };
function transform(removeId=false) { function transform(removeId=false) {
...@@ -365,5 +368,7 @@ module.exports = { ...@@ -365,5 +368,7 @@ module.exports = {
incomeRange, incomeRange,
specialEducation, specialEducation,
specialEducationDoc, specialEducationDoc,
educationLevelModDoc educationLevelModDoc,
educationLevelModEntitySeg,
educationLevelModEntityAgg
}; };
...@@ -149,6 +149,8 @@ const enrollmentAggregate = require(`${libs}/routes_v1/enrollmentAggregate`); ...@@ -149,6 +149,8 @@ const enrollmentAggregate = require(`${libs}/routes_v1/enrollmentAggregate`);
const employeesAggregate = require(`${libs}/routes_v1/employeesAggregate`); const employeesAggregate = require(`${libs}/routes_v1/employeesAggregate`);
const federativeEntity = require(`${libs}/routes_v1/federativeEntity`);
const email = require(`${libs}/routes_v1/email`); const email = require(`${libs}/routes_v1/email`);
api.get('/', (req, res) => { api.get('/', (req, res) => {
...@@ -214,6 +216,7 @@ api.use('/new_pnad', newPnad); ...@@ -214,6 +216,7 @@ api.use('/new_pnad', newPnad);
api.use('/rate_school_new', rateSchoolNew) api.use('/rate_school_new', rateSchoolNew)
api.use('/enrollmentAggregate', enrollmentAggregate); api.use('/enrollmentAggregate', enrollmentAggregate);
api.use('/employeesAggregate', employeesAggregate); api.use('/employeesAggregate', employeesAggregate);
api.use('/federativeEntity', federativeEntity);
//Publication //Publication
......
/*
Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre
Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
This file is part of simcaq-node.
simcaq-node is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
simcaq-node is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with simcaq-node. If not, see <https://www.gnu.org/licenses/>.
*/
const express = require('express');
const { result } = require('lodash');
const federativeEntityApp = express.Router();
const libs = `${process.cwd()}/libs`;
const log = require(`${libs}/log`)(module);
const squel = require('squel');
const query = require(`${libs}/middlewares/query`).query;
const response = require(`${libs}/middlewares/response`);
const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
const aggregateData = require(`${libs}/middlewares/aggregateData`);
const id2str = require(`${libs}/middlewares/id2str`);
const config = require(`${libs}/config`);
const addMissing = require(`${libs}/middlewares/addMissing`);
const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware;
federativeEntityApp.use(cache('15 day'));
let rqf = new ReqQueryFields();
federativeEntityApp.get('/years', (req, res, next) => {
req.sql.from('escola')
.field('DISTINCT escola.ano_censo', 'year')
.where('escola.ano_censo >= 2021')
next();
}, query, response('years'));
federativeEntityApp.get('/adm_dependency', (req, res, next) => {
req.result = []
for (let i = 1; i <= 5; i++) {
req.result.push({
id: i, name: id2str.admDependency(i)
});
}
next();
}, response('adm_dependency'));
federativeEntityApp.get('/adm_dependency_detailed', (req, res, next) => {
req.result = []
for (let i = 1; i <= 9; i++) {
req.result.push({
id: i, name: id2str.admDependencyPriv(i)
});
}
next();
}, response('adm_dependency_detailed'));
federativeEntityApp.get('/education_level_mod_agg', (req, res, next) => {
req.result = []
for (let i = 1; i <= 13; i++) {
req.result.push({
id: i, name: id2str.educationLevelMod(i)
});
}
next();
}, response('education_level_mod_agg'));
federativeEntityApp.get('/integral_time_agg', (req, res, next) => {
req.result = []
for (let i = 0; i <= 3; i++) {
req.result.push({
id: i, name: id2str.integralTime(i)
});
}
next();
}, response('integral_time_agg'));
federativeEntityApp.get('/location', (req, res, next) => {
req.result = []
for (let i = 1; i <= 2; i++) {
req.result.push({
id: i, name: id2str.location(i)
});
}
next();
}, response('location'));
federativeEntityApp.get('/diff_location', (req, res, next) => {
req.result = []
for (let i = 0; i <= 4; i++) {
req.result.push({
id: i, name: id2str.diffLocation(i)
});
}
req.result.push({
id: 8, name: 'Área onde se localizam povos e comunidades tradicionais'
})
next();
}, response('diff_location'));
federativeEntityApp.get('/modality_integral_time', (req, res, next) => {
req.result = []
for (let i = 0; i <= 7; i++) {
req.result.push({
id: i, name: id2str.educationLevelBasic(i)
});
}
next();
}, response('modality_integral_time'));
federativeEntityApp.get('/gender', (req, res, next) => {
req.result = []
for (let i = 1; i <= 2; i++) {
req.result.push({
id: i, name: id2str.gender(i)
});
}
next();
}, response('gender'));
federativeEntityApp.get('/age_range', (req, res, next) => {
req.result = []
for (let i = 1; i <= 7; i++) {
req.result.push({
id: i, name: id2str.ageRangeAggregate(i)
});
}
next();
}, response('age_range'));
federativeEntityApp.get('/ethnic_group', (req, res, next) => {
req.result = []
for (let i = 0; i <= 6; i++) {
req.result.push({
id: i, name: id2str.ethnicGroup(i)
});
}
next();
}, response('ethnic_group'));
federativeEntityApp.get('/period_agg', (req, res, next) => {
req.result = []
for (let i = 0; i <= 5; i++) {
req.result.push({
id: i, name: id2str.period(i)
});
}
next();
}, response('period_agg'));
federativeEntityApp.get('/region', (req, res, next) => {
req.result = []
for (let i = 0; i <= 5; i++) {
req.result.push({
id: i, name: id2str.regionCode(i)
});
}
next();
}, response('period_agg'));
federativeEntityApp.get('/state', (req, res, next) => {
req.result = []
for (let i = 11; i < 54; i++) {
if (id2str.stateName(i) !== 'Não declarada') {
req.result.push({
id: i, name: id2str.stateName(i)
});
}
}
next();
}, response('state'));
federativeEntityApp.get('/special_education', (req, res, next) => {
req.result = []
for (let i = 1; i <= 2; i++) {
req.result.push({
id: i, name: id2str.specialEducation(i)
});
}
next();
}, response('special_education'));
rqf.addField({
name: 'filter',
field: false,
where: true
}).addField({
name: 'dims',
field: true,
where: false
}).addValue({
name: 'adm_dependency',
table: 'escola',
tableField: 'dependencia_adm_id',
resultField: 'adm_dependency_id',
where: {
relation: '=',
type: 'integer',
field: 'dependencia_adm_id'
}
}).addValue({
name: 'adm_dependency_detailed',
table: 'escola',
tableField: 'dependencia_adm_priv',
resultField: 'adm_dependency_detailed_id',
where: {
relation: '=',
type: 'integer',
field: 'dependencia_adm_priv'
}
}).addValue({
name: 'education_level_mod',
table: 'escola',
tableField: 'etapas_mod_ensino_segmento_id',
resultField: 'education_level_mod_id',
where: {
relation: '=',
type: 'integer',
field: 'etapas_mod_ensino_segmento_id'
}
}).addValue({
name:'integral_time',
table: 'escola',
tableField: 'tempo_integral',
resultField: 'integral_time_id',
where: {
relation: '=',
type: 'integer',
field: 'tempo_integral'
}
}).addValue({
name: 'education_level_short',
table: 'escola',
tableField: 'etapa_resumida',
resultField: 'education_level_short_id',
where: {
relation: '=',
type: 'integer',
field: 'etapa_resumida'
}
}).addValue({
name: 'region',
table: 'regiao',
tableField: ['nome', 'id'],
resultField: ['region_name', 'region_id'],
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: 'id',
foreign: 'regiao_id',
foreignTable: 'escola'
}
}).addValue({
name: 'mesoregion',
table: 'municipio',
tableField: ['nome_mesorregiao', 'mesorregiao_id'],
resultField: ['mesoregion_name', 'mesoregion_id'],
where: {
relation: '=',
type: 'integer',
field: 'mesorregiao_id',
table: 'municipio'
},
join: {
primary: 'id',
foreign: 'municipio_id',
foreignTable: 'escola'
}
}).addValue({
name: 'microregion',
table: 'municipio',
tableField: ['nome_microrregiao', 'microrregiao_id'],
resultField: ['microregion_name', 'microregion_id'],
where: {
relation: '=',
type: 'integer',
field: 'microrregiao_id',
table: 'municipio'
},
join: {
primary: 'id',
foreign: 'municipio_id',
foreignTable: 'escola'
}
}).addValue({
name: 'min_year',
table: 'escola',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '>=',
type: 'integer',
field: 'ano_censo',
},
}).addValue({
name: 'max_year',
table: 'escola',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '<=',
type: 'integer',
field: 'ano_censo',
},
}).addValueToField({
name: 'state',
table: 'estado',
tableField: ['nome', 'id'],
resultField: ['state_name', 'state_id'],
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: 'id',
foreign: 'estado_id',
foreignTable: 'escola'
}
}, 'dims').addValueToField({
name: 'state',
table: 'estado',
tableField: 'nome',
resultField: 'state_name',
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: 'id',
foreign: 'estado_id',
foreignTable: 'escola'
}
}, 'filter').addValueToField({
name: 'city',
table: 'municipio',
tableField: ['nome', 'id'],
resultField: ['city_name', 'city_id'],
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: 'id',
foreign: 'municipio_id',
foreignTable: 'escola'
}
}, 'dims').addValueToField({
name: 'city',
table: 'municipio',
tableField: 'nome',
resultField: 'city_name',
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: 'id',
foreign: 'municipio_id',
foreignTable: 'escola'
}
}, 'filter').addValueToField({
name: 'school',
table: 'escola',
tableField: ['nome_escola', 'id'],
resultField: ['school_name', 'school_id'],
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: ['id', 'ano_censo'],
foreign: ['escola_id', 'ano_censo'],
foreignTable: 'escola'
}
}, 'dims').addValueToField({
name: 'locale_id',
table: 'escola',
tableField: 'localizacao_id',
resultField: 'locale_id',
where: {
relation: '=',
type: 'integer',
field: 'localizacao_id'
}
}, 'dims').addValueToField({
name: 'school_id',
table: 'escola',
tableField: 'id',
resultField: 'school_id',
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: ['id', 'ano_censo'],
foreign: ['escola_id', 'ano_censo'],
foreignTable: 'escola'
}
}, 'dims').addValueToField({
name: 'school',
table: 'escola',
tableField: 'nome_escola',
resultField: 'school_name',
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: ['id', 'ano_censo'],
foreign: ['escola_id', 'ano_censo'],
foreignTable: 'escola'
}
}, 'filter').addValue({
name: 'location',
table: 'escola',
tableField: 'localizacao_id',
resultField: 'location_id',
where: {
relation: '=',
type: 'integer',
field: 'localizacao_id'
}
}).addValue({
name: 'diff_location',
table: 'escola',
tableField: 'localizacao_diferenciada_par',
resultField: 'diff_location_id',
where: {
relation: '=',
type: 'integer',
field: 'localizacao_diferenciada_par'
}
});
federativeEntityApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
console.log(req.query);
if (req.query.dims && req.query.dims.includes('education_level_mod_entity_seg'))
{
req.sql.from('docentes_sinopse')
.field('SUM(docentes_sinopse.num_doc_ed_inf_total)', 'total_doc_ed_inf_total')
.field('SUM(docentes_sinopse.num_doc_en_fund_total)', 'total_doc_en_fund_total')
.field('SUM(docentes_sinopse.num_doc_en_medio_total)', 'total_doc_en_medio_total')
.field('SUM(docentes_sinopse.num_doc_ed_prof_total)', 'total_doc_ed_prof_total')
.field('SUM(docentes_sinopse.num_doc_ed_prof_tec_total)', 'total_doc_ed_prof_tec_total')
.field('SUM(docentes_sinopse.num_doc_ed_prof_fic_total)', 'total_doc_ed_prof_fic_total')
.field('SUM(docentes_sinopse.num_doc_eja_total)', 'total_doc_eja_total')
.field('docentes_sinopse.ano_censo', 'year')
.group('docentes_sinopse.ano_censo')
.order('docentes_sinopse.ano_censo')
.where('docentes_sinopse.cod_reg = 0');
}
else if (req.query.dims && req.query.dims.includes('education_level_mod_entity_agg'))
{
req.sql.from('docentes_sinopse')
.field('SUM(docentes_sinopse.num_doc_ed_inf_creche)', 'total_doc_ed_inf_creche')
.field('SUM(docentes_sinopse.num_doc_ed_inf_pre_escola)', 'total_doc_ed_inf_pre_escola')
.field('SUM(docentes_sinopse.num_doc_en_fund_anos_iniciais)', 'total_doc_en_fund_anos_iniciais')
.field('SUM(docentes_sinopse.num_doc_en_fund_anos_finais)', 'total_doc_en_fund_anos_finais')
.field('SUM(docentes_sinopse.num_doc_en_medio_propedeutico)', 'total_doc_en_medio_propedeutico')
.field('SUM(docentes_sinopse.num_doc_en_medio_normal_magisterio)', 'total_doc_en_medio_normal_magisterio')
.field('SUM(docentes_sinopse.num_doc_en_medio_integrado)', 'total_doc_en_medio_integrado')
.field('SUM(docentes_sinopse.num_doc_ed_prof_en_medio)', 'total_doc_ed_prof_en_medio')
.field('SUM(docentes_sinopse.num_doc_ed_prof_tec_concomitante)', 'total_doc_ed_prof_tec_concomitante')
.field('SUM(docentes_sinopse.num_doc_ed_prof_tec_subsequente)', 'total_doc_ed_prof_tec_subsequente')
.field('SUM(docentes_sinopse.num_doc_ed_prof_tec_misto)', 'total_doc_ed_prof_tec_misto')
.field('SUM(docentes_sinopse.num_doc_ed_prof_fic_concomitante)', 'total_doc_ed_prof_fic_concomitante')
.field('SUM(docentes_sinopse.num_doc_ed_prof_fic_integrado_eja)', 'total_doc_ed_prof_fic_integrado_eja')
.field('SUM(docentes_sinopse.num_doc_eja_en_fund)', 'total_doc_eja_en_fund')
.field('SUM(docentes_sinopse.num_doc_eja_en_medio)', 'total_doc_eja_en_medio')
.field('docentes_sinopse.ano_censo', 'year')
.group('docentes_sinopse.ano_censo')
.order('docentes_sinopse.ano_censo')
.where('docentes_sinopse.cod_reg = 0');
}
else {
req.sql.from('docentes_sinopse')
.field('SUM(docentes_sinopse.qt_mat_bas)', 'total')
.field('docentes_sinopse.ano_censo', 'year')
.group('docentes_sinopse.ano_censo')
.order('docentes_sinopse.ano_censo');
}
next();
}, query, aggregateData, id2str.transform(false), response('federative_entity'));
module.exports = federativeEntityApp;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment