diff --git a/src/libs/convert/scholarDependency.js b/src/libs/convert/scholarDependency.js new file mode 100644 index 0000000000000000000000000000000000000000..25684b9b1981f20e655289e61f67f772767bb694 --- /dev/null +++ b/src/libs/convert/scholarDependency.js @@ -0,0 +1,76 @@ +/* +Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-node is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +simcaq-node is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +module.exports = function scholarDependency(id) { + switch (id) { + case 1: + return "Biblioteca"; + case 2: + return "Sala de leitura"; + case 3: + return "Laboratório de informática"; + case 4: + return "Laboratório de ciências"; + case 5: + return "Parque infantil"; + case 6: + return "Quadra poliesportiva"; + case 7: + return "Quadras a serem cobertas"; + case 8: + return "Pátio"; + case 9: + return "Pátios a serem cobertos"; + case 10: + return "Sala de direção"; + case 11: + return "Secretaria"; + case 12: + return "Sala de professores"; + case 13: + return "Cozinha"; + case 14: + return "Despensa"; + case 15: + return "Almoxarifado"; + case 16: + return "Internet"; + case 17: + return "Internet banda larga"; + case 18: + return "Banheiro dentro do prédio"; + case 19: + return "Banheiro adequado para educação infantil dentro do prédio"; + case 20: + return "Fornecimento de energia"; + case 21: + return "Abastecimento de água"; + case 22: + return "Ãgua filtrada"; + case 23: + return "Coleta de esgoto"; + case 24: + return "Dependências adaptadas para pessoas com deficiências"; + case 25: + return "Banheiros adaptados para pessoas com deficiências"; + default: + return "Dependência escolar desconhecida"; + } +} \ No newline at end of file diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index 39d819aa13bb2f269b53b9ff39579b12849e5ccb..cb549d3d57326365f2289d6f7786123941cf2a87 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -100,6 +100,7 @@ const admDependencyPub = require(`${libs}/convert/admDependencyPub`); 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 ids = { gender_id: gender, @@ -191,7 +192,8 @@ const ids = { shift_id: shift, supply_dimension_id: supplyDimension, type_id: type, - level_id: level + level_id: level, + scholar_dependency_id: scholarDependency }; function transform(removeId=false) { diff --git a/src/libs/routes_v2/api.js b/src/libs/routes_v2/api.js index 5c00d3fed30c4a2daf975097aee6cfd24e0582f2..a8e1e1b7d0c62e8b5c62037b8b3d55d6f22165e8 100644 --- a/src/libs/routes_v2/api.js +++ b/src/libs/routes_v2/api.js @@ -160,6 +160,8 @@ const simcaqAggregatedEnrollment = require(`${libs}/routes_v2/simcaqAggregatedEn const simcaqTeacherCityPlan = require(`${libs}/routes_v2/simcaqTeacherCityPlan`); +const simcaqSchoolInfrastructure = require(`${libs}/routes_v2/simcaqSchoolInfrastructure`); + api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API v2 is running' }); }); @@ -231,5 +233,6 @@ api.use('/simcaq_number_of_teachers', simcaqNumberOfTeachers); api.use('/simcaq_enrollment_projection', simcaqEnrollmentProjection); api.use('/simcaq_aggregated_enrollment', simcaqAggregatedEnrollment); api.use('/simcaq_teacher_city_plan', simcaqTeacherCityPlan); +api.use('/simcaq_school_infrastructure', simcaqSchoolInfrastructure); module.exports = api; diff --git a/src/libs/routes_v2/simcaqSchoolInfrastructure.js b/src/libs/routes_v2/simcaqSchoolInfrastructure.js new file mode 100644 index 0000000000000000000000000000000000000000..f10022cb63c511bb5857b9a188b2dd1bcc026420 --- /dev/null +++ b/src/libs/routes_v2/simcaqSchoolInfrastructure.js @@ -0,0 +1,87 @@ +/* +Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-node is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +simcaq-node is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +const express = require('express'); + +const simcaqSchoolInfrastructureApp = 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 reqBody = require(`${libs}/middlewares/reqBody`); + +const config = require(`${libs}/config`); + +const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware; + +let rqf = new ReqQueryFields(); + +const id2str = require(`${libs}/middlewares/id2str`); + +simcaqSchoolInfrastructureApp.use(cache('15 day')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'year', + table: 'simcaq_school_infrastructure', + tableField: 'ano_censo', + where: { + relation: '=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'scholar_dependency', + table: 'simcaq_school_infrastructure', + tableField: 'scholar_dependency_id', + where: { + relation: '=', + type: 'integer', + field: 'scholar_dependency_id' + } +}); + +simcaqSchoolInfrastructureApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + req.sql.from('simcaq_school_infrastructure') + .field('simcaq_school_infrastructure.ano_censo', 'year') + .field('simcaq_school_infrastructure.scholar_dependency_id', 'scholar_dependency_id') + .field('SUM(simcaq_school_infrastructure.total_schools)', 'total_schools') + .field('SUM(total_no_dependency)', 'total_schools_without_dependency') + .field('SUM(total_with_dependency)', 'total_schools_with_dependency') + .group('simcaq_school_infrastructure.ano_censo') + .group('simcaq_school_infrastructure.scholar_dependency_id'); + next(); +}, query, id2str.transform(), response('simcaqSchoolInfrastructure')); + +module.exports = simcaqSchoolInfrastructureApp;