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/diffLocation.js b/src/libs/convert/diffLocation.js index 16441ca7209987bdf941634fd39a3660a083c59d..aadc9cf6fd341dc51214c58682b8ded5e371a055 100644 --- a/src/libs/convert/diffLocation.js +++ b/src/libs/convert/diffLocation.js @@ -30,5 +30,7 @@ module.exports = function location(id) { return 'Ãrea remanescente de quilombos'; case 8: return 'Ãrea onde se localizam povos e comunidades tradicionais'; + default: + return 'Não definido'; } }; diff --git a/src/libs/convert/educationDegreeEntity.js b/src/libs/convert/educationDegreeEntity.js new file mode 100644 index 0000000000000000000000000000000000000000..e16ba13f906bb28a28d6e26a150353e084fa2947 --- /dev/null +++ b/src/libs/convert/educationDegreeEntity.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 educationDegreeEntity(id) { + switch (id) { + case 1: + return 'Ensino Fundamental'; + case 2: + return 'Ensino Médio'; + case 3: + return 'Graduação Com Licenciatura'; + case 4: + return 'Graduação Sem Licenciatura'; + } +}; diff --git a/src/libs/convert/educationLevelBasic.js b/src/libs/convert/educationLevelBasic.js index 3d166fe525019ab06f6ecbb59ede4e382ca57fa6..7c242b07072d8e51530677207c3f5c05a605f436 100644 --- a/src/libs/convert/educationLevelBasic.js +++ b/src/libs/convert/educationLevelBasic.js @@ -24,11 +24,11 @@ module.exports = function educationLevelBasic(id) { return 'Creche'; case 2: return 'Pré-Escola'; - case 4: + case 3: return 'Ensino Fundamental - anos iniciais'; - case 5: + case 4: return 'Ensino Fundamental - anos finais'; - case 6: + case 5: return 'Ensino Médio'; default: return 'Não classificada'; diff --git a/src/libs/convert/educationLevelModAgg.js b/src/libs/convert/educationLevelModAgg.js index c55a7e8fc3e2f9e2549fff244f61fc57a63ba143..6ebfa6274210a5f8956aebfe937aabae6faf07ea 100644 --- a/src/libs/convert/educationLevelModAgg.js +++ b/src/libs/convert/educationLevelModAgg.js @@ -40,6 +40,8 @@ module.exports = function educationLevelMod(id) { return 'EJA - EF e EM Integrado - tecnico'; case 10: return 'Educacao Profissional - concomitante e subsequente'; + case 11: + return 'suporte_total' default: return 'Não classificada'; } diff --git a/src/libs/convert/educationLevelModEntityAgg.js b/src/libs/convert/educationLevelModEntityAgg.js new file mode 100644 index 0000000000000000000000000000000000000000..a9fb4fbcf6c53d8a683e8bdf6ecd1f90b61ce3b3 --- /dev/null +++ b/src/libs/convert/educationLevelModEntityAgg.js @@ -0,0 +1,56 @@ +/* +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'; + } +}; diff --git a/src/libs/convert/educationLevelModEntitySeg.js b/src/libs/convert/educationLevelModEntitySeg.js new file mode 100644 index 0000000000000000000000000000000000000000..fedf7d562230a31f35e235d0523c8281f99e4f94 --- /dev/null +++ b/src/libs/convert/educationLevelModEntitySeg.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 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'; + } +}; 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/convert/specialEducationEntity.js b/src/libs/convert/specialEducationEntity.js new file mode 100644 index 0000000000000000000000000000000000000000..b358c4edaba32b3c18220a73279a74568aa59a97 --- /dev/null +++ b/src/libs/convert/specialEducationEntity.js @@ -0,0 +1,31 @@ +/* +Copyright (C) 2022 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 specialEducation(id) { + switch (id) { + case 1: + return 'Classe Comum'; + case 2: + return 'Classe Exclusiva'; + default: + return 'Não definido'; + } +}; + diff --git a/src/libs/convert/totalDoc.js b/src/libs/convert/totalDoc.js new file mode 100644 index 0000000000000000000000000000000000000000..09f947c834c9958e971949b67533044111171d19 --- /dev/null +++ b/src/libs/convert/totalDoc.js @@ -0,0 +1,23 @@ +/* +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 totalDoc(id) { + return ''; +}; diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js index 3ea93de36e317413eb7a1c956ae80f9b66f7732b..eed373ddbbfd98c4a30fc4615823bb5d91a01fc4 100644 --- a/src/libs/middlewares/aggregateData.js +++ b/src/libs/middlewares/aggregateData.js @@ -22,7 +22,20 @@ const convert = { modality_integral_time: 'educationLevelBasic', special_education: 'specialEducation', special_education_doc: 'specialEducationDoc', - education_level_mod_doc: 'educationLevelModDoc' + special_education_entity: 'specialEducationEntity', + education_level_mod_doc: 'educationLevelModDoc', + education_level_mod_entity_seg: 'educationLevelModEntitySeg', + 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', + total_doc: "totalDoc", + education_degree_entity: "educationDegreeEntity", + government_agreement: "governmentAgreement" } function aggregateData(req, res, next) { @@ -38,7 +51,18 @@ function aggregateData(req, res, next) { 'period_agg', 'modality_integral_time', 'special_education', - 'special_education_doc' + 'special_education_doc', + 'special_education_entity', + 'education_level_mod_entity_seg', + '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', + 'education_degree_entity' ] let id; const fields = req.query.dims.split(','); diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index 1971d0a014e5d744e64b3497ba1cf335b306dafe..f366d90a30c8d5c57955856040c78d610b3392b3 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -118,8 +118,14 @@ const incomeRange = require(`${libs}/convert/incomeRange`); const ageRangeAggregate = require(`${libs}/convert/ageRangeAggregate`); const specialEducation = require(`${libs}/convert/specialEducation`); const specialEducationDoc = require(`${libs}/convert/specialEducationDoc`); +const specialEducationEntity = require(`${libs}/convert/specialEducationEntity`); 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 totalDoc = require(`${libs}/convert/totalDoc`); +const educationDegreeEntity = require(`${libs}/convert/educationDegreeEntity`); const ids = { gender_id: gender, @@ -231,7 +237,14 @@ const ids = { income_range_id: incomeRange, special_education: specialEducation, 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, + age_range_entity: ageRangeEntity, + post_graduation_entity: postGraduationEntity, + special_education_entity: specialEducationEntity, + total_doc: totalDoc, + education_degree_entity: educationDegreeEntity }; function transform(removeId=false) { @@ -365,5 +378,12 @@ module.exports = { incomeRange, specialEducation, specialEducationDoc, - educationLevelModDoc + educationLevelModDoc, + educationLevelModEntitySeg, + educationLevelModEntityAgg, + ageRangeEntity, + postGraduationEntity, + specialEducationEntity, + totalDoc, + educationDegreeEntity }; diff --git a/src/libs/routes_v1/api.js b/src/libs/routes_v1/api.js index ba0369516e4f200dffe6a384d97b5776247fe0ee..bffc8b5d0ff428652d958d41d521ad1992007b85 100644 --- a/src/libs/routes_v1/api.js +++ b/src/libs/routes_v1/api.js @@ -149,8 +149,14 @@ const enrollmentAggregate = require(`${libs}/routes_v1/enrollmentAggregate`); const employeesAggregate = require(`${libs}/routes_v1/employeesAggregate`); +const courseAggregate = require(`${libs}/routes_v1/courseAggregate`); + +const federativeEntity = require(`${libs}/routes_v1/federativeEntity`); + const email = require(`${libs}/routes_v1/email`); +const uniLocalOfferAggregate = require(`${libs}/routes_v1/uniLocalOfferAggregate`) + api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API v1 is running' }); }); @@ -214,6 +220,9 @@ api.use('/new_pnad', newPnad); api.use('/rate_school_new', rateSchoolNew) api.use('/enrollmentAggregate', enrollmentAggregate); api.use('/employeesAggregate', employeesAggregate); +api.use('/course_aggregate', courseAggregate); +api.use('/federativeEntity', federativeEntity); +api.use('/uni_offer_aggregate', uniLocalOfferAggregate); //Publication diff --git a/src/libs/routes_v1/courseAggregate.js b/src/libs/routes_v1/courseAggregate.js new file mode 100644 index 0000000000000000000000000000000000000000..78ae89a71035adf992cdc43f1e8253fc5dbef575 --- /dev/null +++ b/src/libs/routes_v1/courseAggregate.js @@ -0,0 +1,412 @@ +/* +Copyright (C) 2024 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 CourseAggregateApp = express.Router(); + +const libs = `${process.cwd()}/libs`; + +const squel = require('squel'); + +const query = require(`${libs}/middlewares/query`).query; + +const response = require(`${libs}/middlewares/response`); + +const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); + +const id2str = require(`${libs}/middlewares/id2str`); + +const config = require(`${libs}/config`); + +const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware; + +let rqf = new ReqQueryFields(); + +CourseAggregateApp.use(cache('15 day')); + +CourseAggregateApp.get('/years', (req, res, next) => { + req.sql.from('curso_superior_agregado') + .field('DISTINCT curso_superior_agregado.ano_censo', 'year') + next(); +}, query, response('years')); + +CourseAggregateApp.get('/upper_adm_dependency', (req, res, next) => { + req.result = []; + for(let i = 1; i <= 7; ++i) { + req.result.push({ + id: i, + name: id2str.upperAdmDependency(i) + }); + }; + next(); +}, response('upper_adm_dependency')); + +CourseAggregateApp.get('/academic_organization', (req, res, next) => { + req.result = []; + for(let i = 1; i <= 5; ++i) { + req.result.push({ + id: i, + name: id2str.academicOrganization(i) + }); + }; + next(); +}, response('academic_organization')); + +CourseAggregateApp.get('/academic_level', (req, res, next) => { + req.result = []; + for(let i = 1; i <= 4; ++i) { + req.result.push({ + id: i, + name: id2str.academicLevel(i) + }); + }; + next(); +}, response('academic_level')); + +CourseAggregateApp.get('/upper_education_mod', (req, res, next) => { + req.result = []; + for(let i = 1; i <= 2; ++i) { + req.result.push({ + id: i, + name: id2str.upperEducationMod(i) + }); + }; + next(); +}, response('upper_education_mod')); + +CourseAggregateApp.get('/region', (req, res, next) => { + req.result = [] + for (let i = 1; i < 6; i++) { + req.result.push({ + id: i, name: id2str.regionCode(i) + }); + } + + next(); +}, response('region')); + +CourseAggregateApp.get('/cap_code', (req, res, next) => { + req.result = [] + for (let i = 11; i < 54; i++) { + if (id2str.capitalCode(i) !== 'Não informado') { + req.result.push({ + id: i, name: id2str.capitalCode(i) + }); + } + } + req.result.push({id: 99, name: id2str.capitalCode(99)}); + + next(); +}, response('cap_code')); + +CourseAggregateApp.get('/metro_code', (req, res, next) => { + req.result = [] + for (let i = 13; i < 53; i++) { + if (id2str.metroCode(i) !== 'Não informado') { + req.result.push({ + id: i, name: id2str.metroCode(i) + }); + } + } + req.result.push({id: 99, name: id2str.metroCode(99)}); + + next(); +}, response('metro_code')); + +CourseAggregateApp.get('/is_free', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Classificado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('is_free')); + + +CourseAggregateApp.get('/cine_geral', (req, res, next) => { + req.result = []; + for(let i = 1; i <= 10; ++i) { + req.result.push({ + id: i, + name: id2str.cineGeral(i) + }); + }; + next(); +}, response('cine_geral')); + +CourseAggregateApp.get('/cine_specific', (req, res, next) => { + req.result = []; + const defaultCase = null; + for(let i = 1; i <= 104; ++i) { + let obj = { + id: i, + name: id2str.cineSpecific(i) + }; + if (obj.name !== id2str.cineSpecific(defaultCase)){ + req.result.push(obj); + } + }; + req.result.push({ + id: defaultCase, + name: id2str.cineSpecific(defaultCase) + }); + next(); +}, response('cine_specific')); + +CourseAggregateApp.get('/cine_detailed', (req, res, next) => { + req.result = []; + const defaultCase = null; + for(let i = 11; i <= 1041; ++i) { + let obj = { + id: i, + name: id2str.cineDetailed(i) + }; + if (obj.name !== id2str.cineDetailed(defaultCase)){ + req.result.push(obj); + } + }; + req.result.push({ + id: defaultCase, + name: id2str.cineDetailed(defaultCase) + }); + next(); +}, response('cine_detailed')); + +CourseAggregateApp.get('/university', (req, res, next) => { + req.sql.from('curso_superior_agregado') + .field('DISTINCT curso_superior_agregado.cod_ies', 'cod') + .field('ies_ens_superior.nome_ies', 'nome') + .join('ies_ens_superior', null, 'curso_superior_agregado.cod_ies = ies_ens_superior.cod_ies and curso_superior_agregado.ano_censo = ies_ens_superior.ano_censo') + next(); +}, query, response('university')); + +CourseAggregateApp.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) + }); + } + } + req.result.push({id: 99, name: id2str.stateName(99)}); + + next(); +}, response('state')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'upper_adm_dependency', + table: 'curso_superior_agregado', + tableField: 'tp_categ_adm', + resultField: 'upper_adm_dependency_id', + where: { + relation: '=', + type: 'integer', + field: 'tp_categ_adm' + } +}).addValue({ + name: 'state', + table: 'estado', + tableField: ['id', 'nome'], + resultField: ['state_id', 'state_nome'], + where: { + relation: '=', + type: 'integer', + field: 'id', + }, + join: { + primary: 'id', + foreign: 'cod_uf', + foreignTable: 'curso_superior_agregado' + } +}).addValue({ + name: 'academic_organization', + table: 'curso_superior_agregado', + tableField: 'tp_org_acad', + resultField: 'academic_organization_id', + where: { + relation: '=', + type: 'integer', + field: 'tp_org_acad' + } +}).addValue({ + name: 'academic_level', + table: 'curso_superior_agregado', + tableField: 'tp_grau_acad', + resultField: 'academic_level_id', + where: { + relation: '=', + type: 'integer', + field: 'tp_grau_acad' + } +}).addValue({ + name: 'upper_education_mod', + table: 'curso_superior_agregado', + tableField: 'tp_modal_ens', + resultField: 'upper_education_mod_id', + where: { + relation: '=', + type: 'integer', + field: 'tp_modal_ens' + } +}).addValue({ + name: 'is_free', + table: 'curso_superior_agregado', + tableField: 'in_gratuito', + resultField: 'is_free_id', + where: { + relation: '=', + type: 'boolean', + field: 'in_gratuito' + } +}).addValue({ + name: 'cine_geral', + table: 'curso_superior_agregado', + tableField: 'cod_cine_area_geral', + resultField: 'cine_geral_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_cine_area_geral' + } +}).addValue({ + name: 'cine_specific', + table: 'curso_superior_agregado', + tableField: 'cod_cine_area_esp', + resultField: 'cine_specific_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_cine_area_esp' + } +}).addValue({ + name: 'cine_detailed', + table: 'curso_superior_agregado', + tableField: 'cod_cine_area_detalhada', + resultField: 'cine_detailed_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_cine_area_detalhada' + } +}).addValue({ + name: 'uni_offer_aggregate', + table: 'ies_ens_superior', + tableField: ['cod_ies', 'nome_ies'], + resultField: ['university_id', 'university_name'], + where: { + relation: '=', + type: 'integer', + field: 'cod_ies' + }, + join: { + primary: ['cod_ies', 'ano_censo'], + foreign: ['cod_ies', 'ano_censo'], + foreignTable: 'curso_superior_agregado' + } +}).addValue({ + name: 'cap_code', + table: 'curso_superior_agregado', + tableField: 'cod_cap', + resultField: 'cap_code_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_cap' + } +}).addValue({ + name: 'region', + table: 'curso_superior_agregado', + tableField: 'cod_reg', + resultField: 'region_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_reg' + } +}).addValue({ + name: 'metro_code', + table: 'curso_superior_agregado', + tableField: 'cod_rm_ride', + resultField: 'metro_code_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_rm_ride' + } +}).addValue({ + name: 'min_year', + table: 'curso_superior_agregado', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'max_year', + table: 'curso_superior_agregado', + tableField: '', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'city', + table: 'municipio', + tableField: ['id', 'nome'], + resultField: ['city_id', 'city_name'], + where: { + relation: '=', + type: 'integer', + field: 'id', + table: 'municipio' + }, + join: { + primary: 'id', + foreign: 'cod_mun', + foreignTable: 'curso_superior_agregado' + } +}); + +CourseAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + req.sql.from('curso_superior_agregado') + .field('count(distinct(cod_curso))', 'total') + .field('curso_superior_agregado.ano_censo', 'year') + .where('curso_superior_agregado.tp_nivel_acad = 1 AND qtd_cursos = 1') + .group('curso_superior_agregado.ano_censo') + .order('curso_superior_agregado.ano_censo') + console.log(req.sql.toString()) + next(); +}, query, id2str.transform(false), response('course_aggregate')); + +module.exports = CourseAggregateApp; diff --git a/src/libs/routes_v1/enrollmentAggregate.js b/src/libs/routes_v1/enrollmentAggregate.js index d266d2403c00b742c3329fc871d863b9cf986842..7e8cd3faece61c7999d16db913c50938de4e51fb 100644 --- a/src/libs/routes_v1/enrollmentAggregate.js +++ b/src/libs/routes_v1/enrollmentAggregate.js @@ -70,7 +70,7 @@ enrollmentAggregateApp.get('/adm_dependency', (req, res, next) => { enrollmentAggregateApp.get('/adm_dependency_detailed', (req, res, next) => { req.result = [] - for (let i = 1; i <= 9; i++) { + for (let i = 1; i <= 8; i++) { req.result.push({ id: i, name: id2str.admDependencyPriv(i) }); @@ -78,6 +78,18 @@ enrollmentAggregateApp.get('/adm_dependency_detailed', (req, res, next) => { next(); }, response('adm_dependency_detailed')); +enrollmentAggregateApp.get('/government_agreement', (req, res, next) => { + req.result = [] + + for(let i = 1; i <= 6; ++i) { + req.result.push({ + id: i, + name: id2str.governmentAgreement(i) + }); + }; + next(); +}, response('government_agreement')); + enrollmentAggregateApp.get('/education_level_mod_agg', (req, res, next) => { req.result = [] @@ -114,7 +126,7 @@ enrollmentAggregateApp.get('/location', (req, res, next) => { enrollmentAggregateApp.get('/diff_location', (req, res, next) => { req.result = [] - for (let i = 0; i <= 4; i++) { + for (let i = 0; i < 4; i++) { req.result.push({ id: i, name: id2str.diffLocation(i) }); @@ -483,7 +495,17 @@ rqf.addField({ where: { relation: '=', type: 'integer', - field: 'localizacao_diferenciada_par' + field: 'localizacao_diferenciada_par', + } +}).addValue({ + name: 'government_agreement', + table: 'escola', + tableField: 'dependencia_convenio_publico', + resultField: 'government_agreement_id', + where: { + relation: '=', + type: 'integer', + field: 'dependencia_convenio_publico' } }); @@ -499,7 +521,8 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .field('SUM(escola.qt_mat_bas_fem)', 'total_fem') .field('escola.ano_censo', 'year') .group('escola.ano_censo') - .order('escola.ano_censo'); + .order('escola.ano_censo') + .where('escola.localizacao_diferenciada_par is not null'); } else if (req.query.dims && req.query.dims.includes('age_range')) { req.sql.from('escola') @@ -511,7 +534,8 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .field('SUM(escola.qt_mat_bas_18_mais)', 'total_18_mais') .field('escola.ano_censo', 'year') .group('escola.ano_censo') - .order('escola.ano_censo'); + .order('escola.ano_censo') + .where('escola.localizacao_diferenciada_par is not null') } else if (req.query.dims && req.query.dims.includes('ethnic_group')) { req.sql.from('escola') @@ -523,7 +547,8 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .field('SUM(escola.qt_mat_bas_indigena)', 'total_indigena') .field('escola.ano_censo', 'year') .group('escola.ano_censo') - .order('escola.ano_censo'); + .order('escola.ano_censo') + .where('escola.localizacao_diferenciada_par is not null') } else if (req.query.dims && req.query.dims.includes('education_level_mod_agg')) { req.sql.from('escola') @@ -537,9 +562,12 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .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('SUM(escola.qt_mat_bas)', 'total_total') .field('escola.ano_censo', 'year') .group('escola.ano_censo') - .order('escola.ano_censo'); + .order('escola.ano_censo') + .where('escola.localizacao_diferenciada_par is not null'); + } else if (req.query.dims && req.query.dims.includes('integral_time_agg')) { req.sql.from('turma,escola') @@ -549,7 +577,7 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .field('escola.ano_censo', 'year') .group('escola.ano_censo') .order('escola.ano_censo') - .where('turma.tipo_atendimento_id <= 2 and turma.escola_id = escola.id and turma.ano_censo = escola.ano_censo'); + .where('turma.tipo_atendimento_id <= 2 and turma.escola_id = escola.id and turma.ano_censo = escola.ano_censo and escola.localizacao_diferenciada_par is not null'); } else if (req.query.dims && req.query.dims.includes('period_agg')) { req.sql.from('turma,escola') @@ -561,7 +589,7 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .field('escola.ano_censo', 'year') .group('escola.ano_censo') .order('escola.ano_censo') - .where('turma.tipo_atendimento_id <= 2 and turma.escola_id = escola.id and turma.ano_censo = escola.ano_censo'); + .where('turma.tipo_atendimento_id <= 2 and turma.escola_id = escola.id and turma.ano_censo = escola.ano_censo and escola.localizacao_diferenciada_par is not null'); } else if (req.query.dims && req.query.dims.includes('modality_integral_time')) { req.sql.from('escola') @@ -573,6 +601,7 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .field('escola.ano_censo', 'year') .group('escola.ano_censo') .order('escola.ano_censo') + .where('escola.localizacao_diferenciada_par is not null'); } else if (req.query.dims && req.query.dims.includes('special_education')) { req.sql.from('escola') @@ -581,13 +610,15 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .field('escola.ano_censo', 'year') .group('escola.ano_censo') .order('escola.ano_censo') + .where('escola.localizacao_diferenciada_par is not null'); } else { req.sql.from('escola') .field('SUM(escola.qt_mat_bas)', 'total') .field('escola.ano_censo', 'year') .group('escola.ano_censo') - .order('escola.ano_censo'); + .order('escola.ano_censo') + .where('escola.localizacao_diferenciada_par is not null'); } next(); }, query, aggregateData, id2str.transform(false), response('enrollment_aggregate')); diff --git a/src/libs/routes_v1/federativeEntity.js b/src/libs/routes_v1/federativeEntity.js new file mode 100644 index 0000000000000000000000000000000000000000..661907c54256a9b8ef48c4d26401d01269251042 --- /dev/null +++ b/src/libs/routes_v1/federativeEntity.js @@ -0,0 +1,646 @@ +/* +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('/education_degree_entity', (req, res, next) => { + req.result = [] + + for (let i = 1; i <= 4; i++) { + req.result.push({ + id: i, name: id2str.educationDegreeEntity(i) + }); + } + next(); +}, response('education_degree_entity')); + +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_entity', (req, res, next) => { + req.result = [] + + for (let i = 1; i <= 2; i++) { + req.result.push({ + id: i, name: id2str.specialEducationEntity(i) + }); + } + + next(); +}, response('special_education_entity')); + + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'region', + table: 'regiao', + tableField: ['nome', 'id'], + resultField: ['region_name', 'region_id'], + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'cod_reg', + foreignTable: 'docentes_sinopse' + } +}).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: 'docentes_sinopse', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + field: 'ano_censo', + }, +}).addValue({ + name: 'max_year', + table: 'docentes_sinopse', + 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: 'cod_uf', + foreignTable: 'docentes_sinopse' + } +}, 'dims').addValueToField({ + name: 'state', + table: 'estado', + tableField: 'nome', + resultField: 'state_name', + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'cod_uf', + foreignTable: 'docentes_sinopse' + } +}, 'filter').addValueToField({ + name: 'city', + table: 'municipio', + tableField: ['nome', 'id'], + resultField: ['city_name', 'city_id'], + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'cod_mun', + foreignTable: 'docentes_sinopse' + } +}, 'dims').addValueToField({ + name: 'city', + table: 'municipio', + tableField: 'nome', + resultField: 'city_name', + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'cod_mun', + foreignTable: 'docentes_sinopse' + } +}, 'filter').addValueToField({ + name: 'school', + table: 'docentes_sinopse', + 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: 'docentes_sinopse', + tableField: 'localizacao_id', + resultField: 'locale_id', + where: { + relation: '=', + type: 'integer', + field: 'localizacao_id' + } +}, 'dims').addValueToField({ + name: 'school_id', + table: 'docentes_sinopse', + 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: 'docentes_sinopse', + 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: 'docentes_sinopse', + tableField: 'localizacao_id', + resultField: 'location_id', + where: { + relation: '=', + type: 'integer', + field: 'localizacao_id' + } +}); + +federativeEntityApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + let whereRule = ''; + const filtersObject = {} + + req.query.filter.split(',').forEach((filter) => { + let [key, value] = filter.split(':'); + filtersObject[key] = Number(JSON.parse(value)); + }) + + if (req.query.filter && req.query.filter.includes('city')) { + whereRule = 'docentes_sinopse.cod_mun = ' + filtersObject.city; + } + else if (req.query.filter && req.query.filter.includes('state')) { + whereRule = 'docentes_sinopse.cod_uf = ' + filtersObject.state + + ((req.query.dims && req.query.dims.includes('city')) ? '' : ' AND docentes_sinopse.cod_mun = 0'); + } + else if (req.query.filter && req.query.filter.includes('region')) { + whereRule = 'docentes_sinopse.cod_reg = ' + filtersObject.region + + ((req.query.dims !== undefined && req.query.dims.includes('state')) + ? ' AND docentes_sinopse.cod_mun = 0' + : (req.query.dims !== undefined && req.query.dims.includes('city')) + ? '' + : ' AND docentes_sinopse.cod_uf = 0'); + + } + else { + whereRule = (req.query.dims && req.query.dims.includes('region')) + ? 'docentes_sinopse.cod_uf = 0' + : (req.query.dims && req.query.dims.includes('state')) + ? 'docentes_sinopse.cod_mun = 0' + : (req.query.dims && req.query.dims.includes('city')) + ? '' + : 'docentes_sinopse.cod_reg = 0' + + } + + console.log(whereRule); + + 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(whereRule); + } + 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(whereRule); + } + else if (req.query.dims && req.query.dims.includes('special_education_entity')) + { + 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(whereRule); + } + 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(whereRule); + } + 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(whereRule); + } + else if (req.query.dims && req.query.dims.includes('education_degree_entity')) + { + req.sql.from('docentes_sinopse') + .field('SUM(docentes_sinopse.num_doc_esc_en_fund)', 'total_num_doc_esc_en_fund') + .field('SUM(docentes_sinopse.num_doc_esc_en_medio)', 'total_num_doc_esc_en_medio') + .field('SUM(docentes_sinopse.num_doc_esc_grad_com_licenciatura)', 'total_num_doc_esc_grad_com_licenciatura') + .field('SUM(docentes_sinopse.num_doc_esc_grad_sem_licenciatura)', 'total_num_doc_esc_grad_sem_licenciatura') + .field('docentes_sinopse.ano_censo', 'year') + .group('docentes_sinopse.ano_censo') + .order('docentes_sinopse.ano_censo') + .where(whereRule); + } + 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(whereRule); + } + 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(whereRule); + } + 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(whereRule); + } + 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(whereRule); + } + 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(whereRule); + } + else if ((req.query.dims && req.query.dims.includes('state')) || (req.query.filter && req.query.filter.includes('state'))) { + req.sql.from('docentes_sinopse') + .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') + .where(whereRule); + } + else if ((req.query.dims && req.query.dims.includes('region')) || (req.query.filter && req.query.filter.includes('region'))) { + req.sql.from('docentes_sinopse') + .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') + .where(whereRule); + } + else { + req.sql.from('docentes_sinopse') + .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') + .where(whereRule); + } + next(); +}, query, aggregateData, id2str.transform(false), response('federative_entity')); + +module.exports = federativeEntityApp; diff --git a/src/libs/routes_v1/rateSchoolNew.js b/src/libs/routes_v1/rateSchoolNew.js index a6ae0218aaa01e00cb695ac59a690a836a532d2c..237edfa1d5fa2d3033ded9b103452b5f01ba1e1b 100644 --- a/src/libs/routes_v1/rateSchoolNew.js +++ b/src/libs/routes_v1/rateSchoolNew.js @@ -308,20 +308,49 @@ rqf.addField({ } }); -// The queries are matched and the total is calculated -function matchQueries(attendsSchoolObj, populationObj) { - let match = []; - - for (let i = 0; i < attendsSchoolObj.length; i++) { - let newObj = attendsSchoolObj[i]; - - newObj.total = (attendsSchoolObj[i].total / populationObj[i].total) * 100; +/* + The queries are matched and the total is calculated. + This function is necessary to match the results of the + 2 queries with the right pair. In some queries, the result + doesn't exist in one of the 2, so, we need to run this algorithm + to match them right. +*/ - newObj.age_range_id = newObj.faixa_etaria; - delete newObj.faixa_etaria; +function matchQueries(queryPartial, queryTotal) { + let match = []; + queryTotal.forEach((result) => { + let newObj = {}; + let keys = Object.keys(result); + keys.forEach((key) => { + newObj[key] = result[key]; + }); + let index = keys.indexOf('total'); + if(index > -1) keys.splice(index, 1); + let objMatch = null; + + for(let i = 0; i < queryPartial.length; ++i) { + let partial = queryPartial[i]; + let foundMatch = true; + for(let j = 0; j < keys.length; ++j) { + let key = keys[j]; + if(partial[key] !== result[key]) { + foundMatch = false; + break; + } + } + if(foundMatch) { + objMatch = partial; + break; + } + } - match.push(newObj); - } + if(objMatch) { + newObj.denominator = result.total; + newObj.partial = objMatch.total; + newObj.total = (objMatch.total / result.total) * 100; + match.push(newObj); + } + }); return match; } diff --git a/src/libs/routes_v1/uniLocalOfferAggregate.js b/src/libs/routes_v1/uniLocalOfferAggregate.js new file mode 100644 index 0000000000000000000000000000000000000000..f50afff10d25cb8e73f9399dfef810795ad01bc1 --- /dev/null +++ b/src/libs/routes_v1/uniLocalOfferAggregate.js @@ -0,0 +1,124 @@ +/* +Copyright (C) 2024 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 uniLocalOfferAggregateApp = express.Router(); + +const libs = `${process.cwd()}/libs`; + +const query = require(`${libs}/middlewares/query`).query; + +const response = require(`${libs}/middlewares/response`); + +const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); + +const config = require(`${libs}/config`); + +const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware; + +let rqf = new ReqQueryFields(); + +uniLocalOfferAggregateApp.use(cache('15 day')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'min_year', + table: 'curso_superior_agregado', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'max_year', + table: 'curso_superior_agregado', + tableField: '', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'region', + table: 'curso_superior_agregado', + tableField: 'cod_reg', + resultField: 'region_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_reg' + } +}).addValue({ + name: 'state', + table: 'estado', + tableField: ['id', 'nome'], + resultField: ['state_id', 'state_nome'], + where: { + relation: '=', + type: 'integer', + field: 'id', + }, + join: { + primary: 'id', + foreign: 'cod_uf', + foreignTable: 'curso_superior_agregado' + } +}).addValue({ + name: 'city', + table: 'municipio', + tableField: ['id', 'nome'], + resultField: ['city_id', 'city_name'], + where: { + relation: '=', + type: 'integer', + field: 'id', + table: 'municipio' + }, + join: { + primary: 'id', + foreign: 'cod_mun', + foreignTable: 'curso_superior_agregado' + } +}); + +uniLocalOfferAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + req.sql.from('curso_superior_agregado') + .field('DISTINCT curso_superior_agregado.cod_ies', 'id') + .field('ies_ens_superior.nome_ies', 'name') + .field('curso_superior_agregado.cod_mun', 'city_id') + .field('curso_superior_agregado.cod_uf', 'state_id') + .field('curso_superior_agregado.cod_reg', 'region_id') + .join('ies_ens_superior', null, 'curso_superior_agregado.cod_ies = ies_ens_superior.cod_ies and curso_superior_agregado.ano_censo = ies_ens_superior.ano_censo') + .order('curso_superior_agregado.cod_ies') + next(); +}, query, response('uni_offer_aggregate')); + +module.exports = uniLocalOfferAggregateApp; \ No newline at end of file diff --git a/src/libs/routes_v1/universityLocalOffer.js b/src/libs/routes_v1/universityLocalOffer.js index 535094c492915b6b3d38a5e02a267a4196910c36..88ed5ac03989c127d9624e55ced1d30c63858050 100644 --- a/src/libs/routes_v1/universityLocalOffer.js +++ b/src/libs/routes_v1/universityLocalOffer.js @@ -84,7 +84,7 @@ rqf.addField({ }, join: { primary: 'nome', - foreign: 'nome_regiao_ies', + foreign: 'nome_regiao', foreignTable: 'localoferta_ens_superior' }