diff --git a/src/libs/convert/ageRangeEntity.js b/src/libs/convert/ageRangeEntity.js new file mode 100644 index 0000000000000000000000000000000000000000..f9ca149b249603d1928cb01f7938e5b4837eab33 --- /dev/null +++ b/src/libs/convert/ageRangeEntity.js @@ -0,0 +1,40 @@ +/* +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 ageRangeEntity(id) { + switch (id) { + case 1: + return 'Até 24 anos'; + case 2: + return '25 a 29 anos'; + case 3: + return '30 a 39 anos'; + case 4: + return '40 a 49 anos'; + case 5: + return '50 a 54 anos'; + case 6: + return '55 a 59 anos'; + case 7: + return '60 anos ou mais'; + default: + return 'Não declarada'; + } +}; diff --git a/src/libs/convert/postGraduationEntity.js b/src/libs/convert/postGraduationEntity.js new file mode 100644 index 0000000000000000000000000000000000000000..49e8d08af7f0eaafe9cd5a14d0482b0accf9b337 --- /dev/null +++ b/src/libs/convert/postGraduationEntity.js @@ -0,0 +1,32 @@ +/* +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 ageRange(id) { + switch (id) { + case 1: + return 'Pós-Graduação Especialização'; + case 2: + return 'Pós-Graduação Mestrado'; + case 3: + return 'Pós-Graduação Doutorado'; + default: + return ''; + } +}; diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js index 4059a2f0ab5d7c1821cd468745cec56b8828259f..3dadee22817dbf8d21fdf5307cf39ab71b464a18 100644 --- a/src/libs/middlewares/aggregateData.js +++ b/src/libs/middlewares/aggregateData.js @@ -24,7 +24,14 @@ const convert = { special_education_doc: 'specialEducationDoc', education_level_mod_doc: 'educationLevelModDoc', education_level_mod_entity_seg: 'educationLevelModEntitySeg', - education_level_mod_entity_agg: 'educationLevelModEntityAgg' + education_level_mod_entity_agg: 'educationLevelModEntityAgg', + adm_dependency_entity_agg: 'newPnadAdmDependency', + adm_dependency_entity: 'admDependency', + location_entity: 'location', + gender_entity: 'gender', + age_range_entity: 'ageRangeEntity', + post_graduation_entity: 'postGraduationEntity', + contract_type_entity: 'contractType' } function aggregateData(req, res, next) { @@ -42,7 +49,14 @@ function aggregateData(req, res, next) { 'special_education', 'special_education_doc', 'education_level_mod_entity_seg', - 'education_level_mod_entity_agg' + 'education_level_mod_entity_agg', + 'adm_dependency_entity_agg', + 'adm_dependency_entity', + 'location_entity', + 'gender_entity', + 'age_range_entity', + 'post_graduation_entity', + 'contract_type_entity' ] let id; const fields = req.query.dims.split(','); diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index d940606bb5740c9908c2faade79cd74446904d08..08a1ebed376c7267befd104587257e533674b843 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -121,6 +121,8 @@ const specialEducationDoc = require(`${libs}/convert/specialEducationDoc`); const educationLevelModDoc = require(`${libs}/convert/educationLevelModDoc`); const educationLevelModEntitySeg = require(`${libs}/convert/educationLevelModEntitySeg`); const educationLevelModEntityAgg = require(`${libs}/convert/educationLevelModEntityAgg`); +const ageRangeEntity = require(`${libs}/convert/ageRangeEntity`); +const postGraduationEntity = require(`${libs}/convert/postGraduationEntity`); const ids = { gender_id: gender, @@ -234,7 +236,9 @@ const ids = { special_education_doc: specialEducationDoc, education_level_mod_doc: educationLevelModDoc, education_level_mod_entity_seg: educationLevelModEntitySeg, - education_level_mod_entity_agg: educationLevelModEntityAgg + education_level_mod_entity_agg: educationLevelModEntityAgg, + age_range_entity: ageRangeEntity, + post_graduation_entity: postGraduationEntity }; function transform(removeId=false) { @@ -370,5 +374,7 @@ module.exports = { specialEducationDoc, educationLevelModDoc, educationLevelModEntitySeg, - educationLevelModEntityAgg + educationLevelModEntityAgg, + ageRangeEntity, + postGraduationEntity }; diff --git a/src/libs/routes_v1/federativeEntity.js b/src/libs/routes_v1/federativeEntity.js index df39c3817698452942ca5f2ee4532380865dfb1c..9de0dfbfc81233047021da26863d7f6a63440f06 100644 --- a/src/libs/routes_v1/federativeEntity.js +++ b/src/libs/routes_v1/federativeEntity.js @@ -233,56 +233,6 @@ rqf.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', @@ -295,8 +245,8 @@ rqf.addField({ }, join: { primary: 'id', - foreign: 'regiao_id', - foreignTable: 'escola' + foreign: 'cod_reg', + foreignTable: 'docentes_sinopse' } }).addValue({ name: 'mesoregion', @@ -332,7 +282,7 @@ rqf.addField({ } }).addValue({ name: 'min_year', - table: 'escola', + table: 'docentes_sinopse', tableField: 'ano_censo', resultField: 'year', where: { @@ -342,7 +292,7 @@ rqf.addField({ }, }).addValue({ name: 'max_year', - table: 'escola', + table: 'docentes_sinopse', tableField: 'ano_censo', resultField: 'year', where: { @@ -412,7 +362,7 @@ rqf.addField({ } }, 'filter').addValueToField({ name: 'school', - table: 'escola', + table: 'docentes_sinopse', tableField: ['nome_escola', 'id'], resultField: ['school_name', 'school_id'], where: { @@ -427,7 +377,7 @@ rqf.addField({ } }, 'dims').addValueToField({ name: 'locale_id', - table: 'escola', + table: 'docentes_sinopse', tableField: 'localizacao_id', resultField: 'locale_id', where: { @@ -437,7 +387,7 @@ rqf.addField({ } }, 'dims').addValueToField({ name: 'school_id', - table: 'escola', + table: 'docentes_sinopse', tableField: 'id', resultField: 'school_id', where: { @@ -452,7 +402,7 @@ rqf.addField({ } }, 'dims').addValueToField({ name: 'school', - table: 'escola', + table: 'docentes_sinopse', tableField: 'nome_escola', resultField: 'school_name', where: { @@ -467,7 +417,7 @@ rqf.addField({ } }, 'filter').addValue({ name: 'location', - table: 'escola', + table: 'docentes_sinopse', tableField: 'localizacao_id', resultField: 'location_id', where: { @@ -475,16 +425,6 @@ rqf.addField({ 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) => { @@ -529,12 +469,103 @@ federativeEntityApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .order('docentes_sinopse.ano_censo') .where('docentes_sinopse.cod_reg = 0'); } + else if (req.query.dims && req.query.dims.includes('special_education')) + { + req.sql.from('docentes_sinopse') + .field('SUM(docentes_sinopse.num_doc_ed_especial_classe_comum)', 'total_doc_ed_especial_classe_comum') + .field('SUM(docentes_sinopse.num_doc_ed_especial_classe_exclusiva)', 'total_doc_ed_especial_classe_exclusiva') + .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('adm_dependency_entity_agg')) + { + req.sql.from('docentes_sinopse') + .field('SUM(docentes_sinopse.num_doc_dependencia_adm_pub)', 'total_doc_dependencia_adm_pub') + .field('SUM(docentes_sinopse.num_doc_dependencia_adm_priv)', 'total_doc_dependencia_adm_priv') + .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('adm_dependency_entity')) + { + req.sql.from('docentes_sinopse') + .field('SUM(docentes_sinopse.num_doc_dependencia_adm_federal)', 'total_doc_dependencia_adm_federal') + .field('SUM(docentes_sinopse.num_doc_dependencia_adm_estadual)', 'total_doc_dependencia_adm_estadual') + .field('SUM(docentes_sinopse.num_doc_dependencia_adm_municipal)', 'total_doc_dependencia_adm_municipal') + .field('SUM(docentes_sinopse.num_doc_dependencia_adm_priv)', 'total_doc_dependencia_adm_priv') + .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('location_entity')) + { + req.sql.from('docentes_sinopse') + .field('SUM(docentes_sinopse.num_doc_loc_urbana_total)', 'total_doc_loc_urbana_total') + .field('SUM(docentes_sinopse.num_doc_loc_rural_total)', 'total_doc_loc_rural_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('gender_entity')) + { + req.sql.from('docentes_sinopse') + .field('SUM(docentes_sinopse.num_doc_masc_total)', 'total_doc_masc_total') + .field('SUM(docentes_sinopse.num_doc_fem_total)', 'total_doc_fem_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('age_range_entity')) + { + req.sql.from('docentes_sinopse') + .field('SUM(docentes_sinopse.num_doc_fem_24 + docentes_sinopse.num_doc_masc_24)', 'total_doc_24') + .field('SUM(docentes_sinopse.num_doc_fem_25_29 + docentes_sinopse.num_doc_masc_25_29)', 'total_doc_25_29') + .field('SUM(docentes_sinopse.num_doc_fem_30_39 + docentes_sinopse.num_doc_masc_30_39)', 'total_doc_30_39') + .field('SUM(docentes_sinopse.num_doc_fem_40_49 + docentes_sinopse.num_doc_masc_40_49)', 'total_doc_40_49') + .field('SUM(docentes_sinopse.num_doc_fem_50_54 + docentes_sinopse.num_doc_masc_50_54)', 'total_doc_50_54') + .field('SUM(docentes_sinopse.num_doc_fem_55_59 + docentes_sinopse.num_doc_masc_55_59)', 'total_doc_55_59') + .field('SUM(docentes_sinopse.num_doc_fem_60_mais + docentes_sinopse.num_doc_masc_60_mais)', 'total_doc_60_mais') + .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('post_graduation_entity')) + { + req.sql.from('docentes_sinopse') + .field('SUM(docentes_sinopse.num_doc_esc_pos_grad_especializacao)', 'total_doc_esc_pos_grad_especializacao') + .field('SUM(docentes_sinopse.num_doc_esc_pos_grad_mestrado)', 'total_doc_esc_pos_grad_mestrado') + .field('SUM(docentes_sinopse.num_doc_esc_pos_grad_doutorado)', 'total_doc_esc_pos_grad_doutorado') + .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('contract_type_entity')) + { + req.sql.from('docentes_sinopse') + .field('SUM(docentes_sinopse.num_doc_vinc_concursado_efetivo_estavel_total)', 'total_doc_vinc_concursado_efetivo_estavel_total') + .field('SUM(docentes_sinopse.num_doc_vinc_contrato_temp_total)', 'total_doc_vinc_contrato_temp_total') + .field('SUM(docentes_sinopse.num_doc_vinc_contrato_terceirizado_total)', 'total_doc_vinc_contrato_terceirizado_total') + .field('SUM(docentes_sinopse.num_doc_vinc_contrato_clt_total)', 'total_doc_vinc_contrato_clt_total') + .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('SUM(docentes_sinopse.num_doc_ed_bas_total)', 'total') .field('docentes_sinopse.ano_censo', 'year') .group('docentes_sinopse.ano_censo') - .order('docentes_sinopse.ano_censo'); + .order('docentes_sinopse.ano_censo') + .where('docentes_sinopse.cod_uf = 0'); } next(); }, query, aggregateData, id2str.transform(false), response('federative_entity'));