From 9698bb016b7d6fa9bd168d46b393909a3053f0d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20A=2E=20Okida=20Gon=C3=A7alves?= <laog19@inf.ufpr.br> Date: Fri, 24 Mar 2023 11:48:03 -0300 Subject: [PATCH] Add enrollment diagnosis route --- src/libs/routes_v2/api.js | 3 + src/libs/routes_v2/enrollment_diagnosis.js | 133 +++++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 src/libs/routes_v2/enrollment_diagnosis.js diff --git a/src/libs/routes_v2/api.js b/src/libs/routes_v2/api.js index 5365e80e..071f8ffa 100644 --- a/src/libs/routes_v2/api.js +++ b/src/libs/routes_v2/api.js @@ -136,6 +136,8 @@ const courseStudents = require(`${libs}/routes_v2/courseStudents`); const simcaqFirstReport = require(`${libs}/routes_v2/simcaqFirstReport`); +const enrollmentDiagnosis = require(`${libs}/routes_v2/enrollment_diagnosis`); + api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API v2 is running' }); }); @@ -195,5 +197,6 @@ api.use('/universityLocalOffer', universityLocalOffer); api.use('/message', message); api.use('/course_students', courseStudents); api.use('/simcaq_first_report', simcaqFirstReport); +api.use('/enrollment_diagnosis', enrollmentDiagnosis); module.exports = api; diff --git a/src/libs/routes_v2/enrollment_diagnosis.js b/src/libs/routes_v2/enrollment_diagnosis.js new file mode 100644 index 00000000..221549e5 --- /dev/null +++ b/src/libs/routes_v2/enrollment_diagnosis.js @@ -0,0 +1,133 @@ +/* +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 enrollmentDiagnosisApp = 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(); + +enrollmentDiagnosisApp.use(cache('15 day')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addValue({ + name: 'year', + table: 'simcaq_diagnostico_de_matricula', + tableField: 'ano_censo', + where: { + relation: '=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'city', + table: 'simcaq_diagnostico_de_matricula', + tableField: 'municipio_id', + where: { + relation: '=', + type: 'integer', + field: 'municipio_id' + } +}).addValue({ + name: 'state', + table: 'simcaq_diagnostico_de_matricula', + tableField: 'estado_id', + where: { + relation: '=', + type: 'integer', + field: 'estado_id' + } +}).addValue({ + name: 'school', + table: 'simcaq_diagnostico_de_matricula', + tableField: 'id', + where: { + relation: '=', + type: 'integer', + field: 'id' + } +}).addValue({ + name: 'stage', + table: 'simcaq_diagnostico_de_matricula', + tableField: 'etapa', + where: { + relation: '=', + type: 'integer', + field: 'etapa' + } +}).addValue({ + name: 'location', + table: 'simcaq_diagnostico_de_matricula', + tableField: 'localizacao_id', + where: { + relation: '=', + type: 'integer', + field: 'localizacao_id' + } +}).addValue({ + name: 'adm_dependency', + table: 'simcaq_diagnostico_de_matricula', + tableField: 'dependencia_adm_id', + where: { + relation: '=', + type: 'integer', + field: 'dependencia_adm_id' + } +}); + +enrollmentDiagnosisApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + req.sql.from('simcaq_diagnostico_de_matricula') + .field('simcaq_diagnostico_de_matricula.etapa', 'stage') + .field('SUM(simcaq_diagnostico_de_matricula.total)', 'total') + .field('SUM(simcaq_diagnostico_de_matricula.matriculas_federal)', 'federal_enrollments') + .field('SUM(simcaq_diagnostico_de_matricula.matriculas_estadual)', 'state_enrollments') + .field('SUM(simcaq_diagnostico_de_matricula.matriculas_municipal)', 'city_enrollments') + .field('SUM(simcaq_diagnostico_de_matricula.matriculas_priv_conv_sem_fin)', 'private_affiliated_non_profit_enrollments') + .field('SUM(simcaq_diagnostico_de_matricula.matriculas_priv_conv_com_fin)', 'private_affiliated_for_profit_enrollments') + .field('SUM(simcaq_diagnostico_de_matricula.matriculas_priv_nao_conv_sem_fin)', 'private_not_affiliated_non_profit_enrollments') + .field('SUM(simcaq_diagnostico_de_matricula.matriculas_priv_nao_conv_com_fin)', 'private_not_affiliated_for_profit_enrollments') + .field('SUM(simcaq_diagnostico_de_matricula.matriculas_urbana)', 'urban_enrollments') + .field('SUM(simcaq_diagnostico_de_matricula.matriculas_rural)', 'rural_enrollments') + .group('simcaq_diagnostico_de_matricula.etapa'); + + console.log(req.sql.toString()); + next(); +}, query, response('enrollmentDiagnosis')); + +module.exports = enrollmentDiagnosisApp; -- GitLab