diff --git a/src/libs/routes_v2/api.js b/src/libs/routes_v2/api.js index 33822b8281231e04f15986fb66bacbb01204857e..fd345d05d5ecbf430d2cf71b04cc6289a5696ef3 100644 --- a/src/libs/routes_v2/api.js +++ b/src/libs/routes_v2/api.js @@ -142,6 +142,12 @@ const simcaqSecondReport = require(`${libs}/routes_v2/simcaqSecondReport`); const simcaqDivisionOfResponsibility = require(`${libs}/routes_v2/simcaqDivisionOfResponsibility`); +const simcaqClassroomSize = require(`${libs}/routes_v2/simcaqClassroomSize`); + +const simcaqWorkload = require(`${libs}/routes_v2/simcaqWorkload`); + +const simcaqNumberOfEmployees = require(`${libs}/routes_v2/simcaqNumberOfEmployees`); + api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API v2 is running' }); }); @@ -204,5 +210,8 @@ api.use('/simcaq_first_report', simcaqFirstReport); api.use('/simcaq_enrollment_diagnosis', simcaqEnrollmentDiagnosis); api.use('/simcaq_second_report', simcaqSecondReport); api.use('/simcaq_division_of_responsibility', simcaqDivisionOfResponsibility); +api.use('/simcaq_classroom_size', simcaqClassroomSize); +api.use('/simcaq_workload', simcaqWorkload); +api.use('/simcaq_number_of_employees', simcaqNumberOfEmployees); module.exports = api; diff --git a/src/libs/routes_v2/simcaqClassroomSize.js b/src/libs/routes_v2/simcaqClassroomSize.js new file mode 100644 index 0000000000000000000000000000000000000000..9b48f3b349299c4bfc28aeda889d46057ef081e0 --- /dev/null +++ b/src/libs/routes_v2/simcaqClassroomSize.js @@ -0,0 +1,147 @@ +/* +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 simcaqClassroomSizeApp = 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`); + +simcaqClassroomSizeApp.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_tamanho_das_turmas' + } +}, '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_tamanho_das_turmas' + } +}, 'dims').addValue({ + name: 'school', + table: 'escola_agregada', + tableField: 'id', + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'escola_id', + foreignTable: 'simcaq_tamanho_das_turmas' + } +}, 'dims').addValue({ + name: 'education_level_short_id', + table: 'simcaq_tamanho_das_turmas', + tableField: 'etapa', + where: { + relation: '=', + type: 'integer', + field: 'etapa' + } +}).addValue({ + name: 'location', + table: 'simcaq_tamanho_das_turmas', + tableField: 'localizacao_id', + where: { + relation: '=', + type: 'integer', + field: 'localizacao_id' + } +}).addValue({ + name: 'adm_dependency_public_id', + table: 'simcaq_tamanho_das_turmas', + tableField: 'rede', + where: { + relation: '=', + type: 'integer', + field: 'rede' + } +}).addValue({ + name: 'year', + table: 'simcaq_tamanho_das_turmas', + tableField: 'ano_censo', + where: { + relation: '=', + type: 'integer', + field: 'ano_censo' + } +}); + +simcaqClassroomSizeApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + req.sql.from('simcaq_tamanho_das_turmas') + .field('AVG(simcaq_tamanho_das_turmas.num_matricula)', 'average_classroom_size') + .field('simcaq_tamanho_das_turmas.etapa', 'education_level_short_id') + .field('simcaq_tamanho_das_turmas.ano_censo', 'year') + .group('simcaq_tamanho_das_turmas.ano_censo') + .group('simcaq_tamanho_das_turmas.etapa'); + next(); +}, query, id2str.transform(), response('classroomSize')); + +module.exports = simcaqClassroomSizeApp; diff --git a/src/libs/routes_v2/simcaqDivisionOfResponsibility.js b/src/libs/routes_v2/simcaqDivisionOfResponsibility.js index 3ec798e3ea6ae2921a695cf413b97eefbe0258a4..b9704b3b7d8590dbef02653a254840d0914e9af3 100644 --- a/src/libs/routes_v2/simcaqDivisionOfResponsibility.js +++ b/src/libs/routes_v2/simcaqDivisionOfResponsibility.js @@ -127,9 +127,11 @@ rqf.addField({ simcaqDivisionOfResponsibilityApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { req.sql.from('simcaq_divisao_de_responsabilidade') + .field('simcaq_divisao_de_responsabilidade.ano_censo', 'year') .field('SUM(simcaq_divisao_de_responsabilidade.total_matriculas)', 'enrollments') .field('simcaq_divisao_de_responsabilidade.etapa', 'education_level_short_id') .field('simcaq_divisao_de_responsabilidade.rede', 'adm_dependency_public_id') + .group('simcaq_divisao_de_responsabilidade.ano_censo') .group('simcaq_divisao_de_responsabilidade.etapa') .group('simcaq_divisao_de_responsabilidade.rede'); next(); diff --git a/src/libs/routes_v2/simcaqNumberOfEmployees.js b/src/libs/routes_v2/simcaqNumberOfEmployees.js new file mode 100644 index 0000000000000000000000000000000000000000..58a28ffaafae673f47ae817f21dafe2b54abd8ec --- /dev/null +++ b/src/libs/routes_v2/simcaqNumberOfEmployees.js @@ -0,0 +1,129 @@ +/* +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 simcaqNumberOfEmployeesApp = 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`); + +simcaqNumberOfEmployeesApp.use(cache('15 day')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'year', + table: 'simcaq_numero_de_funcionarios', + tableField: 'ano_censo', + where: { + relation: '=', + type: 'integer', + field: 'ano_censo' + } +}).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_numero_de_funcionarios' + } +}, '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_numero_de_funcionarios' + } +}, 'dims').addValue({ + name: 'school', + table: 'escola_agregada', + tableField: 'id', + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'escola_id', + foreignTable: 'simcaq_numero_de_funcionarios' + } +}, 'dims').addValue({ + name: 'adm_dependency_public_id', + table: 'simcaq_numero_de_funcionarios', + tableField: 'rede', + where: { + relation: '=', + type: 'integer', + field: 'rede' + } +}); + +simcaqNumberOfEmployeesApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + req.sql.from('simcaq_numero_de_funcionarios') + .field('SUM(num_funcionarios)', 'average_number_of_employees') + .field('simcaq_numero_de_funcionarios.rede', 'adm_dependency_public_id') + .field('simcaq_numero_de_funcionarios.ano_censo', 'year') + .group('simcaq_numero_de_funcionarios.rede') + .group('simcaq_numero_de_funcionarios.ano_censo'); + next(); +}, query, id2str.transform(), response('simcaqNumberOfEmployees')); + +module.exports = simcaqNumberOfEmployeesApp; diff --git a/src/libs/routes_v2/simcaqWorkload.js b/src/libs/routes_v2/simcaqWorkload.js new file mode 100644 index 0000000000000000000000000000000000000000..b4584224f16b94b2490885493293f41ebb5b8f30 --- /dev/null +++ b/src/libs/routes_v2/simcaqWorkload.js @@ -0,0 +1,151 @@ +/* +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 simcaqWorkloadApp = 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`); + +simcaqWorkloadApp.use(cache('15 day')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'year', + table: 'simcaq_carga_horaria_de_ensino', + tableField: 'ano_censo', + where: { + relation: '=', + type: 'integer', + field: 'ano_censo' + } +}).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_carga_horaria_de_ensino' + } +}, '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_carga_horaria_de_ensino' + } +}, 'dims').addValue({ + name: 'school', + table: 'escola_agregada', + tableField: 'id', + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'escola_id', + foreignTable: 'simcaq_carga_horaria_de_ensino' + } +}, 'dims').addValue({ + name: 'adm_dependency_public_id', + table: 'simcaq_carga_horaria_de_ensino', + tableField: 'rede', + where: { + relation: '=', + type: 'integer', + field: 'rede' + } +}).addValue({ + name: 'education_level_short_id', + table: 'simcaq_carga_horaria_de_ensino', + tableField: 'etapa', + where: { + relation: '=', + type: 'integer', + field: 'etapa' + } +}).addValue({ + name: 'shift_id', + table: 'simcaq_carga_horaria_de_ensino', + tableField: 'turno', + where: { + relation: '=', + type: 'integer', + field: 'turno' + } +}); + +simcaqWorkloadApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + req.sql.from('simcaq_carga_horaria_de_ensino') + .field('AVG(duracao_turma_horas)', 'average_workload') + .field('simcaq_carga_horaria_de_ensino.etapa', 'education_level_short_id') + .field('simcaq_carga_horaria_de_ensino.turno', 'shift_id') + .field('simcaq_carga_horaria_de_ensino.rede', 'adm_dependency_public_id') + .field('simcaq_carga_horaria_de_ensino.ano_censo', 'year') + .group('simcaq_carga_horaria_de_ensino.etapa') + .group('simcaq_carga_horaria_de_ensino.turno') + .group('simcaq_carga_horaria_de_ensino.rede') + .group('simcaq_carga_horaria_de_ensino.ano_censo'); + next(); +}, query, id2str.transform(), response('simcaqWorkload')); + +module.exports = simcaqWorkloadApp;