diff --git a/CHANGELOG.md b/CHANGELOG.md index ad2d90ae546c79c8e7cbba04bfc4125f841bb2dc..a25bd9818b975f668f18614a10835ca1353603b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,146 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 1.11.17 - 2019-10-08 +## Changed +- Fix query\_exec + +## 1.11.16 - 2019-10-30 +## Changed +- University Teacher updated + +## 1.11.15 - 2019-10-16 +## Changed +- Fix addMissing for classCount route + +## 1.11.14 - 2019-10-13 +## Changed +- OCDE updated + +## 1.11.13 - 2019-09-11 +## Changed +- Classroom with dim location and city filter, will always return both locations + +## 1.11.12 - 2019-09-10 +## Changed +- Changed classroom filters to match classroomCount + +## 1.11.11 - 2019-09-09 +## Changed +- Changed classroomCount filters + +## 1.11.10 - 2019-08-23 +## Changed +- Removed year limitation +- Updated existing variables + +## 1.11.9 - 2019-07-25 +## Changed +- Course count order fix +- Course count missing fix + +## 1.11.8 = 2019-07-19 +## Changed +- Remove /user route + +## 1.11.7 - 2019-07-12 +## Changed +- EnrollmentProjection now returns empty values with 0 + +## 1.11.6 - 2019-07-11 +## Changed +- Return haveSportsCourtCoverage and haveCourtyardCoverage = [] in route school_infrastructure + +## 1.11.5 - 2019-07-09 +## Changed + - Fix integral time + - Fix match queries in school_infrastructure + ## 2019-07-03 ### Changed - Remove mongoose dependency so it can be used in SMPPIR +## 1.11.4 - 2019-06-17 +## Changed +- Changed enrollment variable +- Added location and latitude to state and city +- Changed courseCount variables +- Removed 'Not classified' from teacher + +## 1.11.3 - 2019-06-17 +## Changed +- Changed variables from university +- Removed year limitation from university + +## 1.11.2 - 2019-06-17 +## Changed +- transport now uses an aggregate table + +## 1.11.1 - 2019-06-10 +## Changed +- ClassroomCount now uses an aggregate table + +## 1.11.0 - 2019-05-24 +## Changed +- Add university teacher indicator for 2017 + +## 1.10.5 - 2019-05-23 +## Changed +- Revert api.js + +## 1.10.4 - 2019-05-23 +## Changed +- Fix order in enrollment indicator +## Added +- Added university enrollment indicator +- Added course count indicator + +## 1.10.3 - 2019-05-22 +## Changed +- Fix schoolInfrastructure.js + +## 1.10.2 - 2019-05-10 +## Changed +- Fix api.js + +## 1.10.0 - 2019-05-10 +## Added +- Added university indicator + +## 1.9.8 - 2019-08-02 +## Changed +- Fix bug duplicate city name in classroom count + +## 1.9.7 - 2019-05-02 +## Changed +- Fix enrollment projection +- Fix enrollment number in classroom count +- Fix error in class count + +## 1.9.6 - 2019-04-02 +## Changed +- Fix null in integral time + +## 1.9.5 - 2019-03-15 +## Changed +- Fix join's in class count route + +## 1.9.4 - 2019-03-12 +## Changed +- Change docente.id to docente.id_docente + +## 1.9.3 - 2019-03-12 +## Changed +- Fix addMissing function + +## 1.9.2 - 2019-02-20 +## Changed +- Fix location variable in table + +## 1.9.1 - 2019-02-14 +## Changed +- Fix join's in financial route + ## 1.9.0 - 2018-11-24 ## Changed - Fix school infrastructure results when partial or needed schools query return empty diff --git a/package.json b/package.json index f603817a79d175c397ddb03a822a8537dd0d30a2..541094f97ca0057b75f9aa94238597972d2e1a92 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "passport-http-bearer": "^1.0.1", "passport-oauth2-client-password": "^0.1.2", "request": "^2.88.0", + "sqlstring": "^2.3.1", "squel": "^5.12.2", "winston": "^2.4.4" }, diff --git a/src/libs/convert/academicLevel.js b/src/libs/convert/academicLevel.js new file mode 100644 index 0000000000000000000000000000000000000000..3f76bc115a7e7897ef7aea4967fa872d07409bf2 --- /dev/null +++ b/src/libs/convert/academicLevel.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 . +*/ + +module.exports = function academicLevel(id) { + switch (id) { + case 1: + return 'Bacharelado'; + case 2: + return 'Licenciatura'; + case 3: + return 'Tecnológico'; + default: + return 'Não classificada'; + } +}; diff --git a/src/libs/convert/academicOrganization.js b/src/libs/convert/academicOrganization.js new file mode 100644 index 0000000000000000000000000000000000000000..14611d15af395aa85678efff3d38ad9d08692d53 --- /dev/null +++ b/src/libs/convert/academicOrganization.js @@ -0,0 +1,36 @@ +/* +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 . +*/ + +module.exports = function academicOrganization(id) { + switch (id) { + case 1: + return 'Universidade'; + case 2: + return 'Centro Universitário'; + case 3: + return 'Faculdade'; + case 4: + return 'Instituto Federal de Educação, Ciência e Tecnologia'; + case 5: + return 'Centro Federal de Educação Tecnológica'; + default: + return 'Não classificada'; + } +}; diff --git a/src/libs/convert/ageStudentCode.js b/src/libs/convert/ageStudentCode.js new file mode 100644 index 0000000000000000000000000000000000000000..450c93610b221fc7af6334690571bba595eee5b3 --- /dev/null +++ b/src/libs/convert/ageStudentCode.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 . +*/ + +module.exports = function ageStudentCode(id) { + switch (id) { + case 1: + return 'Menor que 18 anos'; + case 2: + return 'Entre 18 anos e 24 anos'; + case 3: + return 'Entre 25 anos e 29 anos'; + case 4: + return 'Entre 30 anos e 34 anos'; + case 5: + return 'Entre 35 anos e 39 anos'; + case 6: + return 'Maior que 39 anos'; + default: + return 'Não classificado'; + } +}; diff --git a/src/libs/convert/ethnicGroupIES.js b/src/libs/convert/ethnicGroupIES.js new file mode 100644 index 0000000000000000000000000000000000000000..a57150fcc30d5e46df45ba9c1cd7d97761fc612f --- /dev/null +++ b/src/libs/convert/ethnicGroupIES.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 . +*/ + +module.exports = function ethnicGroupIES(id) { + switch (id) { + case 0: + return 'Aluno não quis declarar cor/raça'; + case 1: + return 'Branca'; + case 2: + return 'Preta'; + case 3: + return 'Parda'; + case 4: + return 'Amarela'; + case 5: + return 'Indígena'; + default: + return 'Não dispõe da informação (Não resposta)'; + } +}; diff --git a/src/libs/convert/ethnicGroupTeacherIES.js b/src/libs/convert/ethnicGroupTeacherIES.js new file mode 100644 index 0000000000000000000000000000000000000000..7db2936ccc04200a58a7680f32c4a0d2c3122aaa --- /dev/null +++ b/src/libs/convert/ethnicGroupTeacherIES.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 . +*/ + +module.exports = function ethnicGroupTeacherIES(id) { + switch (id) { + case 0: + return 'Docente não quis declarar cor/raça'; + case 1: + return 'Branca'; + case 2: + return 'Preta'; + case 3: + return 'Parda'; + case 4: + return 'Amarela'; + case 5: + return 'Indígena'; + default: + return 'Não dispõe da informação (Não resposta)'; + } +}; diff --git a/src/libs/convert/genderIES.js b/src/libs/convert/genderIES.js new file mode 100644 index 0000000000000000000000000000000000000000..8eba4fe45cfa21daaaa0d8ea96accb894d8e7453 --- /dev/null +++ b/src/libs/convert/genderIES.js @@ -0,0 +1,30 @@ +/* +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 . +*/ + +module.exports = function genderIES(id) { + switch(id) { + case 1: + return 'Feminino'; + case 2: + return 'Masculino'; + default: + return 'Não declarado'; + } +}; diff --git a/src/libs/convert/integralTime.js b/src/libs/convert/integralTime.js index b231be33d51aca64227301d3eb4d05d10808b6aa..11fd23850e2b51a6bce33ccbec160f0980ec25f8 100644 --- a/src/libs/convert/integralTime.js +++ b/src/libs/convert/integralTime.js @@ -19,10 +19,12 @@ along with simcaq-node. If not, see . */ module.exports = function integralTime(id) { - if (id == null) - return 'Não se aplica (semi presencial e EaD)'; - else if (id == false) - return 'Não'; - else if (id == true) - return 'Sim'; + switch (id) { + case true: + return 'Sim'; + case false: + return 'Não'; + default: + return 'Não se aplica (semi presencial e EaD)'; + } }; diff --git a/src/libs/convert/ocdeDetailed.js b/src/libs/convert/ocdeDetailed.js new file mode 100644 index 0000000000000000000000000000000000000000..e83dc4d933dc997e97c9ded6799bbc72f93ae376 --- /dev/null +++ b/src/libs/convert/ocdeDetailed.js @@ -0,0 +1,183 @@ +/* +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 . +*/ +module.exports = function ocdeDetailed(id) { + switch (id) { + case 142: + return 'Ciências da educação'; + case 144: + return 'Formação de professor da educação básica'; + case 145: + return 'Formação de professor de matérias específicas'; + case 146: + return 'Formação de professor de disciplinas profissionais'; + case 210: + return 'Artes (cursos gerais)'; + case 211: + return 'Belas artes'; + case 212: + return 'Música e artes cênicas'; + case 213: + return 'Técnicas audiovisuais e produção de mídia'; + case 214: + return 'Design e estilismo'; + case 215: + return 'Artesanato'; + case 220: + return 'Humanidades e letras (cursos gerais)'; + case 221: + return 'Religião e teologia'; + case 222: + return 'Línguas e culturas estrangeiras'; + case 223: + return 'Língua materna (vernácula)'; + case 225: + return 'História e arqueologia'; + case 226: + return 'Filosofia e ética'; + case 310: + return 'Ciências sociais e comportamentais (cursos gerais)'; + case 311: + return 'Psicologia'; + case 312: + return 'Sociologia e estudos culturais'; + case 313: + return 'Ciência política e educação cívica'; + case 314: + return 'Economia'; + case 321: + return 'Jornalismo e reportagem'; + case 322: + return 'Biblioteconomia, informação, arquivos'; + case 340: + return 'Comércio e administração (cursos gerais)'; + case 341: + return 'Vendas em atacado e varejo'; + case 342: + return 'Marketing e publicidade'; + case 343: + return 'Finanças, bancos, seguros'; + case 344: + return 'Contabilidade e tributação'; + case 345: + return 'Gerenciamento e administração'; + case 346: + return 'Secretariado e trabalhos de escritório'; + case 380: + return 'Direito'; + case 420: + return 'Ciências (cursos gerais)'; + case 421: + return 'Biologia e bioquímica'; + case 422: + return 'Ciências ambientais'; + case 440: + return 'Ciências físicas (cursos gerais)'; + case 441: + return 'Física'; + case 442: + return 'Química'; + case 443: + return 'Ciências da terra'; + case 461: + return 'Matemática'; + case 462: + return 'Estatística'; + case 481: + return 'Ciência da computação'; + case 482: + return 'Uso do computador'; + case 483: + return 'Processamento da informação'; + case 520: + return 'Engenharia e profissões de engenharia (cursos gerais)'; + case 521: + return 'Engenharia mecânica e metalurgia (trabalhos com metais)'; + case 522: + return 'Eletricidade e energia'; + case 523: + return 'Eletrônica e automação'; + case 524: + return 'Química e engenharia de processos'; + case 525: + return 'Veículos a motor, construção naval e aeronáutica'; + case 540: + return 'Fabricação e processamento (cursos gerais)'; + case 541: + return 'Processamento de alimentos'; + case 542: + return 'Têxteis, roupas, calçados, couros'; + case 543: + return 'Materiais (madeira, papel, plástico, vidro)'; + case 544: + return 'Mineração e extração'; + case 581: + return 'Arquitetura e urbanismo'; + case 582: + return 'Engenharia civil e de construção'; + case 621: + return 'Produção agrícola e pecuária'; + case 622: + return 'Horticultura'; + case 623: + return 'Engenharia florestal - silvicultura'; + case 624: + return 'Recursos pesqueiros'; + case 641: + return 'Veterinária'; + case 720: + return 'Saúde (cursos gerais)'; + case 721: + return 'Medicina'; + case 723: + return 'Enfermagem e atenção primária (assistência básica)'; + case 724: + return 'Odontologia'; + case 725: + return 'Tecnologias de diagnóstico e tratamento médico'; + case 726: + return 'Terapia e reabilitação'; + case 727: + return 'Farmácia'; + case 762: + return 'Serviço social e orientação'; + case 811: + return 'Hotelaria, restaurantes e serviços de alimentação'; + case 812: + return 'Viagens, turismo e lazer'; + case 813: + return 'Esportes'; + case 814: + return 'Ciências domésticas'; + case 815: + return 'Serviços de beleza'; + case 840: + return 'Transportes e serviços (cursos gerais)'; + case 850: + return 'Proteção ambiental (cursos gerais)'; + case 861: + return 'Proteção de pessoas e de propriedades'; + case 862: + return 'Saúde e segurança do trabalho'; + case 863: + return 'Setor militar e de defesa'; + default: + return 'Não classificada'; + } +}; \ No newline at end of file diff --git a/src/libs/convert/ocdeGeral.js b/src/libs/convert/ocdeGeral.js new file mode 100644 index 0000000000000000000000000000000000000000..70671edb3dbbb1083f10e8953c886a2a85bf29c4 --- /dev/null +++ b/src/libs/convert/ocdeGeral.js @@ -0,0 +1,44 @@ +/* +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 . +*/ + +module.exports = function ocdeGeral(id) { + switch (id) { + case 0: + return 'Área básica'; + case 1: + return 'Educação'; + case 2: + return 'Humanidades e artes'; + case 3: + return 'Ciências sociais, negócios e direito'; + case 4: + return 'Ciências, matemática e computação'; + case 5: + return 'Engenharia, produção e construção'; + case 6: + return 'Agricultura e veterinária'; + case 7: + return 'Saúde e bem estar social'; + case 8: + return 'Serviços'; + default: + return 'Não classificada'; + } +}; diff --git a/src/libs/convert/ocdeSpecific.js b/src/libs/convert/ocdeSpecific.js new file mode 100644 index 0000000000000000000000000000000000000000..0133fa97a143dc342799c3a8b3b68c4d6dbb5fa5 --- /dev/null +++ b/src/libs/convert/ocdeSpecific.js @@ -0,0 +1,72 @@ +/* +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 . +*/ + +module.exports = function ocdeSpecific(id) { + switch (id) { + case 1: + return 'Área básica de cursos'; + case 14: + return 'Formação de professor e ciências da educação'; + case 21: + return 'Artes'; + case 22: + return 'Humanidades e letras'; + case 31: + return 'Ciências sociais e comportamentais'; + case 32: + return 'Jornalismo e informação'; + case 34: + return 'Comércio e administração'; + case 38: + return 'Direito'; + case 42: + return 'Ciências da vida'; + case 44: + return 'Ciências físicas'; + case 46: + return 'Matemática e estatística'; + case 48: + return 'Computação'; + case 52: + return 'Engenharia e profissões correlatas'; + case 54: + return 'Produção e processamento'; + case 58: + return 'Arquitetura e construção'; + case 62: + return 'Agricultura, florestas e recursos pasqueiros'; + case 64: + return 'Veterinária'; + case 72: + return 'Saúde'; + case 76: + return 'Serviço social'; + case 81: + return 'Serviços pessoais'; + case 84: + return 'Serviços de transportes (cursos gerais)'; + case 85: + return 'Proteção ambiental'; + case 86: + return 'Serviços de segurança'; + default: + return 'Não classificada'; + } +}; diff --git a/src/libs/convert/schoolType.js b/src/libs/convert/schoolType.js new file mode 100644 index 0000000000000000000000000000000000000000..f485ecb9fabf74e860e34d1d082b0de1eacce36d --- /dev/null +++ b/src/libs/convert/schoolType.js @@ -0,0 +1,30 @@ +/* +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 . +*/ + +module.exports = function studentDeficiency(id) { + switch (id) { + case 1: + return 'Pública'; + case 2: + return 'Privada'; + default: + return 'Não classificado'; + } +}; diff --git a/src/libs/convert/studentDeficiency.js b/src/libs/convert/studentDeficiency.js new file mode 100644 index 0000000000000000000000000000000000000000..c5ad0e0184de5f4eecf1ed889c7ea526f634ee0d --- /dev/null +++ b/src/libs/convert/studentDeficiency.js @@ -0,0 +1,30 @@ +/* +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 . +*/ + +module.exports = function studentDeficiency(id) { + switch (id) { + case 0: + return 'Não'; + case 1: + return 'Sim'; + default: + return 'Não declarado' + } +}; diff --git a/src/libs/convert/teacherSchooling.js b/src/libs/convert/teacherSchooling.js new file mode 100644 index 0000000000000000000000000000000000000000..d31bd2ee9ff6b27fca20e2a2946dea75996e6cbb --- /dev/null +++ b/src/libs/convert/teacherSchooling.js @@ -0,0 +1,36 @@ +/* +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 . +*/ + +module.exports = function teacherSchooling(id) { + switch (id) { + case 1: + return 'Sem graduação'; + case 2: + return 'Graduação'; + case 3: + return 'Especialização'; + case 4: + return 'Mestrado'; + case 5: + return 'Doutorado'; + default: + return 'Não declarado'; + } +}; diff --git a/src/libs/convert/teacherSituation.js b/src/libs/convert/teacherSituation.js new file mode 100644 index 0000000000000000000000000000000000000000..ae77189bdf25b7117c7a0618ed9f8c8aaaa0a71c --- /dev/null +++ b/src/libs/convert/teacherSituation.js @@ -0,0 +1,36 @@ +/* +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 . +*/ + +module.exports = function teacherSituation(id) { + switch (id) { + case 1: + return 'Em exercício'; + case 2: + return 'Afastado para qualificação'; + case 3: + return 'Afastado para exercício em outros órgãos/entidades'; + case 4: + return 'Afastado por outros motivos'; + case 5: + return 'Afastado para tratamento de saúde'; + case 6: + return 'Falecido'; + } +}; diff --git a/src/libs/convert/transport.js b/src/libs/convert/transport.js new file mode 100644 index 0000000000000000000000000000000000000000..f5dbeadbcbfa0c6a90e29514edf288b4c61510c8 --- /dev/null +++ b/src/libs/convert/transport.js @@ -0,0 +1,48 @@ +/* +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 . +*/ + +module.exports = function teacherSituation(id) { + switch (id) { + case 1: + return 'public_transport'; + case 2: + return 'van_and_kombi'; + case 3: + return 'micro_bus'; + case 4: + return 'bus'; + case 5: + return 'bike'; + case 6: + return 'animal_traction'; + case 7: + return 'other_vehicle'; + case 8: + return 'waterway_5_Students'; + case 9: + return 'waterway_15_Students'; + case 10: + return 'waterway_35_Students'; + case 11: + return 'waterway_More_Than_35'; + case 12: + return 'subway_and_train'; + } +}; diff --git a/src/libs/convert/upperAdmDependency.js b/src/libs/convert/upperAdmDependency.js new file mode 100644 index 0000000000000000000000000000000000000000..311475ff7774ba18eac407bf4b78a3d93bf438fb --- /dev/null +++ b/src/libs/convert/upperAdmDependency.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 . +*/ + +module.exports = function upperAdmDependency(id) { + switch (id) { + case 1: + return 'Pública Federal'; + case 2: + return 'Pública Estadual'; + case 3: + return 'Pública Municipal'; + case 4: + return 'Privada com fins lucrativos'; + case 5: + return 'Privada sem fins lucrativos'; + case 6: + return 'Privada confessional'; + case 7: + return 'Especial'; + default: + return 'Não classificada'; + } +}; diff --git a/src/libs/convert/upperEducationMod.js b/src/libs/convert/upperEducationMod.js new file mode 100644 index 0000000000000000000000000000000000000000..47fa9573cf6477f47f7ee435cbd733e9ce3e152b --- /dev/null +++ b/src/libs/convert/upperEducationMod.js @@ -0,0 +1,30 @@ +/* +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 . +*/ + +module.exports = function upperEducationMod(id) { + switch (id) { + case 1: + return 'Presencial'; + case 2: + return 'A Distância'; + default: + return 'Não classificada'; + } +}; diff --git a/src/libs/convert/upperTurn.js b/src/libs/convert/upperTurn.js new file mode 100644 index 0000000000000000000000000000000000000000..b5cac83f361bebe821ef9be7b4a442500bd43985 --- /dev/null +++ b/src/libs/convert/upperTurn.js @@ -0,0 +1,34 @@ +/* +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 . +*/ + +module.exports = function upperTurn(id) { + switch (id) { + case 1: + return 'Matutino'; + case 2: + return 'Vespertino'; + case 3: + return 'Noturno'; + case 4: + return 'Integral'; + default: + return 'Não aplicavel (Ead)'; + } +}; diff --git a/src/libs/convert/workRegime.js b/src/libs/convert/workRegime.js new file mode 100644 index 0000000000000000000000000000000000000000..f03d97a8ec20ff4466b9024e16a38a425c3465b1 --- /dev/null +++ b/src/libs/convert/workRegime.js @@ -0,0 +1,34 @@ +/* +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 . +*/ + +module.exports = function workRegime(id) { + switch (id) { + case 1: + return 'Tempo Integral com dedicação exclusiva'; + case 2: + return 'Tempo Integral sem dedicação exclusiva'; + case 3: + return 'Tempo Parcial'; + case 4: + return 'Horista'; + default: + return 'Não declarado'; + } +}; diff --git a/src/libs/db/query_exec.js b/src/libs/db/query_exec.js index 0437bf24cc75e8343cb99ed4a4d844fcfb2299f5..904a34fe71b804cfa8a79d580f9be260402f2b07 100644 --- a/src/libs/db/query_exec.js +++ b/src/libs/db/query_exec.js @@ -25,6 +25,8 @@ const log = require(`${libs}/log`)(module); const conn = require(`${libs}/db/monet`); +const SqlString = require('sqlstring'); + // Promise that executes an SQL query with optional parameters // ``` // Examples: @@ -37,25 +39,16 @@ const conn = require(`${libs}/db/monet`); // ``` function execSqlQuery(sqlQuery, sqlQueryParams = []) { log.debug(`Executing SQL query '${sqlQuery}' with params '${sqlQueryParams}'`); + let queryStrWithParams = SqlString.format(sqlQuery, sqlQueryParams); return new Promise((resolve, reject) => { - // Prepare statement - conn.prepare(sqlQuery, true).then((dbQuery) => { - // Execute query - dbQuery.exec(sqlQueryParams).then((dbResult) => { - // release resources allocated for the prepared statement - dbQuery.release(); - resolve(dbResult.data); - }).catch((queryError) => { - log.error(`SQL query execution error: ${queryError.message}`); - log.error(`SQL query: ${sqlQuery} with params: ${sqlQueryParams}`); - // release resources allocated for the prepared statement - dbQuery.release(); - reject(new Error(queryError.message)); - }); - }).catch((prepError) => { - log.error(`SQL prepared statement error: ${prepError.message}`); + // Execute query + conn.query(queryStrWithParams, [], true).then((dbResult) => { + // release resources allocated for the prepared statement + resolve(dbResult.data); + },(queryError) => { + log.error(`SQL query execution error: ${queryError.message}`); log.error(`SQL query: ${sqlQuery} with params: ${sqlQueryParams}`); - reject(new Error(prepError.message)); + reject(new Error(queryError.message)); }); }); } diff --git a/src/libs/middlewares/addMissing.js b/src/libs/middlewares/addMissing.js index 6f5ef699eae671c659a66f26bb51e888ad5b62cd..5d0c92fa4b23288c0760b8f303ff8ce834b24cc5 100644 --- a/src/libs/middlewares/addMissing.js +++ b/src/libs/middlewares/addMissing.js @@ -22,68 +22,180 @@ module.exports = function addMissing(rqf){ return (req, res, next) => { let dims = Object.keys(req.dims).filter(i => {return i !== 'size';}); // FIXME: No momento, só funciona para duas dimensões (padrão para o LDE) - if(dims.length != 2) return next(); - if(req.filter.min_year != req.filter.max_year) return next(); + if((dims.length != 2) && (dims.length == 1 && req.filter.min_year == req.filter.max_year)) return next(); + // if(req.filter.min_year != req.filter.max_year) return next(); if(req.result.length === 0) return next(); - let result = req.result; - let dimsValues = {}; - result.forEach((r) => { - dims.forEach((dim) => { - let rqfName = rqf.fieldValues[dim].resultField; - if(typeof dimsValues[rqfName] === 'undefined') { - dimsValues[rqfName] = []; - } - if(dimsValues[rqfName].indexOf(r[rqfName]) === -1) { - dimsValues[rqfName].push(r[rqfName]); - } - }) - }); + if(dims.length == 2) { - let G = {}; - let rqfName = rqf.fieldValues[dims[0]].resultField; - let rqfName2 = rqf.fieldValues[dims[1]].resultField; - G[rqfName] = {}; - dimsValues[rqfName].forEach((value) => { - let secondDim = {}; + let result = req.result; - dimsValues[rqfName2].forEach((dValue) => { - secondDim[dValue] = false; + let dimsValues = {}; + result.forEach((r) => { + dims.forEach((dim) => { + let rqfName = rqf.fieldValues[dim].resultField; + if(typeof dimsValues[rqfName] === 'undefined') { + dimsValues[rqfName] = []; + } + if(dimsValues[rqfName].indexOf(r[rqfName]) === -1) { + dimsValues[rqfName].push(r[rqfName]); + } + }) }); - G[rqfName][value] = {}; - G[rqfName][value][rqfName2] = secondDim; - }); - - result.forEach((r) => { - let resultDim1 = r[rqfName]; - let resultDim2 = r[rqfName2]; - G[rqfName][resultDim1][rqfName2][resultDim2] = true; - }); - - Object.keys(G[rqfName]).forEach((dim1Value) => { - Object.keys(G[rqfName][dim1Value][rqfName2]).forEach((dim2Value) => { - let value = G[rqfName][dim1Value][rqfName2][dim2Value]; - if(!value) { - let newEntry = Object.assign({}, result[0], {[rqfName]: parseInt(dim1Value, 10), [rqfName2]: parseInt(dim2Value, 10), total: 0}); - // result.push(newEntry); - let index = 0; - for(let i = 0; i < result.length; ++i) { - let r = result[i]; - index = i; - if(r[rqfName] > newEntry[rqfName]) break; - if(r[rqfName] == newEntry[rqfName] && r[rqfName2] > newEntry[rqfName2]) break; - } - if (newEntry.dim1Value != undefined && newEntry.dim2Value != undefined) { - let newResult = [...result.slice(0, index), newEntry, ...result.slice(index, result.length)]; - result = newResult; + let G = {}; + let rqfName = rqf.fieldValues[dims[0]].resultField; + let rqfName2 = rqf.fieldValues[dims[1]].resultField; + G[rqfName] = {}; + dimsValues[rqfName].forEach((value) => { + let secondDim = {}; + + dimsValues[rqfName2].forEach((dValue) => { + secondDim[dValue] = false; + }); + + G[rqfName][value] = {}; + G[rqfName][value][rqfName2] = secondDim; + }); + + result.forEach((r) => { + let resultDim1 = r[rqfName]; + let resultDim2 = r[rqfName2]; + G[rqfName][resultDim1][rqfName2][resultDim2] = true; + }); + + Object.keys(G[rqfName]).forEach((dim1Value) => { + Object.keys(G[rqfName][dim1Value][rqfName2]).forEach((dim2Value) => { + let value = G[rqfName][dim1Value][rqfName2][dim2Value]; + if(!value) { + let newEntry = Object.assign({}, result[0], {[rqfName]: parseInt(dim1Value, 10), [rqfName2]: parseInt(dim2Value, 10), total: 0}); + if(newEntry.hasOwnProperty("average")) + newEntry.average = 0; + if(newEntry.hasOwnProperty("median")) + newEntry.median = 0; + if(newEntry.hasOwnProperty("stddev")) + newEntry.stddev = 0; + if(newEntry.hasOwnProperty("first_qt")) + newEntry.first_qt = 0; + if(newEntry.hasOwnProperty("third_qt")) + newEntry.third_qt = 0; + // result.push(newEntry); + let index = 0; + for(let i = 0; i < result.length; ++i) { + let r = result[i]; + index = i; + if(r[rqfName] > newEntry[rqfName]) break; + if(r[rqfName] == newEntry[rqfName] && r[rqfName2] > newEntry[rqfName2]) break; + } + if (newEntry.dim1Value == undefined && newEntry.dim2Value == undefined) { + let newResult = [...result.slice(0, index), newEntry, ...result.slice(index, result.length)]; + result = newResult; + } } - } + }); }); - }); - req.result = result; + req.result = result; + } + + + // Quando é série historica, é uma dimensão com max e min year nos filtros. + else if (dims.length == 1 && req.filter.min_year != req.filter.max_year) { + let result = req.result; + //Pega os valores da dimensão + let dimsValues = {}; + result.forEach((r) => { + + // para cada dimensão + dims.forEach((dim) => { + + // pega o nome da dimensao + let rqfName = rqf.fieldValues[dim].resultField; + if (rqfName[0] == "university_id" || rqfName[1] == "university_id") { + rqfName = "university_id" + }; + let rqfName2 = "year" + //se n existir o array é uma nova dimensão, então cria os arrays para colocar os ids + if(typeof dimsValues[rqfName] === 'undefined') { + dimsValues[rqfName] = []; + } + if(typeof dimsValues[rqfName2] === 'undefined') { + dimsValues[rqfName2] = []; + } + //se já existe, verifica se está no vetor, se n estiver, adiciona o id + if(dimsValues[rqfName].indexOf(r[rqfName]) === -1) { + dimsValues[rqfName].push(r[rqfName]); + } + //se já existe, verifica se está no vetor, se n estiver, adiciona o ano + if(dimsValues[rqfName2].indexOf(r[rqfName2]) === -1) { + dimsValues[rqfName2].push(r[rqfName2]); + } + }) + }) + + //ordena os anos + dimsValues["year"] = dimsValues["year"].sort(); + // console.log(dimsValues); + + let dimsValuesKey = Object.keys(dimsValues); + // console.log(dimsValuesKey); + + let firstDim = dimsValuesKey[0]; + let secondDim = dimsValuesKey[1]; + let count = 0; + + //Permuta as dimensões em ordem, agora verifica se existe no vetor de resultados. + dimsValues[firstDim].forEach((fDim) => { + dimsValues[secondDim].forEach((sDim) => { + + //caso o object chegou ao final e ainda temos coisas para adicionar + if (typeof result[count] === 'undefined' ) { + let newEntry = Object.assign({}, result[count - 1]); + newEntry[firstDim] = fDim; + newEntry[secondDim] = sDim + newEntry["total"] = 0; + let newResult = [...result.slice(0, count), newEntry, ...result.slice(count, result.length)]; + result = newResult; + count++; + } + + // console.log(fDim,result[count][firstDim],sDim,result[count][secondDim]) + + //está no vetor, aumenta o contador + else if ((fDim == result[count][firstDim]) && (sDim == result[count][secondDim])) { + // console.log("A Entrada Existe"); + count++; + + //se não existe no objecto, vamos ordernar + } else { + + // console.log("A entrada " + fDim + " "+ sDim + " Não existe"); + + //Se não existe pega uma copia do próximo, onde a primeira dimensão seja igual + if (result[count][firstDim] == fDim) { + let newEntry = Object.assign({}, result[count]); + newEntry[firstDim] = fDim; + newEntry[secondDim] = sDim + newEntry["total"] = 0; + let newResult = [...result.slice(0, count), newEntry, ...result.slice(count, result.length)]; + result = newResult; + count++; + //se não existe pega uma copia do anterior, onde a primeira dimensão seja igual + } else if (result[count - 1][firstDim] == fDim) { + let newEntry = Object.assign({}, result[count - 1]); + newEntry[firstDim] = fDim; + newEntry[secondDim] = sDim + newEntry["total"] = 0; + let newResult = [...result.slice(0, count - 1), newEntry, ...result.slice(count - 1, result.length)]; + result = newResult; + count++; + } + } + }); + }); + req.result = result; + } next(); }; }; diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index 65a8b3cab9ad06d15d013a264b8dc88bf376eacd..d800505c1e7d9213199f0e0aa5b28d70a2c3c5ba 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -27,6 +27,7 @@ const admDependencyPriv = require(`${libs}/convert/admDependencyPriv`); const location = require(`${libs}/convert/location`); const ruralLocation = require(`${libs}/convert/ruralLocation`); const ethnicGroup = require(`${libs}/convert/ethnicGroup`); +const ethnicGroupIES = require(`${libs}/convert/ethnicGroupIES`); const agreement = require(`${libs}/convert/agreement`); const booleanVariable = require(`${libs}/convert/booleanVariable`); const educationLevel = require(`${libs}/convert/educationLevel`); @@ -41,18 +42,42 @@ 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 ageStudentCode = require(`${libs}/convert/ageStudentCode`); const fullAgeRange = require(`${libs}/convert/fullAgeRange`); const genderPnad = require(`${libs}/convert/genderPnad`); const fifthHouseholdIncome = require(`${libs}/convert/fifthHouseholdIncome`); const extremesHouseholdIncome = require(`${libs}/convert/extremesHouseholdIncome`); const educationLevelBasic = require(`${libs}/convert/educationLevelBasic`); const useTransport = require(`${libs}/convert/booleanVariable`); +const transport = require(`${libs}/convert/transport`); const useTransportPublic = require(`${libs}/convert/booleanVariable`); const transportationManager = require(`${libs}/convert/transportationManager`); const specialClass = require(`${libs}/convert/booleanVariable`); const integralTime = require(`${libs}/convert/integralTime`); const educationLevelSchoolYear = require(`${libs}/convert/educationLevelSchoolYear`); const pfe = require(`${libs}/convert/pfe`); +const upperAdmDependency = require(`${libs}/convert/upperAdmDependency`); +const academicOrganization = require(`${libs}/convert/academicOrganization`); +const ocdeSpecific = require(`${libs}/convert/ocdeSpecific`); +const ocdeGeral = require(`${libs}/convert/ocdeGeral`); +const ocdeDetailed = require(`${libs}/convert/ocdeDetailed`); +const academicLevel = require(`${libs}/convert/academicLevel`); +const upperEducationMod = require(`${libs}/convert/upperEducationMod`); +const studentDeficiency = require(`${libs}/convert/studentDeficiency`); +const schoolType = require(`${libs}/convert/schoolType`); +const upperTurn = require(`${libs}/convert/upperTurn`); +const teacherSituation = require(`${libs}/convert/teacherSituation`); +const workRegime = require(`${libs}/convert/workRegime`); +const substitute = require(`${libs}/convert/booleanVariable`); +const visitor = require(`${libs}/convert/booleanVariable`); +const eadTeacher = require(`${libs}/convert/booleanVariable`); +const graduationPresential = require(`${libs}/convert/booleanVariable`); +const postgraduateEadTeacher = require(`${libs}/convert/booleanVariable`); +const postgraduatePresentialTeacher = require(`${libs}/convert/booleanVariable`); +const teacherSchooling = require(`${libs}/convert/teacherSchooling`); +const ethnicGroupTeacherIES = require(`${libs}/convert/ethnicGroupTeacherIES`); +const genderIES = require(`${libs}/convert/genderIES`); +const deficiency = require(`${libs}/convert/studentDeficiency`); const ids = { gender_id: gender, @@ -97,6 +122,34 @@ const ids = { special_class_id: specialClass, education_level_school_year_id: educationLevelSchoolYear, pfe_id: pfe, + upper_adm_dependency_id: upperAdmDependency, + academic_organization_id: academicOrganization, + ocde_specific_id: ocdeSpecific, + ocde_geral_id: ocdeGeral, + ocde_detailed_id: ocdeDetailed, + academic_level_id: academicLevel, + upper_education_mod_id: upperEducationMod, + student_deficiency_id: studentDeficiency, + school_type_id: schoolType, + upper_turn_id: upperTurn, + is_free_id: booleanVariable, + night_time_id: booleanVariable, + capital_id: booleanVariable, + ethnic_group_ies_id: ethnicGroupIES, + teacher_situation_id: teacherSituation, + work_regime_id: workRegime, + substitute_id: booleanVariable, + visitor_id: booleanVariable, + ead_teacher_id: eadTeacher, + graduation_presential_id: graduationPresential, + postgraduate_ead_teacher_id: postgraduateEadTeacher, + postgraduate_presential_teacher_id: postgraduatePresentialTeacher, + teacher_schooling_id: teacherSchooling, + ethnic_group_teacher_ies_id: ethnicGroupTeacherIES, + gender_ies_id: genderIES, + deficiency_id: deficiency, + age_student_code_id: ageStudentCode, + transport_id: transport }; function transform(removeId=false) { @@ -144,6 +197,7 @@ module.exports = { educationLevelBasic, educationLevelMod, educationLevelShort, + educationLevelSchoolYear, admDependency, admDependencyPriv, location, @@ -160,6 +214,7 @@ module.exports = { ethnicGroupPnad, ageRange, ageRangeAll, + ageStudentCode, fullAgeRange, genderPnad, fifthHouseholdIncome, @@ -167,5 +222,29 @@ module.exports = { useTransport, transportationManager, specialClass, - integralTime + integralTime, + upperAdmDependency, + academicOrganization, + ocdeSpecific, + ocdeGeral, + ocdeDetailed, + academicLevel, + upperEducationMod, + studentDeficiency, + schoolType, + ethnicGroupIES, + upperTurn, + teacherSituation, + workRegime, + substitute, + visitor, + eadTeacher, + graduationPresential, + postgraduateEadTeacher, + postgraduatePresentialTeacher, + teacherSchooling, + ethnicGroupTeacherIES, + genderIES, + deficiency, + transport }; diff --git a/src/libs/routes/api.js b/src/libs/routes/api.js index abc8a2d74133a2abf4bac63f47e0e5fdf7bbbbc1..81007df0b8986cdf29115a54adfef6b19fc02fac 100644 --- a/src/libs/routes/api.js +++ b/src/libs/routes/api.js @@ -93,6 +93,14 @@ const youth_jobs = require(`${libs}/routes/SMPPIR/youth_jobs`) const youth_education = require(`${libs}/routes/SMPPIR/youth_education`) +const universityEnrollment = require(`${libs}/routes/universityEnrollment`); + +const courseCount = require(`${libs}/routes/courseCount`); + +const university = require(`${libs}/routes/university`); + +const universityTeacher = require(`${libs}/routes/universityTeacher`); + api.get('/', (req, res) => { res.json({ msg: 'SMPPIR API is running' }); }); @@ -132,4 +140,4 @@ api.use('/ciganos_sustentability', ciganos_sustentability); api.use('/youth_jobs', youth_jobs) api.use('/youth_education', youth_education) -module.exports = api; \ No newline at end of file +module.exports = api; diff --git a/src/libs/routes/courseCount.js b/src/libs/routes/courseCount.js new file mode 100644 index 0000000000000000000000000000000000000000..c59892e7fe5e928978b43e5f5ea94959c746c4e5 --- /dev/null +++ b/src/libs/routes/courseCount.js @@ -0,0 +1,413 @@ +/* +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 . +*/ + +const express = require('express'); + +const courseCountApp = 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 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; + +let rqf = new ReqQueryFields(); + +courseCountApp.use(cache('15 day')); + +courseCountApp.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')); + +courseCountApp.get('/years', (req, res, next) => { + req.sql.from('curso_ens_superior') + .field('DISTINCT curso_ens_superior.ano_censo', 'year'); + next(); +}, query, response('years')); + +courseCountApp.get('/year_range', (req, res, next) => { + req.sql.from('curso_ens_superior') + .field('MIN(curso_ens_superior.ano_censo)', 'start_year') + .field('MAX(curso_ens_superior.ano_censo)', 'end_year'); + next(); +}, query, response('range')); + +courseCountApp.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')); + +courseCountApp.get('/capital', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Classificado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('capital')); + +courseCountApp.get('/ocde_geral', (req, res, next) => { + req.result = []; + for(let i = 1; i <= 8; ++i) { + req.result.push({ + id: i, + name: id2str.ocdeGeral(i) + }); + }; + next(); +}, response('ocde_geral')); + +courseCountApp.get('/ocde_specific', (req, res, next) => { + req.result = []; + const defaultCase = null; + for(let i = 1; i <= 86; ++i) { + let obj = { + id: i, + name: id2str.ocdeSpecific(i) + }; + if (obj.name !== id2str.ocdeSpecific(defaultCase)){ + req.result.push(obj); + } + }; + req.result.push({ + id: defaultCase, + name: id2str.ocdeSpecific(defaultCase) + }); + next(); +}, response('ocde_specific')); + +courseCountApp.get('/ocde_detailed', (req, res, next) => { + req.result = []; + const defaultCase = null; + for(let i = 142; i <= 863; ++i) { + let obj = { + id: i, + name: id2str.ocdeDetailed(i) + }; + if (obj.name !== id2str.ocdeDetailed(defaultCase)){ + req.result.push(obj); + } + }; + req.result.push({ + id: defaultCase, + name: id2str.ocdeDetailed(defaultCase) + }); + next(); +}, response('ocde_detailed')); + +courseCountApp.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')); + +courseCountApp.get('/upper_education_mod', (req, res, next) => { + req.result = []; + for(let i = 1; i <= 3; ++i) { + req.result.push({ + id: i, + name: id2str.upperEducationMod(i) + }); + }; + next(); +}, response('upper_education_mod')); + +courseCountApp.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')); + +courseCountApp.get('/night_time', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Classificado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('night_time')); + +courseCountApp.get('/university', (req, res, next) => { + req.sql.from('curso_ens_superior') + .field('DISTINCT curso_ens_superior.nome_ies', 'nome') + .field('curso_ens_superior.cod_ies', 'cod') + next(); +}, query, response('university')); + +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: 'nome', + foreign: 'nome_regiao_curso', + foreignTable: 'curso_ens_superior' + } +}).addValue({ + name: 'state', + table: 'estado', + tableField: ['nome', 'id'], + resultField: ['state_name', 'state_id'], + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'cod_uf_curso', + foreignTable: 'curso_ens_superior' + } +}).addValue({ + name: 'city', + table: 'curso_ens_superior', + tableField: ['municipio_curso', 'cod_municipio_curso'], + resultField: ['city_name', 'city_id'], + where: { + relation: '=', + type: 'integer', + field: 'cod_municipio_curso' + } +}).addValue({ + name: 'university', + table: 'curso_ens_superior', + tableField: ['cod_ies', 'nome_ies'], + resultField: ['university_id', 'university_name'], + where: { + relation: '=', + type: 'integer', + field: 'cod_ies' + } +}).addValue({ + name:'upper_adm_dependency', + table: 'curso_ens_superior', + tableField: 'par_categoria_administrativa', + resultField: 'upper_adm_dependency_id', + where: { + relation: '=', + type: 'integer', + field: 'par_categoria_administrativa' + } +}).addValue({ + name:'academic_organization', + table: 'curso_ens_superior', + tableField: 'cod_organizacao_academica', + resultField: 'academic_organization_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_organizacao_academica' + } +}).addValue({ + name:'capital', + table: 'curso_ens_superior', + tableField: 'tfd_capital_curso', + resultField: 'capital_id', + where: { + relation: '=', + type: 'integer', + field: 'tfd_capital_curso' + } +}).addValue({ + name:'course', + table: 'curso_ens_superior', + tableField: 'nome_curso', + resultField: 'course_name', + where: { + relation: 'LIKE', + type: 'string', + field: 'nome_curso' + } +}).addValue({ + name:'ocde_specific', + table: 'curso_ens_superior', + tableField: ['cod_ocde_area_especifica', 'nome_ocde_area_especifica'], + resultField: ['ocde_specific_id', 'ocde_specific_name'], + where: { + relation: '=', + type: 'integer', + field: 'cod_ocde_area_especifica' + } +}).addValue({ + name:'ocde_geral', + table: 'curso_ens_superior', + tableField: ['cod_ocde_area_geral', 'nome_ocde_area_geral'], + resultField: ['ocde_geral_id', 'ocde_geral_name'], + where: { + relation: '=', + type: 'integer', + field: 'cod_ocde_area_geral' + } +}).addValue({ + name:'ocde_detailed', + table: 'curso_ens_superior', + tableField: ['cod_ocde_area_detalhada', 'nome_ocde_area_detalhada'], + resultField: ['ocde_detailed_id', 'ocde_datailed_name'], + where: { + relation: '=', + type: 'integer', + field: 'cod_ocde_area_detalhada' + } +}).addValue({ + name:'academic_level', + table: 'curso_ens_superior', + tableField: 'cod_grau_academico', + resultField: 'academic_level_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_grau_academico' + } +}).addValue({ + name:'upper_education_mod', + table: 'curso_ens_superior', + tableField: 'cod_modalidade_ensino', + resultField: 'upper_education_mod_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_modalidade_ensino' + } +}).addValue({ + name:'is_free', + table: 'curso_ens_superior', + tableField: 'gratuito', + resultField: 'is_free_id', + where: { + relation: '=', + type: 'boolean', + field: 'gratuito' + } +}).addValue({ + name:'night_time', + table: 'curso_ens_superior', + tableField: 'noturno_curso', + resultField: 'night_time_id', + where: { + relation: '=', + type: 'boolean', + field: 'noturno_curso' + } +}).addValue({ + name:'situation', + table: 'curso_ens_superior', + tableField: 'cod_situacao_curso', + resultField: 'situacao_curso_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_situacao_curso' + } +}).addValue({ + name:'year', + table: 'curso_ens_superior', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'min_year', + table: 'curso_ens_superior', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + table: 'curso_ens_superior', + field: 'ano_censo' + } +}).addValue({ + name: 'max_year', + table: 'curso_ens_superior', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + table: 'curso_ens_superior', + field: 'ano_censo' + } +}); + +courseCountApp.get('/', rqf.parse(), (req, res, next) => { + req.sql.from('curso_ens_superior') + .field('COUNT(curso_ens_superior.cod_curso)', 'total') + .field("'Brasil'", 'name') + .field('curso_ens_superior.ano_censo', 'year') + .group('curso_ens_superior.ano_censo') + .order('curso_ens_superior.ano_censo') + .where('curso_ens_superior.tipo_atributo_ingresso <> 1 OR curso_ens_superior.tipo_atributo_ingresso is NULL') + .where('curso_ens_superior.cod_nivel_academico = 1'); + next(); +}, rqf.build(), query, id2str.transform(), addMissing(rqf), response('course_count')); + +module.exports = courseCountApp; diff --git a/src/libs/routes/university.js b/src/libs/routes/university.js new file mode 100644 index 0000000000000000000000000000000000000000..959f4adb331344515f139582014150cebbe43749 --- /dev/null +++ b/src/libs/routes/university.js @@ -0,0 +1,331 @@ +/* +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 . +*/ + +const express = require('express'); + +const universityApp = 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(); + +let rqfCount = new ReqQueryFields(); + +universityApp.use(cache('15 day')); + +universityApp.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')); + +universityApp.get('/years', (req, res, next) => { + req.sql.from('ies_ens_superior') + .field('DISTINCT ies_ens_superior.ano_censo', 'year') + next(); +}, query, response('years')); + +universityApp.get('/year_range', (req, res, next) => { + req.sql.from('ies_ens_superior') + .field('MIN(ies_ens_superior.ano_censo)', 'start_year') + .field('MAX(ies_ens_superior.ano_censo)', 'end_year'); + next(); +}, query, response('range')); + +universityApp.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')); + +universityApp.get('/capital', (req, res, next) => { + req.result = []; + for(let i = 0; i <= 1; ++i) { + req.result.push({ + id: i, + name: id2str.booleanVariable(i) + }); + }; + next(); +}, response('capital')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addValue({ + name: 'id', + table: 'ies_ens_superior', + tableField: 'cod_ies', + resultField: 'id', + where: { + relation: '=', + type: 'integer', + field: 'cod_ies' + } +}).addValue({ + name: 'city', + table: 'municipio', + tableField: 'nome', + resultField: 'city_name', + where: { + relation: '=', + type: 'integer', + field: 'cod_municipio_ies', + table: 'ies_ens_superior' + }, + join: { + primary: 'id', + foreign: 'cod_municipio_ies', + foreignTable: 'ies_ens_superior' + } +}).addValue({ + name: 'state', + table: 'estado', + tableField: 'nome', + resultField: 'state_name', + where: { + relation: '=', + type: 'integer', + field: 'cod_uf_ies', + table: 'ies_ens_superior' + }, + join: { + primary: 'id', + foreign: 'cod_uf_ies', + foreignTable: 'ies_ens_superior' + } +}).addValue({ + name: 'year', + table: 'ies_ens_superior', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '=', + type: 'integer', + field: 'ano_censo', + table: 'ies_ens_superior' + } +}).addField({ + name: 'search', + field: true, + where: true +}).addValueToField({ + name: 'city_name', + table: 'municipio', + tableField: 'nome', + resultField: 'city_name', + dontGroup: true, + where: { + relation: 'LIKE', + type: 'string', + field: 'nome' + }, + join: { + primary: 'id', + foreign: 'cod_municipio_ies', + foreignTable: 'ies_ens_superior' + } +}, 'search') +.addValueToField({ + name: 'state_name', + table: 'estado', + tableField: 'nome', + resultField: 'state_name', + dontGroup: true, + where: { + relation: 'LIKE', + type: 'string', + field: 'sigla' + }, + join: { + primary: 'id', + foreign: 'cod_uf_ies', + foreignTable: 'ies_ens_superior' + } +}, 'search'); + + +rqfCount.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_ies', + table: 'ies_ens_superior' + }, + join: { + primary: 'id', + foreign: 'cod_municipio_ies', + foreignTable: 'ies_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: 'ies_ens_superior' + } + +}).addValue({ + name: 'min_year', + table: '@', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + table: '@', + field: 'ano_censo' + } +}).addValue({ + name: 'max_year', + table: '@', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + table: '@', + field: 'ano_censo' + } +}).addValue({ + name: 'state', + table: 'estado', + tableField: ['nome', 'id'], + resultField: ['state_name', 'state_id'], + where: { + relation: '=', + type: 'integer', + field: 'cod_uf_ies', + table: '@' + }, + join: { + primary: 'id', + foreign: 'cod_uf_ies', + foreignTable: '@' + } +}).addValue({ + name: 'upper_adm_dependency', + table: 'ies_ens_superior', + tableField: 'par_categoria_administrativa', + resultField: 'upper_adm_dependency_id', + where: { + relation: '=', + type: 'integer', + table: 'ies_ens_superior', + field: 'cod_categoria_administrativa' + } +}).addValue({ + name: 'academic_organization', + table: 'ies_ens_superior', + tableField: 'cod_organizacao_academica', + resultField: 'academic_organization_id', + where: { + relation: '=', + type: 'integer', + table: 'ies_ens_superior', + field: 'cod_organizacao_academica' + } +}).addValue({ + name: 'capital', + table: 'ies_ens_superior', + tableField: 'tfd_capital_ies', + resultField: 'capital_id', + where: { + relation: '=', + type: 'integer', + table: 'ies_ens_superior', + field: 'capital_ies' + } +}); + +universityApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + req.sql.from('ies_ens_superior') + .field('ies_ens_superior.cod_ies', 'id') + .field('ies_ens_superior.ano_censo', 'year') + .field('ies_ens_superior.nome_ies', 'name') + .field('ies_ens_superior.cod_uf_ies', 'state_id') + .field('ies_ens_superior.cod_municipio_ies', 'city_id'); + next(); + +}, query, response('university')); + +universityApp.get('/count', rqfCount.parse(), (req, res, next) => { + req.sql.field('COUNT(*)', 'total') + .field("'Brasil'", 'name') + .field('ies_ens_superior.ano_censo', 'year') + .from('ies_ens_superior') + .group('ies_ens_superior.ano_censo') + .order('ies_ens_superior.ano_censo') + + next(); +}, rqfCount.build(), query, addMissing(rqfCount), id2str.transform(), response('university')); + +module.exports = universityApp; diff --git a/src/libs/routes/universityEnrollment.js b/src/libs/routes/universityEnrollment.js new file mode 100644 index 0000000000000000000000000000000000000000..a618a7be5d9eb56dc169b36e70ca2cd04c703f21 --- /dev/null +++ b/src/libs/routes/universityEnrollment.js @@ -0,0 +1,492 @@ +/* +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 . +*/ + +const express = require('express'); + +const universityEnrollmentApp = 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 id2str = require(`${libs}/middlewares/id2str`); + +const addMissing = require(`${libs}/middlewares/addMissing`); + +const config = require(`${libs}/config`); + +const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware; + +let rqf = new ReqQueryFields(); + +universityEnrollmentApp.get('/years', (req, res, next) => { + req.sql.from('aluno_ens_superior') + .field('DISTINCT aluno_ens_superior.ano_censo', 'year'); + next(); +}, query, response('years')); + +universityEnrollmentApp.get('/year_range', (req, res, next) => { + req.sql.from('aluno_ens_superior') + .field('MIN(aluno_ens_superior.ano_censo)', 'start_year') + .field('MAX(aluno_ens_superior.ano_censo)', 'end_year'); + next(); +}, query, response('range')); + +universityEnrollmentApp.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')); + +universityEnrollmentApp.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')); + +universityEnrollmentApp.get('/ocde_geral', (req, res, next) => { + req.result = []; + for(let i = 0; i <= 8; ++i) { + req.result.push({ + id: i, + name: id2str.ocdeGeral(i) + }); + }; + next(); +}, response('ocde_geral')); + +universityEnrollmentApp.get('/ocde_specific', (req, res, next) => { + req.result = []; + const defaultCase = null; + for(let i = 1; i <= 86; ++i) { + let obj = { + id: i, + name: id2str.ocdeSpecific(i) + }; + if (obj.name !== id2str.ocdeSpecific(defaultCase)){ + req.result.push(obj); + } + }; + req.result.push({ + id: defaultCase, + name: id2str.ocdeSpecific(defaultCase) + }); + next(); +}, response('ocde_specific')); + +universityEnrollmentApp.get('/ocde_detailed', (req, res, next) => { + req.result = []; + const defaultCase = null; + for(let i = 142; i <= 863; ++i) { + let obj = { + id: i, + name: id2str.ocdeDetailed(i) + }; + if (obj.name !== id2str.ocdeDetailed(defaultCase)){ + req.result.push(obj); + } + }; + req.result.push({ + id: defaultCase, + name: id2str.ocdeDetailed(defaultCase) + }); + next(); +}, response('ocde_detailed')); + +universityEnrollmentApp.get('/upper_turn', (req, res, next) => { + req.result = []; + for(let i = 1; i <= 4; ++i) { + req.result.push({ + id: i, + name: id2str.upperTurn(i) + }); + }; + next(); +}, response('upper_turn')); + +universityEnrollmentApp.get('/student_deficiency', (req, res, next) => { + req.result = []; + for(let i = 0; i <= 1; ++i) { + req.result.push({ + id: i, + name: id2str.studentDeficiency(i) + }); + }; + next(); +}, response('student_deficiency')); + +universityEnrollmentApp.get('/ethnic_group_ies', (req, res, next) => { + req.result = []; + for(let i = 1; i <=5; ++i) { + req.result.push({ + id: i, + name: id2str.ethnicGroupIES(i) + }); + } + next(); +}, response('ethnic_group_ies')); + +universityEnrollmentApp.get('/school_type', (req, res, next) => { + req.result = []; + for(let i = 1; i <= 2; ++i) { + req.result.push({ + id: i, + name: id2str.schoolType(i) + }); + }; + next(); +}, response('school_type')); + +universityEnrollmentApp.get('/university', (req, res, next) => { + req.sql.from('aluno_ens_superior') + .field('DISTINCT aluno_ens_superior.nome_ies', 'nome') + .field('aluno_ens_superior.cod_ies', 'cod') + next(); +}, query, response('university')); + +universityEnrollmentApp.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')); + +universityEnrollmentApp.get('/gender_ies', function (req, res, next) { + req.result = []; + for (var i = 1; i <= 2; ++i) { + req.result.push({ + id: i, + name: id2str.genderIES(i) + }); + }; + next(); +}, response('gender_ies')); + +universityEnrollmentApp.get('/upper_education_mod', function (req, res, next) { + req.result = []; + for (var i = 1; i <= 3; ++i) { + req.result.push({ + id: i, + name: id2str.upperEducationMod(i) + }); + }; + next(); +}, response('upper_education_mod')); + +universityEnrollmentApp.get('/age_student_code', function (req, res, next) { + req.result = []; + for (var i = 1; i <= 6; ++i) { + req.result.push({ + id: i, + name: id2str.ageStudentCode(i) + }); + }; + next(); +}, response('age_student_code')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'min_year', + table: '@', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + table: '@', + field: 'ano_censo' + } +}).addValue({ + name: 'max_year', + table: '@', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + table: '@', + field: 'ano_censo' + } +}).addValue({ + name: 'state', + table: 'estado', + tableField: ['nome', 'id'], + resultField: ['state_name', 'state_id'], + where: { + relation: '=', + type: 'integer', + field: 'cod_uf_ies', + table: '@' + }, + join: { + primary: 'id', + foreign: 'cod_uf_ies', + foreignTable: '@' + } +}).addValue({ + name: 'city', + table: 'municipio', + tableField: ['nome', 'id'], + resultField: ['city_name', 'city_id'], + where: { + relation: '=', + type: 'integer', + field: 'cod_municipio_ies', + table: '@' + }, + join: { + primary: 'id', + foreign: 'cod_municipio_ies', + foreignTable: '@' + } +}).addValue({ + name: 'region', + table: 'regiao', + tableField: ['nome', 'id'], + resultField: ['region_name', 'region_id'], + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'cod_regiao_ies', + foreignTable: 'aluno_ens_superior' + } +}).addValue({ + name: 'university', + table: 'aluno_ens_superior', + tableField: ['cod_ies', 'nome_ies'], + resultField: ['university_id', 'university_name'], + where: { + relation: '=', + type: 'integer', + field: 'cod_ies' + } +}).addValue({ + name: 'age_student_code', + table: 'aluno_ens_superior', + tableField: 'idade_aluno_codigo', + resultField: 'age_student_code_id', + where: { + relation: '=', + type: 'integer', + field: 'idade_aluno_codigo' + } +}).addValue({ + name: 'upper_adm_dependency', + table: 'aluno_ens_superior', + tableField: 'par_categoria_administrativa', + resultField: 'upper_adm_dependency_id', + where: { + relation: '=', + type: 'integer', + table: 'aluno_ens_superior', + field: 'par_categoria_administrativa' + } +}).addValue({ + name: 'academic_organization', + table: 'aluno_ens_superior', + tableField: 'cod_organizacao_academica', + resultField: 'academic_organization_id', + where: { + relation: '=', + type: 'integer', + table: 'aluno_ens_superior', + field: 'cod_organizacao_academica' + } +}).addValue({ + name:'ocde_specific', + table: 'aluno_ens_superior', + tableField: 'par_cod_ocde_area_especifica', + resultField: 'ocde_specific_id', + where: { + relation: '=', + type: 'integer', + field: 'par_cod_ocde_area_especifica' + } +}).addValue({ + name:'ocde_geral', + table: 'aluno_ens_superior', + tableField: 'par_cod_ocde_area_geral', + resultField: 'ocde_geral_id', + where: { + relation: '=', + type: 'integer', + field: 'par_cod_ocde_area_geral' + } +}).addValue({ + name:'ocde_detailed', + table: 'aluno_ens_superior', + tableField: 'par_cod_ocde_area_detalhada', + resultField: 'ocde_detailed_id', + where: { + relation: '=', + type: 'integer', + field: 'par_cod_ocde_area_detalhada' + } +}).addValue({ + name:'academic_level', + table: 'aluno_ens_superior', + tableField: 'cod_grau_academico', + resultField: 'academic_level_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_grau_academico' + } +}).addValue({ + name:'upper_education_mod', + table: 'aluno_ens_superior', + tableField: 'cod_modalidade_ensino', + resultField: 'upper_education_mod_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_modalidade_ensino' + } +}).addValue({ + name:'upper_turn', + table: 'aluno_ens_superior', + tableField: 'cod_turno_aluno', + resultField: 'upper_turn_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_turno_aluno' + } +}).addValue({ + name:'ethnic_group_ies', + table: 'aluno_ens_superior', + tableField: 'par_cod_cor_raca_aluno', + resultField: 'ethnic_group_ies_id', + where: { + relation: '=', + type: 'integer', + field: 'par_cod_cor_raca_aluno' + } +}).addValue({ + name:'student_deficiency', + table: 'aluno_ens_superior', + tableField: 'par_aluno_deficiencia_transtorno_superdotacao', + resultField: 'student_deficiency_id', + where: { + relation: '=', + type: 'integer', + field: 'par_aluno_deficiencia_transtorno_superdotacao' + } +}).addValue({ + name:'school_type', + table: 'aluno_ens_superior', + tableField: 'par_tipo_escola_ensino_medio', + resultField: 'school_type_id', + where: { + relation: '=', + type: 'integer', + field: 'par_tipo_escola_ensino_medio' + } +}).addValue({ + name: 'university', + table: 'aluno_ens_superior', + tableField: ['cod_ies', 'nome_ies'], + resultField: ['university_id', 'university_name'], + where: { + relation: '=', + type: 'integer', + field: 'cod_ies' + } +}).addValue({ + name: 'gender_ies', + table: 'aluno_ens_superior', + tableField: 'par_genero_aluno', + resultField: 'gender_ies_id', + where: { + relation: '=', + type: 'integer', + field: 'par_genero_aluno' + } +}).addValue({ + name:'academic_level', + table: 'aluno_ens_superior', + tableField: 'cod_grau_academico', + resultField: 'academic_level_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_grau_academico' + } +}); + +universityEnrollmentApp.get('/', rqf.parse(), (req, res, next) => { + + if ("university" in req.dims) { + req.sql.field('COUNT(*)', 'total') + .field("'Brasil'", 'name') + .field('aluno_ens_superior.ano_censo', 'year') + .from('aluno_ens_superior') + .where('aluno_ens_superior.matriculado = 1 AND aluno_ens_superior.cod_nivel_academico = 1') + .group('aluno_ens_superior.cod_ies') + .group('aluno_ens_superior.ano_censo') + .order('aluno_ens_superior.cod_ies') + .order('aluno_ens_superior.ano_censo') + } else { + req.sql.field('COUNT(*)', 'total') + .field("'Brasil'", 'name') + .field('aluno_ens_superior.ano_censo', 'year') + .from('aluno_ens_superior') + .where('aluno_ens_superior.matriculado = 1 AND aluno_ens_superior.cod_nivel_academico = 1') + .group('aluno_ens_superior.ano_censo') + .order('aluno_ens_superior.ano_censo') + } + next(); + +}, rqf.build(), query, addMissing(rqf), id2str.transform(false), response('universityEnrollment')); + +module.exports = universityEnrollmentApp; diff --git a/src/libs/routes/universityTeacher.js b/src/libs/routes/universityTeacher.js new file mode 100644 index 0000000000000000000000000000000000000000..42851c2b85c9dbdd1ec69da7983f2306597dca29 --- /dev/null +++ b/src/libs/routes/universityTeacher.js @@ -0,0 +1,490 @@ +/* +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 . +*/ + +const express = require('express'); + +const teacherEnrollmentApp = 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 id2str = require(`${libs}/middlewares/id2str`); + +const addMissing = require(`${libs}/middlewares/addMissing`); + +const config = require(`${libs}/config`); + +const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware; + +let rqf = new ReqQueryFields(); + +teacherEnrollmentApp.get('/years', (req, res, next) => { + req.sql.from('docente_ens_superior') + .field('DISTINCT docente_ens_superior.ano_censo', 'year'); + next(); +}, query, response('years')); + +teacherEnrollmentApp.get('/year_range', (req, res, next) => { + req.sql.from('docente_ens_superior') + .field('MIN(docente_ens_superior.ano_censo)', 'start_year') + .field('MAX(docente_ens_superior.ano_censo)', 'end_year'); + next(); +}, query, response('range')); + +teacherEnrollmentApp.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')); + +teacherEnrollmentApp.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')); + +teacherEnrollmentApp.get('/teacher_situation', (req, res, next) => { + req.result = []; + for(let i = 1; i <= 6; ++i) { + req.result.push({ + id: i, + name: id2str.teacherSituation(i) + }); + }; + next(); +}, response('teacher_situation')); + +teacherEnrollmentApp.get('/work_regime', (req, res, next) => { + req.result = []; + for(let i = 1; i <= 4; ++i) { + req.result.push({ + id: i, + name: id2str.workRegime(i) + }); + }; + next(); +}, response('work_regime')); + +teacherEnrollmentApp.get('/substitute', (req, res, next) => { + req.result = []; + for(let i = 0; i <= 1; ++i) { + req.result.push({ + id: i, + name: id2str.booleanVariable(i) + }); + }; + next(); +}, response('substitute')); + +teacherEnrollmentApp.get('/visitor', (req, res, next) => { + req.result = []; + for(let i = 0; i <= 1; ++i) { + req.result.push({ + id: i, + name: id2str.booleanVariable(i) + }); + }; + next(); +}, response('visitor')); + +teacherEnrollmentApp.get('/ead_teacher', (req, res, next) => { + req.result = []; + for(let i = 0; i <= 1; ++i) { + req.result.push({ + id: i, + name: id2str.booleanVariable(i) + }); + }; + next(); +}, response('ead_teacher')); + +teacherEnrollmentApp.get('/graduation_presential', (req, res, next) => { + req.result = []; + for(let i = 0; i <= 1; ++i) { + req.result.push({ + id: i, + name: id2str.booleanVariable(i) + }); + }; + next(); +}, response('graduation_presential')); + +teacherEnrollmentApp.get('/postgraduate_ead_teacher', (req, res, next) => { + req.result = []; + for(let i = 0; i <= 1; ++i) { + req.result.push({ + id: i, + name: id2str.booleanVariable(i) + }); + }; + next(); +}, response('postgraduate_ead_teacher')); + +teacherEnrollmentApp.get('/postgraduate_presential_teacher', (req, res, next) => { + req.result = []; + for(let i = 0; i <= 1; ++i) { + req.result.push({ + id: i, + name: id2str.booleanVariable(i) + }); + }; + next(); +}, response('postgraduate_presential_teacher')); + +teacherEnrollmentApp.get('/deficiency', (req, res, next) => { + req.result = []; + for(let i = 0; i <= 1; ++i) { + req.result.push({ + id: i, + name: id2str.booleanVariable(i) + }); + }; + next(); +}, response('deficiency')); + +teacherEnrollmentApp.get('/ethnic_group_teacher_ies', (req, res, next) => { + req.result = []; + for(let i = 0; i <= 5; ++i) { + req.result.push({ + id: i, + name: id2str.ethnicGroupTeacherIES(i) + }); + }; + next(); +}, response('ethnic_group_teacher_ies')); + +teacherEnrollmentApp.get('/teacher_schooling', (req, res, next) => { + req.result = []; + for(let i = 1; i <= 5; ++i) { + req.result.push({ + id: i, + name: id2str.teacherSchooling(i) + }); + }; + next(); +}, response('teacher_schooling')); + +teacherEnrollmentApp.get('/gender_ies', (req, res, next) => { + req.result = []; + for(let i = 1; i <= 2; ++i) { + req.result.push({ + id: i, + name: id2str.genderIES(i) + }); + }; + next(); +}, response('gender_ies')); + + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'min_year', + table: '@', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + table: '@', + field: 'ano_censo' + } +}).addValue({ + name: 'max_year', + table: '@', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + table: '@', + field: 'ano_censo' + } +}).addValue({ + name: 'state', + table: 'estado', + tableField: ['nome', 'id'], + resultField: ['state_name', 'state_id'], + where: { + relation: '=', + type: 'integer', + field: 'cod_uf_ies', + table: '@' + }, + join: { + primary: 'id', + foreign: 'cod_uf_ies', + foreignTable: '@' + } +}).addValue({ + name: 'city', + table: 'municipio', + tableField: ['nome', 'id'], + resultField: ['city_name', 'city_id'], + where: { + relation: '=', + type: 'integer', + field: 'cod_municipio_ies', + table: '@' + }, + join: { + primary: 'id', + foreign: 'cod_municipio_ies', + foreignTable: '@' + } +}).addValue({ + name: 'region', + table: 'regiao', + tableField: ['nome', 'id'], + resultField: ['region_name', 'region_id'], + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'cod_regiao_ies', + foreignTable: 'docente_ens_superior' + } +}).addValue({ + name: 'university', + table: 'docente_ens_superior', + tableField: ['cod_ies', 'nome_ies'], + resultField: ['university_id', 'university_name'], + where: { + relation: '=', + type: 'integer', + field: 'cod_ies' + } +}).addValue({ + name: 'upper_adm_dependency', + table: 'docente_ens_superior', + tableField: 'par_categoria_administrativa', + resultField: 'upper_adm_dependency_id', + where: { + relation: '=', + type: 'integer', + table: 'docente_ens_superior', + field: 'par_categoria_administrativa' + } +}).addValue({ + name: 'academic_organization', + table: 'docente_ens_superior', + tableField: 'cod_organizacao_academica', + resultField: 'academic_organization_id', + where: { + relation: '=', + type: 'integer', + table: 'docente_ens_superior', + field: 'cod_organizacao_academica' + } +}).addValue({ + name:'academic_level', + table: 'docente_ens_superior', + tableField: 'cod_grau_academico', + resultField: 'academic_level_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_grau_academico' + } +}).addValue({ + name:'upper_education_mod', + table: 'docente_ens_superior', + tableField: 'cod_modalidade_ensino', + resultField: 'upper_education_mod_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_modalidade_ensino' + } +}).addValue({ + name:'teacher_situation', + table: 'docente_ens_superior', + tableField: 'par_situacao_docente', + resultField: 'teacher_situation_id', + where: { + relation: '=', + type: 'integer', + field: 'par_situacao_docente' + } +}).addValue({ + name:'work_regime', + table: 'docente_ens_superior', + tableField: 'cod_regime_trabalho', + resultField: 'work_regime_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_regime_trabalho' + } +}).addValue({ + name:'substitute', + table: 'docente_ens_superior', + tableField: 'docente_substituto', + resultField: 'substitute_id', + where: { + relation: '=', + type: 'integer', + field: 'docente_substituto' + } +}).addValue({ + name:'visitor', + table: 'docente_ens_superior', + tableField: 'docente_visitante', + resultField: 'visitor_id', + where: { + relation: '=', + type: 'integer', + field: 'docente_visitante' + } +}).addValue({ + name:'ead_teacher', + table: 'docente_ens_superior', + tableField: 'ministra_aula_ead', + resultField: 'ead_teacher_id', + where: { + relation: '=', + type: 'integer', + field: 'ministra_aula_ead' + } +}).addValue({ + name:'graduation_presential', + table: 'docente_ens_superior', + tableField: 'atua_atividade_graduacao_presencial', + resultField: 'graduation_presential_id', + where: { + relation: '=', + type: 'integer', + field: 'atua_atividade_graduacao_presencial' + } +}).addValue({ + name:'postgraduate_ead_teacher', + table: 'docente_ens_superior', + tableField: 'atua_atividade_posgraduacao_distancia', + resultField: 'postgraduate_ead_teacher_id', + where: { + relation: '=', + type: 'integer', + field: 'atua_atividade_posgraduacao_distancia' + } +}).addValue({ + name:'postgraduate_presential_teacher', + table: 'docente_ens_superior', + tableField: 'atua_atividade_posgraduacao_presencial', + resultField: 'postgraduate_presential_teacher_id', + where: { + relation: '=', + type: 'integer', + field: 'atua_atividade_posgraduacao_presencial' + } +}).addValue({ + name:'teacher_schooling', + table: 'docente_ens_superior', + tableField: 'cod_escolaridade_docente', + resultField: 'teacher_schooling_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_escolaridade_docente' + } +}).addValue({ + name:'ethnic_group_teacher_ies', + table: 'docente_ens_superior', + tableField: 'cod_cor_raca_docente', + resultField: 'ethnic_group_teacher_ies_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_cor_raca_docente' + } +}).addValue({ + name:'gender_ies', + table: 'docente_ens_superior', + tableField: 'sexo_docente', + resultField: 'gender_ies_id', + where: { + relation: '=', + type: 'integer', + field: 'sexo_docente' + } +}).addValue({ + name:'deficiency', + table: 'docente_ens_superior', + tableField: 'par_docente_deficiencia', + resultField: 'deficiency_id', + where: { + relation: '=', + type: 'integer', + field: 'par_docente_deficiencia' + } +}); + +teacherEnrollmentApp.get('/', rqf.parse(), (req, res, next) => { + + if ("university" in req.dims) { + req.sql.field('COUNT(*)', 'total') + .field("'Brasil'", 'name') + .field('docente_ens_superior.ano_censo', 'year') + .from('docente_ens_superior') + .group('docente_ens_superior.cod_ies') + .group('docente_ens_superior.ano_censo') + .order('docente_ens_superior.cod_ies') + .order('docente_ens_superior.ano_censo') + } + else { + req.sql.field('COUNT(*)', 'total') + .field("'Brasil'", 'name') + .field('docente_ens_superior.ano_censo', 'year') + .from('docente_ens_superior') + .group('docente_ens_superior.ano_censo') + .order('docente_ens_superior.ano_censo') + } + + next(); +}, rqf.build(), query, addMissing(rqf), id2str.transform(false), response('teacherEnrollment')); + +module.exports = teacherEnrollmentApp;