diff --git a/src/libs/convert/supplyDimension.js b/src/libs/convert/supplyDimension.js new file mode 100644 index 0000000000000000000000000000000000000000..40f5ca9ace759598ad128fbfd74fd509ad4150d5 --- /dev/null +++ b/src/libs/convert/supplyDimension.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 <https://www.gnu.org/licenses/>. +*/ + +module.exports = function supplyDimension(id) { + switch(id) { + case 1: + return 'Número de matrÃculas'; + case 2: + return 'Número de turmas'; + case 3: + return 'Número de salas'; + case 4: + return 'Número de professores'; + case 5: + return 'Número de funcionários'; + default: + return 'Não especificado'; + } +} \ No newline at end of file diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index 43cc1e0f9ed5edfd32a05c56ab665410034ec5b5..8c2b068d68e2abd596e5c54b6dd681dc1bfb7cae 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -97,6 +97,7 @@ const peePorCategoria = require(`${libs}/convert/peePorCategoria`); const pee = require(`${libs}/convert/booleanVariable`); const shift = require(`${libs}/convert/shift`); const admDependencyPub = require(`${libs}/convert/admDependencyPub`); +const supplyDimension = require(`${libs}/convert/supplyDimension`); const ids = { gender_id: gender, @@ -185,7 +186,8 @@ const ids = { diff_location_id: diffLocation, pee_por_categoria: peePorCategoria, pee_id: pee, - shift_id: shift + shift_id: shift, + supply_dimension_id: supplyDimension }; function transform(removeId=false) { diff --git a/src/libs/routes_v2/api.js b/src/libs/routes_v2/api.js index 195a23e8676c93e1c33ed6fd166078869b8d33f6..b675c882d03d30de38fe174fc17ae4652688260c 100644 --- a/src/libs/routes_v2/api.js +++ b/src/libs/routes_v2/api.js @@ -150,6 +150,8 @@ const simcaqNumberOfEmployees = require(`${libs}/routes_v2/simcaqNumberOfEmploye const simcaqNewClasses = require(`${libs}/routes_v2/simcaqNewClasses`); +const simcaqResult = require(`${libs}/routes_v2/simcaqResult`); + api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API v2 is running' }); }); @@ -216,5 +218,6 @@ api.use('/simcaq_classroom_size', simcaqClassroomSize); api.use('/simcaq_workload', simcaqWorkload); api.use('/simcaq_number_of_employees', simcaqNumberOfEmployees); api.use('/simcaq_new_classes', simcaqNewClasses); +api.use('/simcaq_result', simcaqResult); module.exports = api; diff --git a/src/libs/routes_v2/simcaqClassroomSize.js b/src/libs/routes_v2/simcaqClassroomSize.js index 9b48f3b349299c4bfc28aeda889d46057ef081e0..d70d084ec14d30dad60945547234ff23079d7bf8 100644 --- a/src/libs/routes_v2/simcaqClassroomSize.js +++ b/src/libs/routes_v2/simcaqClassroomSize.js @@ -142,6 +142,6 @@ simcaqClassroomSizeApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .group('simcaq_tamanho_das_turmas.ano_censo') .group('simcaq_tamanho_das_turmas.etapa'); next(); -}, query, id2str.transform(), response('classroomSize')); +}, query, id2str.transform(), response('simcaqClassroomSize')); module.exports = simcaqClassroomSizeApp; diff --git a/src/libs/routes_v2/simcaqResult.js b/src/libs/routes_v2/simcaqResult.js new file mode 100644 index 0000000000000000000000000000000000000000..3ba50ad0948b0bbbc42da746efdb5b47f183e14f --- /dev/null +++ b/src/libs/routes_v2/simcaqResult.js @@ -0,0 +1,140 @@ +/* +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 simcaqResultApp = 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`); + +simcaqResultApp.use(cache('15 day')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'city', + table: 'municipio', + tableField: ['nome', 'id'], + resultField: ['city_name', 'city_id'], + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'simcaq_resultado' + } +}, 'dims').addValue({ + name: 'state', + table: 'estado', + tableField: ['nome', 'id'], + resultField: ['state_name', 'state_id'], + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'estado_id', + foreignTable: 'simcaq_resultado' + } +}, 'dims').addValue({ + name: 'school', + table: 'escola_agregada', + tableField: 'id', + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'escola_id', + foreignTable: 'simcaq_resultado' + } +}, 'dims').addValue({ + name: 'adm_dependency_public_id', + table: 'simcaq_resultado', + tableField: 'rede', + where: { + relation: '=', + type: 'integer', + field: 'rede' + } +}).addValue({ + name: 'year', + table: 'simcaq_resultado', + tableField: 'ano_censo', + where: { + relation: '=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'supply_dimension_id', + table: 'simcaq_resultado', + tableField: 'dimensao_oferta', + where: { + relation: '=', + type: 'integer', + field: 'dimensao_oferta' + } +}); + +simcaqResultApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + req.sql.from('simcaq_resultado') + .field('SUM(simcaq_resultado.atual)', 'current') + .field('simcaq_resultado.rede', 'adm_dependency_public_id') + .field('simcaq_resultado.ano_censo', 'year') + .field('simcaq_resultado.dimensao_oferta', 'supply_dimension_id') + .group('simcaq_resultado.ano_censo') + .group('simcaq_resultado.rede') + .group('simcaq_resultado.dimensao_oferta'); + next(); +}, query, id2str.transform(), response('simcaqResult')); + +module.exports = simcaqResultApp;