diff --git a/src/libs/convert/attendedModality.js b/src/libs/convert/attendedModality.js new file mode 100644 index 0000000000000000000000000000000000000000..fd6162a5d5e690fd865c1614af0cb29ab40b5211 --- /dev/null +++ b/src/libs/convert/attendedModality.js @@ -0,0 +1,56 @@ +/* +Copyright (C) 2024 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-node is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +simcaq-node is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +module.exports = function attendedModality(id) { + switch (id) { + case 1: + return 'Creche'; + case 2: + return 'Pré-escola'; + case 3: + return 'Alfabetização de jovens e adultos'; + case 4: + return 'Ensino Fundamental - Anos iniciais' + case 5: + return 'Ensino Fundamental - Anos finais'; + case 6: + return 'EJA - Ensino Fundamental'; + case 7: + return 'Ensino Médio'; + case 8: + return 'Educação profissional - técnica integrada'; + case 9: + return 'Educação profissional - técnica concomitante e subsequente'; + case 10: + return 'Ensino Médio Regular e Profissional articulado'; + case 11: + return 'EJA - Ensino Médio'; + case 12: + return 'Superior'; + case 13: + return 'Especialização'; + case 14: + return 'Mestrado'; + case 15: + return 'Doutorado'; + case 99: + return 'Não frequenta instituição de ensino'; + } +}; diff --git a/src/libs/convert/attendsSchool.js b/src/libs/convert/attendsSchool.js new file mode 100644 index 0000000000000000000000000000000000000000..c5192999af083af6b66bc17f0c2b3e0a9ebf20c9 --- /dev/null +++ b/src/libs/convert/attendsSchool.js @@ -0,0 +1,31 @@ +/* +Copyright (C) 2024 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-node is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +simcaq-node is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +// This file is used to convert the attendsSchool AND 'bolsa_familia' variable to a human-readable format. +module.exports = function attendsSchool(id) { + switch (id) { + case 1: + return 'Sim'; + case 2: + return 'Não'; + case 9: + return 'Sem informação'; + } +}; diff --git a/src/libs/convert/capitalCode.js b/src/libs/convert/capitalCode.js new file mode 100644 index 0000000000000000000000000000000000000000..2e4774f53cd92e9b6f69360b8664b538b2fe6b63 --- /dev/null +++ b/src/libs/convert/capitalCode.js @@ -0,0 +1,81 @@ +/* +Copyright (C) 2024 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-node is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +simcaq-node is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +module.exports = function capitalCode(id) { + switch (id) { + case 11: + return 'Porto Velho'; + case 12: + return 'Rio Branco'; + case 13: + return 'Manaus'; + case 14: + return 'Boa Vista'; + case 15: + return 'Belém'; + case 16: + return 'Macapá'; + case 17: + return 'Palmas'; + case 21: + return 'São Luís'; + case 22: + return 'Teresina'; + case 23: + return 'Fortaleza'; + case 24: + return 'Natal'; + case 25: + return 'João Pessoa'; + case 26: + return 'Recife'; + case 27: + return 'Maceió'; + case 28: + return 'Aracaju'; + case 29: + return 'Salvador'; + case 31: + return 'Belo Horizonte'; + case 32: + return 'Vitória'; + case 33: + return 'Rio de Janeiro'; + case 35: + return 'São Paulo'; + case 41: + return 'Curitiba'; + case 42: + return 'Florianópolis'; + case 43: + return 'Porto Alegre'; + case 50: + return 'Campo Grande'; + case 51: + return 'Cuiabá'; + case 52: + return 'Goiânia'; + case 53: + return 'Brasília'; + default: + return 'Não é capital'; + } +}; + diff --git a/src/libs/convert/ethnicGroupNewPnad.js b/src/libs/convert/ethnicGroupNewPnad.js new file mode 100644 index 0000000000000000000000000000000000000000..cfbd60e176b014a66fc2ba2dd681cb5203320e38 --- /dev/null +++ b/src/libs/convert/ethnicGroupNewPnad.js @@ -0,0 +1,36 @@ +/* +Copyright (C) 2024 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-node is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +simcaq-node is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +module.exports = function ethnicGroupNewPnad(id) { + switch (id) { + case 1: + return 'Branca'; + case 2: + return 'Preta'; + case 3: + return 'Amarela'; + case 4: + return 'Parda'; + case 5: + return 'Indígena'; + case 9: + return 'Sem declaração'; + } +}; diff --git a/src/libs/convert/illiteracy.js b/src/libs/convert/illiteracy.js new file mode 100644 index 0000000000000000000000000000000000000000..069273977485f6680a83e6b269878653d82bc314 --- /dev/null +++ b/src/libs/convert/illiteracy.js @@ -0,0 +1,30 @@ +/* +Copyright (C) 2024 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-node is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +simcaq-node is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +module.exports = function illiteracy(id) { + switch (id) { + case 0: + return 'Não'; + case 1: + return 'Sim'; + case 9: + return 'Não se aplica - 14 anos ou menos'; + } +}; diff --git a/src/libs/convert/instructionLevel.js b/src/libs/convert/instructionLevel.js new file mode 100644 index 0000000000000000000000000000000000000000..7750a704d90a916bc9ec01f04b43a262a9c02307 --- /dev/null +++ b/src/libs/convert/instructionLevel.js @@ -0,0 +1,40 @@ +/* +Copyright (C) 2024 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-node is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +simcaq-node is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +module.exports = function instructionLevel(id) { + switch (id) { + case 1: + return 'Sem instrução e menos de 1 ano de estudo'; + case 2: + return 'Fundamental incompleto ou equivalente'; + case 3: + return 'Fundamental completo ou equivalente'; + case 4: + return 'Médio incompleto ou equivalente'; + case 5: + return 'Médio completo ou equivalente'; + case 6: + return 'Superior incompleto ou equivalente'; + case 7: + return 'Superior completo ou equivalente'; + case 8: + return 'Não se aplica - 17 anos ou menos'; + } +}; diff --git a/src/libs/convert/metroCode.js b/src/libs/convert/metroCode.js new file mode 100644 index 0000000000000000000000000000000000000000..e7729bb454e0c6b5a8785a84c22d1cb9c59b0d3a --- /dev/null +++ b/src/libs/convert/metroCode.js @@ -0,0 +1,68 @@ +/* +Copyright (C) 2024 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-node is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +simcaq-node is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +module.exports = function metroCode(id) { + switch (id) { + case 13: + return 'Região Metropolitana de Manaus'; + case 15: + return 'Região Metropolitana de Belém'; + case 16: + return 'Região Metropolitana de Macapá'; + case 21: + return 'Região Metropolitana de Grande São Luís'; + case 22: + return 'Região Administrativa Integrada de Desenvolvimento de Grande Teresina' + case 23: + return 'Região Metropolitana de Fortaleza'; + case 24: + return 'Região Metropolitana de Natal'; + case 25: + return 'Região Metropolitana de João Pessoa'; + case 26: + return 'Região Metropolitana de Recife'; + case 27: + return 'Região Metropolitana de Maceió'; + case 28: + return 'Região Metropolitana de Aracaju'; + case 29: + return 'Região Metropolitana de Salvador'; + case 31: + return 'Região Metropolitana de Belo Horizonte'; + case 32: + return 'Região Metropolitana de Grande Vitória'; + case 33: + return 'Região Metropolitana do Rio de Janeiro'; + case 35: + return 'Região Metropolitana de São Paulo'; + case 41: + return 'Região Metropolitana de Curitiba'; + case 42: + return 'Região Metropolitana de Florianópolis'; + case 43: + return 'Região Metropolitana de Porto Alegre'; + case 51: + return 'Região Metropolitana de Vale do Rio Cuiabá'; + case 52: + return 'Região Metropolitana de Goiânia'; + default: + return 'Não é região metropolitana ou região administrativa integrada'; + } +}; diff --git a/src/libs/convert/modality.js b/src/libs/convert/modality.js new file mode 100644 index 0000000000000000000000000000000000000000..a4c56f52ae800dace35c344245b30cf4c741655a --- /dev/null +++ b/src/libs/convert/modality.js @@ -0,0 +1,32 @@ +/* +Copyright (C) 2024 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-node is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +simcaq-node is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +module.exports = function modality(id) { + switch (id) { + case 1: + return 'Presencial'; + case 2: + return 'A distância'; + case 3: + return 'Não informado'; + case 99: + return 'Não frequenta instituição de ensino' + } +}; diff --git a/src/libs/convert/modalityShift.js b/src/libs/convert/modalityShift.js new file mode 100644 index 0000000000000000000000000000000000000000..23661130f016c476ff6da45217b0719ab59c1a15 --- /dev/null +++ b/src/libs/convert/modalityShift.js @@ -0,0 +1,42 @@ +/* +Copyright (C) 2024 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-node is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +simcaq-node is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +module.exports = function modalityShift(id) { + switch (id) { + case null: + return 'Não informado'; + case 1: + return 'Matutino'; + case 2: + return 'Vespertino'; + case 3: + return 'Noturno'; + case 4: + return 'Integral - matutino e vespertino'; + case 5: + return 'Outros'; + case 6: + return 'Não se aplica - pós graduação presencial'; + case 7: + return 'EaD ou semipresencial'; + case 99: + return 'Não frequenta instituição de ensino'; + } +}; diff --git a/src/libs/convert/newPnadAdmDependency.js b/src/libs/convert/newPnadAdmDependency.js new file mode 100644 index 0000000000000000000000000000000000000000..a5cc9d19632363635a829eb92f70f5ccfe25787d --- /dev/null +++ b/src/libs/convert/newPnadAdmDependency.js @@ -0,0 +1,30 @@ +/* +Copyright (C) 2024 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-node is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +simcaq-node is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +module.exports = function newPnadAdmDependency(id) { + switch (id) { + case 1: + return 'Pública'; + case 2: + return 'Privada'; + case 99: + return 'Não frequenta instituição de ensino'; + } +}; diff --git a/src/libs/convert/regionCode.js b/src/libs/convert/regionCode.js new file mode 100644 index 0000000000000000000000000000000000000000..fd21550366426a1a3ef8d1def4c6520a870a9ec6 --- /dev/null +++ b/src/libs/convert/regionCode.js @@ -0,0 +1,34 @@ +/* +Copyright (C) 2024 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-node is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +simcaq-node is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +module.exports = function regionCode(id) { + switch (id) { + case 1: + return 'Norte'; + case 2: + return 'Nordeste'; + case 3: + return 'Sudeste'; + case 4: + return 'Sul' + case 5: + return 'Centro-Oeste'; + } +}; diff --git a/src/libs/convert/yearsOfStudy.js b/src/libs/convert/yearsOfStudy.js new file mode 100644 index 0000000000000000000000000000000000000000..db474559b39841cbaf7d83af65122349a5ac42db --- /dev/null +++ b/src/libs/convert/yearsOfStudy.js @@ -0,0 +1,60 @@ +/* +Copyright (C) 2024 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-node is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +simcaq-node is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +module.exports = function yearsOfStudy(id) { + switch (id) { + case 0: + return 'Sem instrução e menos de 1 ano de estudo'; + case 1: + return '1 ano de estudo'; + case 2: + return '2 anos de estudo'; + case 3: + return '3 anos de estudo'; + case 4: + return '4 anos de estudo'; + case 5: + return '5 anos de estudo'; + case 6: + return '6 anos de estudo'; + case 7: + return '7 anos de estudo'; + case 8: + return '8 anos de estudo'; + case 9: + return '9 anos de estudo'; + case 10: + return '10 anos de estudo'; + case 11: + return '11 anos de estudo'; + case 12: + return '12 anos de estudo'; + case 13: + return '13 anos de estudo'; + case 14: + return '14 anos de estudo'; + case 15: + return '15 anos de estudo'; + case 16: + return '16 anos ou mais de estudo'; + case 99: + return 'Não se aplica - 17 anos ou menos'; + } +}; diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index cb549d3d57326365f2289d6f7786123941cf2a87..7229c2b48e5b02b6e9d95099e24b60b1bda39c92 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -101,6 +101,18 @@ const supplyDimension = require(`${libs}/convert/supplyDimension`); const type = require(`${libs}/convert/type`); const level = require(`${libs}/convert/level`); const scholarDependency = require(`${libs}/convert/scholarDependency`); +const newPnadAdmDependency = require(`${libs}/convert/newPnadAdmDependency`); +const illiteracy = require(`${libs}/convert/illiteracy`); +const yearsOfStudy = require(`${libs}/convert/yearsOfStudy`); +const instructionLevel = require(`${libs}/convert/instructionLevel`); +const attendsSchool = require(`${libs}/convert/attendsSchool`); +const modality = require(`${libs}/convert/modality`); +const attendedModality = require(`${libs}/convert/attendedModality`); +const ethnicGroupNewPnad = require(`${libs}/convert/ethnicGroupNewPnad`); +const capitalCode = require(`${libs}/convert/capitalCode`); +const regionCode = require(`${libs}/convert/regionCode`); +const metroCode = require(`${libs}/convert/metroCode`); +const modalityShift = require(`${libs}/convert/modalityShift`); const ids = { gender_id: gender, @@ -193,7 +205,20 @@ const ids = { supply_dimension_id: supplyDimension, type_id: type, level_id: level, - scholar_dependency_id: scholarDependency + scholar_dependency_id: scholarDependency, + new_pnad_adm_dependency_id: newPnadAdmDependency, + illiteracy_id: illiteracy, + years_of_study_id: yearsOfStudy, + instruction_level_id: instructionLevel, + attends_school_id: attendsSchool, + modality_id: modality, + attended_modality_id: attendedModality, + bolsa_familia_id: attendsSchool, + new_pnad_ethnic_group_id: ethnicGroupNewPnad, + cap_code_id: capitalCode, + reg_code_id: regionCode, + metro_code_id: metroCode, + modality_shift_id: modalityShift }; function transform(removeId=false) { @@ -309,5 +334,17 @@ module.exports = { peePorCategoria, pee, shift, - admDependencyPub + admDependencyPub, + newPnadAdmDependency, + illiteracy, + yearsOfStudy, + instructionLevel, + attendsSchool, + modality, + attendedModality, + ethnicGroupNewPnad, + capitalCode, + regionCode, + metroCode, + modalityShift }; diff --git a/src/libs/routes_v1/api.js b/src/libs/routes_v1/api.js index 103d981dc8068802997551503c2b2939a2094773..53f9e4df0552ed33464f0d34b29dffcd7c02494b 100644 --- a/src/libs/routes_v1/api.js +++ b/src/libs/routes_v1/api.js @@ -141,6 +141,8 @@ const publication = require(`${libs}/routes_v1/publication`); const activity = require(`${libs}/routes_v1/activity`); +const newPnad = require(`${libs}/routes_v1/newPnad`); + const email = require(`${libs}/routes_v1/email`); api.get('/', (req, res) => { @@ -202,6 +204,7 @@ api.use('/disciplines', disciplines); api.use('/universityLocalOffer', universityLocalOffer); api.use('/message', message); api.use('/course_students', courseStudents); +api.use('/new_pnad', newPnad); //Publication api.use('/publication', publication); diff --git a/src/libs/routes_v1/liquidEnrollmentRatio.js b/src/libs/routes_v1/liquidEnrollmentRatio.js index 63bd91685a8df488731a267d268a929a6252a8df..4e3b6f4bff2cff7371500e3795d5d6529071a951 100644 --- a/src/libs/routes_v1/liquidEnrollmentRatio.js +++ b/src/libs/routes_v1/liquidEnrollmentRatio.js @@ -348,6 +348,7 @@ liquidEnrollmentRatioApp.get('/', rqf.parse(),(req, res, next) => { if ("education_level_short" in req.filter) { if (Array.isArray(req.filter.education_level_short)) { + console.log("ENTROU NO PRIMEIRO IF") var stringQuery = ''; for(let i = 0; i < req.filter.education_level_short.length - 1; i++) { stringQuery = stringQuery + ConvertEnrollment(req.filter.education_level_short[i]) + ' OR '; @@ -389,6 +390,7 @@ liquidEnrollmentRatioApp.get('/', rqf.parse(),(req, res, next) => { if ("education_level_short" in req.filter) { if (Array.isArray(req.filter.education_level_short)) { + console.log("ENTROU NO SEGUNDO IF") var stringQuery = ''; for(let i = 0; i < req.filter.education_level_short.length - 1; i++) { stringQuery = stringQuery + convertPnad(req.filter.education_level_short[i]) + ' OR '; diff --git a/src/libs/routes_v1/newPnad.js b/src/libs/routes_v1/newPnad.js new file mode 100644 index 0000000000000000000000000000000000000000..cac2d7b833cda149d5013f91cc871507bf35afb9 --- /dev/null +++ b/src/libs/routes_v1/newPnad.js @@ -0,0 +1,387 @@ +/* +Copyright (C) 2024 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-node is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +simcaq-node is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +const express = require('express'); + +const PnadNovoApp = express.Router(); + +const libs = `${process.cwd()}/libs`; + +const squel = require('squel'); + +const query = require(`${libs}/middlewares/query`).query; + +const response = require(`${libs}/middlewares/response`); + +const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); + +const id2str = require(`${libs}/middlewares/id2str`); + +const config = require(`${libs}/config`); + +const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware; + +let rqf = new ReqQueryFields(); + +PnadNovoApp.use(cache('15 day')); + +PnadNovoApp.get('/years', (req, res, next) => { + req.sql.from('pnad_novo') + .field('DISTINCT pnad_novo.ano_ref', 'year') + next(); +}, query, response('years')); + +PnadNovoApp.get('/illiteracy', (req, res, next) => { + req.result = [] + + for (let i = 0; i < 2; i++) { + req.result.push({ + id: i, name: id2str.Illiteracy(i) + }); + + } + req.result.push({id: 9, name: id2str.Illiteracy(9)}); + next(); +}, response('illiteracy')); + +PnadNovoApp.get('/years_of_study', (req, res, next) => { + req.result = [] + + for (let i = 0; i < 17; i++) { + req.result.push({ + id: i, name: id2str.yearsOfStudy(i) + }); + } + + req.result.push({id: 99, name: id2str.yearsOfStudy(99)}); + next(); +}, response('years_of_study')); + +PnadNovoApp.get('/instruction_level', (req, res, next) => { + req.result = [] + + for (let i = 1; i < 9; i++) { + req.result.push({ + id: i, name: id2str.instructionLevel(i) + }); + } + + next(); +}, response('instruction_level')); + +PnadNovoApp.get('/adm_dependency', (req, res, next) => { + req.result = [] + for (let i = 1; i < 3; i++) { + req.result.push({ + id: i, name: id2str.newPnadAdmDependency(i) + }); + } + req.result.push({id: 99, name: id2str.newPnadAdmDependency(99)}); + next(); +}, response('adm_dependency')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'id', + table: 'pnad_novo', + tableField: 'id', + where: { + relation: '=', + type: 'integer', + field: 'id' + } +}).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', + foreignTable: 'pnad_novo' + } +}).addValue({ + name: 'state_not', + table: 'estado', + tableField: ['nome', 'id'], + resultField: ['state_name', 'state_id'], + where: { + relation: '<>', + type: 'integer', + field: 'cod_uf', + table: 'pnad_novo' + }, + join: { + primary: 'id', + foreign: 'cod_uf', + foreignTable: 'pnad_novo' + } +}).addValue({ + name: 'illiteracy', + table: 'pnad_novo', + tableField: 'analfabetismo', + resultField: 'illiteracy_id', + where: { + relation: '=', + type: 'integer', + field: 'analfabetismo' + } +}).addValue({ + name: 'years_of_study', + table: 'pnad_novo', + tableField: 'anos_de_estudo', + resultField: 'years_of_study_id', + where: { + relation: '=', + type: 'integer', + field: 'anos_de_estudo' + } +}).addValue({ + name: 'instruction_level', + table: 'pnad_novo', + tableField: 'nivel_de_instrucao', + resultField: 'instruction_level_id', + where: { + relation: '=', + type: 'integer', + field: 'nivel_de_instrucao' + } +}).addValue({ + name: 'new_pnad_adm_dependency', + table: 'pnad_novo', + tableField: 'dependencia_adm', + resultField: 'new_pnad_adm_dependency_id', + where: { + relation: '=', + type: 'integer', + field: 'dependencia_adm' + } +}).addValue({ + name: 'attends_school', + table: 'pnad_novo', + tableField: 'frequenta_escola', + resultField: 'attends_school_id', + where: { + relation: '=', + type: 'integer', + field: 'frequenta_escola' + } +}).addValue({ + name: 'modality', + table: 'pnad_novo', + tableField: 'modalidade', + resultField: 'modality_id', + where: { + relation: '=', + type: 'integer', + field: 'modalidade' + } +}).addValue({ + name: 'attended_modality', + table: 'pnad_novo', + tableField: 'nivel_etapa_modalidade_freq', + resultField: 'attended_modality_id', + where: { + relation: '=', + type: 'integer', + field: 'nivel_etapa_modalidade_freq' + } +}).addValue({ + name: 'modality_shift', + table: 'pnad_novo', + tableField: 'turno_nivel_etapa', + resultField: 'modality_shift_id', + where: { + relation: '=', + type: 'integer', + field: 'modality_shift_id' + } +}).addValue({ + name: 'bolsa_familia', + table: 'pnad_novo', + tableField: 'recebeu_rendimentos_de_programa_bolsa_familia', + resultField: 'bolsa_familia_id', + where: { + relation: '=', + type: 'integer', + field: 'recebeu_rendimentos_de_programa_bolsa_familia' + } +}).addValue({ + name: 'new_pnad_ethnic_group', + table: 'pnad_novo', + tableField: 'cor_raca', + resultField: 'new_pnad_ethnic_group_id', + where: { + relation: '=', + type: 'integer', + field: 'cor_raca' + } +}).addValue({ + name: 'age_range', + table: 'pnad_novo', + tableField: 'faixa_etaria', + resultField: 'age_range_all_id', + where: { + relation: '=', + type: 'integer', + field: 'faixa_etaria' + } +}).addValue({ + name: 'income_range', + table: 'pnad_novo', + tableField: 'faixa_rendimento', + resultField: 'income_range', + where: { + relation: '=', + type: 'integer', + field: 'faixa_rendimento' + } +}).addValue({ + name: 'gender', + table: 'pnad_novo', + tableField: 'sexo', + resultField: 'gender_id', + where: { + relation: '=', + type: 'integer', + field: 'sexo' + } +}).addValue({ + name: 'cap_code', + table: 'pnad_novo', + tableField: 'cod_cap', + resultField: 'cap_code_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_cap' + } +}).addValue({ + name: 'reg_code', + table: 'pnad_novo', + tableField: 'cod_regiao', + resultField: 'reg_code_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_regiao' + } +}).addValue({ + name: 'metro_code', + table: 'pnad_novo', + tableField: 'cod_rm_ride', + resultField: 'metro_code_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_rm_ride' + } +}).addValue({ + name: 'min_year', + table: 'pnad_novo', + tableField: 'ano_ref', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + field: 'ano_ref' + } +}).addValue({ + name: 'max_year', + table: 'pnad_novo', + tableField: '', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + field: 'ano_ref' + } +}).addField({ + name: 'search', + field: false, + where: true +}).addValueToField({ + name: 'name', + table: 'pnad_novo', + tableField: 'nome', + where: { + relation: 'LIKE', + type: 'string', + field: 'nome' + } +}, 'search').addValue({ + name: 'mesoregion', + table: 'pnad_novo', + tableField: 'mesorregiao_id', + where: { + relation: '=', + type: 'integer', + field: 'mesorregiao_id' + } +}).addValue({ + name: 'microregion', + table: 'pnad_novo', + tableField: 'microrregiao_id', + where: { + relation: '=', + type: 'integer', + field: 'microrregiao_id' + } +}).addValueToField({ + name: 'region', + table: 'estado', + tableField: 'regiao_id', + resultField: 'region_id', + where: { + relation: '=', + type: 'integer', + field: 'regiao_id', + table: 'estado' + }, + join: { + primary: 'id', + foreign: 'estado_id', + foreignTable: 'municipio' + } +}, 'filter'); + +PnadNovoApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + req.sql.from('pnad_novo') + .field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total') + .field('pnad_novo.ano_ref', 'year') + .group('pnad_novo.ano_ref') + .order('pnad_novo.ano_ref') + console.log(req.sql.toString()) + next(); +}, query, id2str.transform(false),response('pnad_novo')); + +module.exports = PnadNovoApp;