diff --git a/src/libs/convert/ageRangeAggregate.js b/src/libs/convert/ageRangeAggregate.js new file mode 100644 index 0000000000000000000000000000000000000000..850f00387ec1c5edf45ae72b3696244fc3d9e364 --- /dev/null +++ b/src/libs/convert/ageRangeAggregate.js @@ -0,0 +1,38 @@ +/* +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 ageRangeAggregate(id) { + switch (id) { + case 1: + return '0 a 3 anos'; + case 2: + return '4 a 5 anos'; + case 3: + return '6 a 10 anos'; + case 4: + return '11 a 14 anos'; + case 5: + return '15 a 17 anos'; + case 6: + return '18 anos ou mais'; + default: + return 'Não declarada'; + } +}; diff --git a/src/libs/convert/educationLevelModAgg.js b/src/libs/convert/educationLevelModAgg.js new file mode 100644 index 0000000000000000000000000000000000000000..c55a7e8fc3e2f9e2549fff244f61fc57a63ba143 --- /dev/null +++ b/src/libs/convert/educationLevelModAgg.js @@ -0,0 +1,46 @@ +/* +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 educationLevelMod(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'; + case 6: + return 'Ensino Medio Integrado ou Normal - tecnico'; + case 7: + return 'EJA - Ensino Fundamental'; + case 8: + return 'EJA - Ensino Médio'; + case 9: + return 'EJA - EF e EM Integrado - tecnico'; + case 10: + return 'Educacao Profissional - concomitante e subsequente'; + default: + return 'Não classificada'; + } +}; diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js index 58a098c93619a4d0cbc026c5c41025ecf6ea2c2e..41c32836d5f1eef6fbfe1a8903da53a0442daa54 100644 --- a/src/libs/middlewares/aggregateData.js +++ b/src/libs/middlewares/aggregateData.js @@ -1,12 +1,16 @@ const id2str = require(`./id2str`); const convert = { - "adm_dependency_detailed": "admDependencyPriv" + "adm_dependency_detailed": "admDependencyPriv", + "age_range": "ageRangeAggregate", + "gender": "gender", + "ethnic_group": "ethnicGroup", + "education_level_mod_agg": "educationLevelModAgg" } function aggregateData(req, res, next) { const newResult = [] - const aggregateFields = ['gender'] + const aggregateFields = ['gender', 'age_range', 'ethnic_group', 'education_level_mod_agg'] let id; const fields = req.query.dims.split(','); let currentAggregateField; @@ -15,14 +19,14 @@ function aggregateData(req, res, next) { if (currentAggregateField) { console.log(currentAggregateField); req.result.forEach((r) => { - id = 1; + id = currentAggregateField === 'ethnic_group' ? 0 : 1; for (const property in r) { if (property.includes("total_")) { let data = { total: r[property], year: r.year, [`${currentAggregateField}_id`]: id, - [`${currentAggregateField}_name`]: id2str[currentAggregateField](id) + [`${currentAggregateField}_name`]: id2str[convert[currentAggregateField]](id) } if (currentNonAggregateField) { diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index 02273a8bff361981bc0079312881afdf052e439c..0a48e4ce06fd9ea078b8756e8c199bc70963f538 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -32,6 +32,7 @@ const agreement = require(`${libs}/convert/agreement`); const booleanVariable = require(`${libs}/convert/booleanVariable`); const educationLevel = require(`${libs}/convert/educationLevel`); const educationLevelMod = require(`${libs}/convert/educationLevelMod`); +const educationLevelModAgg = require(`${libs}/convert/educationLevelModAgg`); const educationLevelShort = require(`${libs}/convert/educationLevelShort`); const educationType = require(`${libs}/convert/educationType`); const citySize = require(`${libs}/convert/citySize`); @@ -114,6 +115,8 @@ const regionCode = require(`${libs}/convert/regionCode`); const metroCode = require(`${libs}/convert/metroCode`); const modalityShift = require(`${libs}/convert/modalityShift`); const incomeRange = require(`${libs}/convert/incomeRange`); +const ageRangeAggregate = require(`${libs}/convert/ageRangeAggregate`); + const ids = { gender_id: gender, @@ -122,6 +125,7 @@ const ids = { education_level_id: educationLevel, education_level_basic_id: educationLevelBasic, education_level_mod_id: educationLevelMod, + education_level_mod_agg_id: educationLevelModAgg, education_level_short_id: educationLevelShort, adm_dependency_id: admDependency, adm_dependency_detailed_id: admDependencyPriv, @@ -149,6 +153,7 @@ const ids = { ethnic_group_pnad_id: ethnicGroupPnad, age_range_id: ageRange, age_range_all_id: ageRangeAll, + age_range_aggregate_id: ageRangeAggregate, full_age_range_id: fullAgeRange, gender_pnad_id: genderPnad, fifth_household_income_id: fifthHouseholdIncome, @@ -267,6 +272,7 @@ module.exports = { educationLevel, educationLevelBasic, educationLevelMod, + educationLevelModAgg, educationLevelShort, educationLevelSchoolYear, admDependency, @@ -284,6 +290,7 @@ module.exports = { contractType, ethnicGroupPnad, ageRange, + ageRangeAggregate, ageRangeAll, ageStudentCode, fullAgeRange, diff --git a/src/libs/routes_v1/enrollmentAggregate.js b/src/libs/routes_v1/enrollmentAggregate.js index 6f225d6549c70dfc3582649487c23bbc7b187000..95de1c2512a4de0fbc29a8c687cd7542c219f56c 100644 --- a/src/libs/routes_v1/enrollmentAggregate.js +++ b/src/libs/routes_v1/enrollmentAggregate.js @@ -88,6 +88,16 @@ rqf.addField({ 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', @@ -305,6 +315,46 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .group('escola.ano_censo') .order('escola.ano_censo'); } + else if (req.query.dims && req.query.dims.includes('age_range')) { + req.sql.from('escola') + .field('SUM(escola.qt_mat_bas_0_3)', 'total_0_3') + .field('SUM(escola.qt_mat_bas_4_5)', 'total_4_5') + .field('SUM(escola.qt_mat_bas_6_10)', 'total_6_10') + .field('SUM(escola.qt_mat_bas_11_14)', 'total_11_14') + .field('SUM(escola.qt_mat_bas_15_17)', 'total_15_17') + .field('SUM(escola.qt_mat_bas_18_mais)', 'total_18_mais') + .field('escola.ano_censo', 'year') + .group('escola.ano_censo') + .order('escola.ano_censo'); + } + else if (req.query.dims && req.query.dims.includes('ethnic_group')) { + req.sql.from('escola') + .field('SUM(escola.qt_mat_bas_nd)', 'total_nd') + .field('SUM(escola.qt_mat_bas_branca)', 'total_branca') + .field('SUM(escola.qt_mat_bas_preta)', 'total_preta') + .field('SUM(escola.qt_mat_bas_parda)', 'total_parda') + .field('SUM(escola.qt_mat_bas_amarela)', 'total_amarela') + .field('SUM(escola.qt_mat_bas_indigena)', 'total_indigena') + .field('escola.ano_censo', 'year') + .group('escola.ano_censo') + .order('escola.ano_censo'); + } + else if (req.query.dims && req.query.dims.includes('education_level_mod_agg')) { + req.sql.from('escola') + .field('SUM(escola.qt_mat_inf_cre)', 'total_cre') + .field('SUM(escola.qt_mat_inf_pre)', 'total_pre') + .field('SUM(escola.qt_mat_fund_ai)', 'total_fund_ai') + .field('SUM(escola.qt_mat_fund_af)', 'total_fund_af') + .field('SUM(escola.qt_mat_med_agg)', 'total_med') + .field('SUM(escola.qt_mat_med_ct + escola.qt_mat_med_nm)', 'total_med_in') + .field('SUM(escola.qt_mat_eja_fund_agg)', 'total_eja_fund') + .field('SUM(escola.qt_mat_eja_med_agg)', 'total_eja_med') + .field('SUM(escola.qt_mat_eja_fund_fic + escola.qt_mat_eja_med_fic + escola.qt_mat_eja_med_tec)', 'total_tec') + .field('SUM(escola.qt_mat_prof_agg)', 'total_prof') + .field('escola.ano_censo', 'year') + .group('escola.ano_censo') + .order('escola.ano_censo'); + } else { req.sql.from('escola') .field('SUM(escola.qt_mat_bas)', 'total')