diff --git a/src/libs/convert/initialTraining.js b/src/libs/convert/initialTraining.js new file mode 100644 index 0000000000000000000000000000000000000000..3eff60f0021232d9203be255edb495e191d079c4 --- /dev/null +++ b/src/libs/convert/initialTraining.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 initialTraining(id) { + switch (id) { + case 1: + return 'Sem formação mínima'; + case 2: + return 'Ensino Médio na modalidade normal'; + case 3: + return 'Superior bacharelado ou tecnólogo'; + case 4: + return 'Superior com licenciatura ou complementação pedagógica'; + } +}; diff --git a/src/libs/convert/posTraining.js b/src/libs/convert/posTraining.js new file mode 100644 index 0000000000000000000000000000000000000000..12776cd63bfec402082d427db6a1519a8a557b2c --- /dev/null +++ b/src/libs/convert/posTraining.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 posTraining(id) { + switch (id) { + case 1: + return 'Sem pós-graduação'; + case 2: + return 'Especialização'; + case 3: + return 'Mestrado'; + case 4: + return 'Doutorado'; + } +}; diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index 8a4b6cc3401d11da325c6f3566e51755f742cf98..cb9a18d6303bf9226028ddbc246a76e01b1ec2b1 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -86,6 +86,8 @@ const arrangement = require(`${libs}/convert/arrangement`); const nightTime = require(`${libs}/convert/nightTime`); const discipline = require(`${libs}/convert/discipline`); const finishUniversity = require(`${libs}/convert/finishUniversity`); +const initialTraining = require(`${libs}/convert/initialTraining`); +const posTraining = require(`${libs}/convert/posTraining`); const ids = { gender_id: gender, @@ -163,7 +165,9 @@ const ids = { transport_id: transport, arrangement_id: arrangement, discipline: discipline, - finish_id: finishUniversity + finish_id: finishUniversity, + initial_training_id: initialTraining, + pos_training_id: posTraining }; function transform(removeId=false) { @@ -268,5 +272,7 @@ module.exports = { arrangement, nightTime, discipline, - finishUniversity + finishUniversity, + initialTraining, + posTraining }; diff --git a/src/libs/routes/api.js b/src/libs/routes/api.js index bb690b86cc863b79d91ed9e02cd519c99d1ed05f..c96266b09f260fb65813ea5c71ca0aeef4a9347c 100644 --- a/src/libs/routes/api.js +++ b/src/libs/routes/api.js @@ -126,6 +126,8 @@ const location = require(`${libs}/routes/location`); const disciplines = require(`${libs}/routes/disciplines`); +const universityLocalOffer = require(`${libs}/routes/universityLocalOffer`); + api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API is running' }); }); @@ -180,4 +182,5 @@ api.use('/mesoregion', mesoregion); api.use('/microregion', microregion); api.use('/location', location); api.use('/disciplines', disciplines); +api.use('/universityLocalOffer', universityLocalOffer); module.exports = api; diff --git a/src/libs/routes/disciplines.js b/src/libs/routes/disciplines.js index 8da7128fc9275700be14ffdd3f71f6be49057ad7..2c5a9c968a71e1e54f025deee19a71c54978654a 100644 --- a/src/libs/routes/disciplines.js +++ b/src/libs/routes/disciplines.js @@ -479,13 +479,13 @@ disciplinesApp.get('/', rqf.parse(), (req, res, next) => { .field('SUM(adequacao_lingua_portuguesa)', 'total_suitable_lingua_portuguesa') .field('SUM(lingua_inglesa_not_null)', 'total_lingua_inglesa') - .field('SUM(adequacao_lingua_ingles)', 'total_suitable_lingua_inglesa') + .field('SUM(adequacao_lingua_inglesa)', 'total_suitable_lingua_inglesa') .field('SUM(lingua_espanhola_not_null)', 'total_lingua_espanhola') - .field('SUM(adequacao_lingua_espanhol)', 'total_suitable_lingua_espanhola') + .field('SUM(adequacao_lingua_espanhola)', 'total_suitable_lingua_espanhola') .field('SUM(lingua_francesa_not_null)', 'total_lingua_francesa') - .field('SUM(adequacao_lingua_frances)', 'total_suitable_lingua_francesa') + .field('SUM(adequacao_lingua_francesa)', 'total_suitable_lingua_francesa') .field('SUM(lingua_outra_not_null)', 'total_lingua_outra') .field('SUM(adequacao_lingua_outra)', 'total_suitable_lingua_outra') diff --git a/src/libs/routes/teacher.js b/src/libs/routes/teacher.js index 2b2037c4208b1d68f3fe498613918b4362bb3bdb..b2a4dc4ea23b1bac3d9085badf2c1676bb0bafae 100644 --- a/src/libs/routes/teacher.js +++ b/src/libs/routes/teacher.js @@ -182,6 +182,28 @@ teacherApp.get('/ethnic_group', (req, res, next) => { next(); }, response('ethnic_group')); +teacherApp.get('/initial_training', (req, res, next) => { + req.result = []; + for(let i = 1; i <=4; ++i) { + req.result.push({ + id: i, + name: id2str.initialTraining(i) + }); + } + next(); +}, response('initial_training')); + +teacherApp.get('/pos_training', (req, res, next) => { + req.result = []; + for(let i = 1; i <= 4; ++i) { + req.result.push({ + id: i, + name: id2str.posTraining(i) + }); + } + next(); +}, response('pos_training')); + rqf.addField({ name: 'filter', field: false, @@ -432,6 +454,26 @@ rqf.addField({ type: 'integer', field: 'cor_raca' } +}).addValue({ + name: 'initial_training', + table: 'docente', + tableField: 'formacao_inicial_docente', + resultField: 'initial_training_id', + where: { + relation: '=', + type: 'integer', + field: 'formacao_inicial_docente' + } +}).addValue({ + name: 'pos_training', + table: 'docente', + tableField: 'formacao_pos_docente', + resultField: 'pos_training_id', + where: { + relation: '=', + type: 'integer', + field: 'formacao_pos_docente' + } }); teacherApp.get('/', rqf.parse(), (req, res, next) => { diff --git a/src/libs/routes/universityEnrollment.js b/src/libs/routes/universityEnrollment.js index 7a9f5b3f7d27b6d226f745932c256e25f5e2b068..d1670f7c0d6994a94e389bb99b4a393e4219f203 100644 --- a/src/libs/routes/universityEnrollment.js +++ b/src/libs/routes/universityEnrollment.js @@ -373,6 +373,16 @@ rqf.addField({ type: 'integer', field: 'cod_ies' } +}).addValue({ + name: 'universityLocalOffer', + table: '@', + tableField: ['cod_ies', 'nome_ies'], + resultField: ['university_id', 'university_name'], + where: { + relation: '=', + type: 'integer', + field: 'cod_ies' + } }).addValue({ name:'upper_adm_dependency', table: '@', @@ -641,7 +651,7 @@ rqf.addField({ universityEnrollmentApp.get('/', rqf.parse(), (req, res, next) => { if ("localoffer" in req.dims) { - if ("university" in req.dims) { + if ("university" in req.dims || "universityLocalOffer" in req.dims) { req.sql.from('localoferta_ens_superior_matricula') .field('curso_ens_superior.ano_censo', 'year') .field('COUNT(localoferta_ens_superior.cod_local_oferta)', 'total') @@ -668,7 +678,7 @@ universityEnrollmentApp.get('/', rqf.parse(), (req, res, next) => { .field('localoferta_ens_superior_matricula.ano_censo', 'year') .group('localoferta_ens_superior_matricula.ano_censo') .order('localoferta_ens_superior_matricula.ano_censo') - } else if ("university" in req.dims) { + } else if ("university" in req.dims || "universityLocalOffer" in req.dims) { req.sql.from('aluno_ens_superior') .field('COUNT(*)', 'total') .field("'Brasil'", 'name') @@ -680,14 +690,12 @@ universityEnrollmentApp.get('/', rqf.parse(), (req, res, next) => { .order('aluno_ens_superior.cod_ies') .order('aluno_ens_superior.ano_censo') } else { - req.sql.from('aluno_ens_superior') + req.sql.from('localoferta_ens_superior_matricula') .field('COUNT(*)', 'total') .field("'Brasil'", 'name') - .field('aluno_ens_superior.ano_censo', 'year') - .where('aluno_ens_superior.cod_aluno_situacao = 2 OR aluno_ens_superior.cod_aluno_situacao = 6 OR aluno_ens_superior.matriculado = 1') - .where('aluno_ens_superior.cod_nivel_academico = 1') - .group('aluno_ens_superior.ano_censo') - .order('aluno_ens_superior.ano_censo') + .field('localoferta_ens_superior_matricula.ano_censo', 'year') + .group('localoferta_ens_superior_matricula.ano_censo') + .order('localoferta_ens_superior_matricula.ano_censo') } next(); }, rqf.build(), query, id2str.transform(), addMissing(rqf), response('universityEnrollment')); diff --git a/src/libs/routes/universityLocalOffer.js b/src/libs/routes/universityLocalOffer.js new file mode 100644 index 0000000000000000000000000000000000000000..4a594f62d7c132dd875a7f334df8b5728905a25b --- /dev/null +++ b/src/libs/routes/universityLocalOffer.js @@ -0,0 +1,145 @@ +''/* +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 universityLocalOfferApp = 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 id2str = require(`${libs}/middlewares/id2str`); + +const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); + +const request = require(`request`); + +const config = require(`${libs}/config`); + +const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware; + +const addMissing = require(`${libs}/middlewares/addMissing`); + +let rqf = new ReqQueryFields(); + +universityLocalOfferApp.use(cache('15 day')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'city', + table: 'municipio', + tableField: ['nome', 'id'], + resultField: ['city_name', 'city_id'], + where: { + relation: '=', + type: 'integer', + field: 'cod_municipio', + table: 'localoferta_ens_superior' + }, + join: { + primary: 'id', + foreign: 'cod_municipio', + foreignTable: 'localoferta_ens_superior' + } +}).addValue({ + name: 'region', + table: 'regiao', + tableField: ['nome', 'id'], + resultField: ['region_name', 'region_id'], + where: { + relation: 'LIKE', + type: 'string', + field: 'id' + }, + join: { + primary: 'nome', + foreign: 'nome_regiao_ies', + foreignTable: 'localoferta_ens_superior' + } + +}).addValue({ + name: 'min_year', + table: 'localoferta_ens_superior', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + table: 'localoferta_ens_superior', + field: 'ano_censo' + } +}).addValue({ + name: 'max_year', + table: 'localoferta_ens_superior', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + table: 'localoferta_ens_superior', + field: 'ano_censo' + } +}).addValue({ + name: 'state', + table: 'estado', + tableField: ['nome', 'id'], + resultField: ['state_name', 'state_id'], + where: { + relation: '=', + type: 'integer', + field: 'cod_uf', + table: 'localoferta_ens_superior' + }, + join: { + primary: 'id', + foreign: 'cod_uf', + foreignTable: 'localoferta_ens_superior' + } +}); + +universityLocalOfferApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + req.sql.from('localoferta_ens_superior') + .field('distinct localoferta_ens_superior.cod_ies', 'id') + .field('localoferta_ens_superior.ano_censo', 'year') + .field('ies_ens_superior.nome_ies', 'name') + .field('localoferta_ens_superior.cod_uf', 'state_id') + .field('localoferta_ens_superior.cod_municipio', 'city_id') + .field('localoferta_ens_superior.cod_regiao', 'region_id') + .join('ies_ens_superior', null, 'localoferta_ens_superior.cod_ies=ies_ens_superior.cod_ies AND localoferta_ens_superior.ano_censo=ies_ens_superior.ano_censo') + .where('localoferta_ens_superior.nome IS NOT NULL AND ies_ens_superior.nome_ies IS NOT NULL'); + next(); + +}, query, response('universityLocalOfferApp')); + +module.exports = universityLocalOfferApp;