diff --git a/src/libs/convert/ageRangeCescu.js b/src/libs/convert/ageRangeCescu.js new file mode 100644 index 0000000000000000000000000000000000000000..60393c1441e0a06548738c655d3307c4bce4e136 --- /dev/null +++ b/src/libs/convert/ageRangeCescu.js @@ -0,0 +1,43 @@ +/* +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 'Até 17 anos de idade'; + case 2: + return 'De 18 a 24 anos de idade'; + case 3: + return 'De 25 a 29 anos de idade'; + case 4: + return 'De 30 a 34 anos de idade'; + case 5: + return 'De 35 a 39 anos de idade'; + case 6: + return 'De 40 a 49 anos de idade'; + case 7: + return 'De 50 a 59 anos de idade'; + case 8: + return 'De 60 ou mais anos de idade'; + default: + return 'Não declarada'; + } +}; + diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js index eed373ddbbfd98c4a30fc4615823bb5d91a01fc4..982345320880bdd98b94c1fac71ab359352dde82 100644 --- a/src/libs/middlewares/aggregateData.js +++ b/src/libs/middlewares/aggregateData.js @@ -35,7 +35,9 @@ const convert = { contract_type_entity: 'contractType', total_doc: "totalDoc", education_degree_entity: "educationDegreeEntity", - government_agreement: "governmentAgreement" + government_agreement: "governmentAgreement", + school_type: "schoolType", + age_range_cescu: "ageRangeCescu" } function aggregateData(req, res, next) { @@ -62,7 +64,8 @@ function aggregateData(req, res, next) { 'age_range_entity', 'post_graduation_entity', 'contract_type_entity', - 'education_degree_entity' + 'education_degree_entity', + 'age_range_cescu' ] let id; const fields = req.query.dims.split(','); diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index d6c763c9e3d281b3763c8be632d1b4dca5a0e78f..d4b3896b43564c5623d1f96037e7624ddea9999a 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -43,6 +43,7 @@ const contractType = require(`${libs}/convert/contractType`); const ethnicGroupPnad = require(`${libs}/convert/ethnicGroupPnad`); const ageRange = require(`${libs}/convert/ageRange`); const ageRangeAll = require(`${libs}/convert/ageRangeAll`); +const ageRangeCescu = require(`${libs}/convert/ageRangeCescu`); const ageStudentCode = require(`${libs}/convert/ageStudentCode`); const fullAgeRange = require(`${libs}/convert/fullAgeRange`); const genderPnad = require(`${libs}/convert/genderPnad`); @@ -164,6 +165,7 @@ const ids = { age_range_all_id: ageRangeAll, age_range_aggregate_id: ageRangeAggregate, full_age_range_id: fullAgeRange, + age_range_cescu_id: ageRangeCescu, gender_pnad_id: genderPnad, fifth_household_income_id: fifthHouseholdIncome, extremes_household_income_id: extremesHouseholdIncome, @@ -312,6 +314,7 @@ module.exports = { ageRange, ageRangeAggregate, ageRangeAll, + ageRangeCescu, ageStudentCode, fullAgeRange, genderPnad, diff --git a/src/libs/routes_v1/api.js b/src/libs/routes_v1/api.js index 6f2de423e875e9c89216a8bef138aed66df0b53d..3ed477ef7158c4bff43fe8b7612bd895e525716c 100644 --- a/src/libs/routes_v1/api.js +++ b/src/libs/routes_v1/api.js @@ -171,7 +171,6 @@ const adjustedLiquidFrequency = require(`${libs}/routes_v1/adjustedLiquidFrequen const iliteracyRate = require(`${libs}/routes_v1/iliteracyRate`); -// comentei para ver se o api.get abaixo ia dar certo (nao deu) const superiorEnrollmentAggregate = require(`${libs}/routes_v1/superiorEnrollmentAggregate`); api.get('/', (req, res) => { diff --git a/src/libs/routes_v1/superiorEnrollmentAggregate.js b/src/libs/routes_v1/superiorEnrollmentAggregate.js index 7042e514b1609c325ed4caadfd2f3203e94df76c..ed02530ef25563af61891aec8a31e14d50d1852d 100644 --- a/src/libs/routes_v1/superiorEnrollmentAggregate.js +++ b/src/libs/routes_v1/superiorEnrollmentAggregate.js @@ -246,282 +246,142 @@ 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', - 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', + table: 'curso_superior_agregado', tableField: 'ano_censo', resultField: 'year', where: { relation: '>=', type: 'integer', - field: 'ano_censo', - }, + field: 'ano_censo' + } }).addValue({ name: 'max_year', - table: 'escola', - tableField: 'ano_censo', + table: 'curso_superior_agregado', + tableField: '', 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' + field: 'ano_censo' } -}, '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', +}).addValue({ + name: 'tp_categ_adm', + table: 'curso_superior_agregado', + tableField: 'tp_categ_adm', + resultField: 'tp_categ_adm', where: { relation: '=', type: 'integer', - field: 'localizacao_id' + field: 'tp_categ_adm' } -}, 'dims').addValueToField({ - name: 'school_id', - table: 'escola', - tableField: 'id', - resultField: 'school_id', +}).addValue({ + name: 'cine_global', + table: 'curso_superior_agregado', + tableField: ['nome_cine_area_geral', 'cod_cine_area_geral'], + resultField: ['name_cine_global', 'cod_cine_global'], where: { relation: '=', type: 'integer', - field: 'id' + field: 'cod_cine_area_geral', }, - join: { - primary: ['id', 'ano_censo'], - foreign: ['escola_id', 'ano_censo'], - foreignTable: 'escola' - } -}, 'dims').addValueToField({ - name: 'school', - table: 'escola', - tableField: 'nome_escola', - resultField: 'school_name', +}).addValue({ + name: 'cine_sp', + table: 'curso_superior_agregado', + tableField: ['nome_cine_area_esp', 'cod_cine_area_esp'], + resultField: ['name_cine_sp', 'cod_cine_sp'], where: { relation: '=', type: 'integer', - field: 'id' - }, - join: { - primary: ['id', 'ano_censo'], - foreign: ['escola_id', 'ano_censo'], - foreignTable: 'escola' + field: 'cod_cine_area_esp' } -}, 'filter').addValue({ - name: 'location', - table: 'escola', - tableField: 'localizacao_id', - resultField: 'location_id', +}).addValue({ + name: 'cine_deatiled', + table: 'curso_superior_agregado', + tableField: ['nome_cine_area_detalhada', 'cod_cine_area_detalhada'], + resultField: ['name_cine_detailed', 'cod_cine_detailed'], where: { relation: '=', type: 'integer', - field: 'localizacao_id' + field: 'cod_cine_area_detalhada' } }).addValue({ - name: 'diff_location', - table: 'escola', - tableField: 'localizacao_diferenciada_par', - resultField: 'diff_location_id', + name: 'graduates', + table: 'curso_superior_agregado', + tableField: 'qtd_concluintes', + resultField: 'graduates', where: { relation: '=', type: 'integer', - field: 'localizacao_diferenciada_par', + field: 'qtd_concluintes' } }).addValue({ - name: 'government_agreement', - table: 'escola', - tableField: 'dependencia_convenio_publico', - resultField: 'government_agreement_id', + name: 'disabled_students', + table: 'curso_superior_agregado', + tableField: 'qtd_aluno_deficiente', + resultField: 'disabled_students', where: { relation: '=', type: 'integer', - field: 'dependencia_convenio_publico' + field: 'qtd_aluno_deficiente' } +}).addValue({ + }); superiorEnrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + if (req.query.dims && req.query.dims.includes("ethnic_group")){ + req.sql.field('ano_censo', 'year') + .field('sum(qtd_mat_branca)', 'total_branca') + .field('sum(qtd_mat_preta)', 'total_preta') + .field('sum(qtd_mat_parda)', 'total_parda') + .field('sum(qtd_mat_amarela)', 'total_amarela') + .field('sum(qtd_mat_indigena)', 'total_indigena') + .field('sum(qtd_mat_cor_nao_declarada)', 'total_nd') + .from('curso_superior_agregado') + .where('tp_nivel_acad = 1') + .group('ano_censo') + .order('ano_censo'); + } + else if (req.query.dims && req.query.dims.includes("school_type")){ + req.sql.field('ano_censo', 'year') + .field('sum(qtd_mat_proces_publica)', 'total_publica') + .field('sum(qtd_mat_proces_privada)', 'total_privada') + .field('sum(qtd_mat_proces_nao_informada)', 'total_nao_informada') + .from('curso_superior_agregado') + .where('tp_nivel_acad = 1') + .group('ano_censo') + .order('ano_censo'); + } + else if (req.query.dims && req.query.dims.includes("age_range_cescu")){ + req.sql.field('ano_censo', 'year') + .field('sum(qtd_mat_0_17)', 'total_0_17') + .field('sum(qtd_mat_18_24)', 'total_18_24') + .field('sum(qtd_mat_25_29)', 'total_25_29') + .field('sum(qtd_mat_30_34)', 'total_30_34') + .field('sum(qtd_mat_35_39)', 'total_35_39') + .field('sum(qtd_mat_40_49)', 'total_40_49') + .field('sum(qtd_mat_50_59)', 'total_50_59') + .field('sum(qtd_mat_60_mais)', 'total_60_mais') + .from('curso_superior_agregado') + .where('tp_nivel_acad = 1') + .group('ano_censo') + .order('ano_censo'); + } + else { + req.sql.field('ano_censo', 'Ano') + .field('SUM(qtd_matriculas)', 'Número de Matrículas') + .from('curso_superior_agregado') + .where('tp_nivel_acad = 1') + .group('ano_censo') + .order('ano_censo'); + } - req.sql.field('ano_censo', 'Ano') - .field('sum(qtd_matriculas)', 'Número de Matrículas') - .from('curso_superior_agregado') - .where('tp_nivel_acad = 1') - .where('qtd_cursos = 1') - .group('ano_censo') - .order('ano_censo'); - console.log(req.sql.toString()); + console.log(req.query.dims); + next(); -}, query, id2str.transform(false), response('superior_enrollment_aggregate')); +}, query, aggregateData, id2str.transform(false), response('superior_enrollment_aggregate')); module.exports = superiorEnrollmentAggregateApp;