From 32fb486f6e0363d349719e7e8af0e7f5d5a00b1e Mon Sep 17 00:00:00 2001 From: Lewis <lgtg20@inf.ufpr.br> Date: Mon, 14 Oct 2024 12:02:06 -0300 Subject: [PATCH] Refactor education degree entity conversion functions --- src/libs/convert/educationDegreeEntity.js | 32 +++++++++++++++++++++++ src/libs/middlewares/aggregateData.js | 6 +++-- src/libs/middlewares/id2str.js | 7 +++-- src/libs/routes_v1/enrollmentAggregate.js | 24 +++++++++++++++++ src/libs/routes_v1/federativeEntity.js | 23 ++++++++++++++++ 5 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 src/libs/convert/educationDegreeEntity.js diff --git a/src/libs/convert/educationDegreeEntity.js b/src/libs/convert/educationDegreeEntity.js new file mode 100644 index 00000000..e16ba13f --- /dev/null +++ b/src/libs/convert/educationDegreeEntity.js @@ -0,0 +1,32 @@ +/* +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 educationDegreeEntity(id) { + switch (id) { + case 1: + return 'Ensino Fundamental'; + case 2: + return 'Ensino Médio'; + case 3: + return 'Graduação Com Licenciatura'; + case 4: + return 'Graduação Sem Licenciatura'; + } +}; diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js index b9b14eee..864c2f54 100644 --- a/src/libs/middlewares/aggregateData.js +++ b/src/libs/middlewares/aggregateData.js @@ -33,7 +33,8 @@ const convert = { age_range_entity: 'ageRangeEntity', post_graduation_entity: 'postGraduationEntity', contract_type_entity: 'contractType', - total_doc: "totalDoc" + total_doc: "totalDoc", + education_degree_entity: "educationDegreeEntity" } function aggregateData(req, res, next) { @@ -60,7 +61,8 @@ function aggregateData(req, res, next) { 'age_range_entity', 'post_graduation_entity', 'contract_type_entity', - 'total_doc' + 'total_doc', + 'education_degree_entity' ] let id; const fields = req.query.dims.split(','); diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index a53196e2..f366d90a 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -125,6 +125,7 @@ const educationLevelModEntityAgg = require(`${libs}/convert/educationLevelModEnt const ageRangeEntity = require(`${libs}/convert/ageRangeEntity`); const postGraduationEntity = require(`${libs}/convert/postGraduationEntity`); const totalDoc = require(`${libs}/convert/totalDoc`); +const educationDegreeEntity = require(`${libs}/convert/educationDegreeEntity`); const ids = { gender_id: gender, @@ -242,7 +243,8 @@ const ids = { age_range_entity: ageRangeEntity, post_graduation_entity: postGraduationEntity, special_education_entity: specialEducationEntity, - total_doc: totalDoc + total_doc: totalDoc, + education_degree_entity: educationDegreeEntity }; function transform(removeId=false) { @@ -382,5 +384,6 @@ module.exports = { ageRangeEntity, postGraduationEntity, specialEducationEntity, - totalDoc + totalDoc, + educationDegreeEntity }; diff --git a/src/libs/routes_v1/enrollmentAggregate.js b/src/libs/routes_v1/enrollmentAggregate.js index b44bb70a..034aae7f 100644 --- a/src/libs/routes_v1/enrollmentAggregate.js +++ b/src/libs/routes_v1/enrollmentAggregate.js @@ -78,6 +78,20 @@ enrollmentAggregateApp.get('/adm_dependency_detailed', (req, res, next) => { next(); }, response('adm_dependency_detailed')); +enrollmentAggregateApp.get('/government_agreement', cache('15 day'), (req, res, next) => { + req.result = [{ + id: "null", + name: id2str.governmentAgreement("null") + }]; + for(let i = 1; i <= 6; ++i) { + req.result.push({ + id: i, + name: id2str.governmentAgreement(i) + }); + }; + next(); +}, response('government_agreement')); + enrollmentAggregateApp.get('/education_level_mod_agg', (req, res, next) => { req.result = [] @@ -486,6 +500,16 @@ rqf.addField({ field: 'localizacao_diferenciada_par', value: 'null' } +}).addValue({ + name: 'government_agreement', + table: 'escola', + tableField: 'dependencia_convenio_publico', + resultField: 'government_agreement_id', + where: { + relation: '=', + type: 'integer', + field: 'dependencia_convenio_publico' + } }); // Return all cities diff --git a/src/libs/routes_v1/federativeEntity.js b/src/libs/routes_v1/federativeEntity.js index 40668f76..661907c5 100644 --- a/src/libs/routes_v1/federativeEntity.js +++ b/src/libs/routes_v1/federativeEntity.js @@ -67,6 +67,17 @@ federativeEntityApp.get('/adm_dependency', (req, res, next) => { next(); }, response('adm_dependency')); +federativeEntityApp.get('/education_degree_entity', (req, res, next) => { + req.result = [] + + for (let i = 1; i <= 4; i++) { + req.result.push({ + id: i, name: id2str.educationDegreeEntity(i) + }); + } + next(); +}, response('education_degree_entity')); + federativeEntityApp.get('/adm_dependency_detailed', (req, res, next) => { req.result = [] @@ -535,6 +546,18 @@ federativeEntityApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .order('docentes_sinopse.ano_censo') .where(whereRule); } + else if (req.query.dims && req.query.dims.includes('education_degree_entity')) + { + req.sql.from('docentes_sinopse') + .field('SUM(docentes_sinopse.num_doc_esc_en_fund)', 'total_num_doc_esc_en_fund') + .field('SUM(docentes_sinopse.num_doc_esc_en_medio)', 'total_num_doc_esc_en_medio') + .field('SUM(docentes_sinopse.num_doc_esc_grad_com_licenciatura)', 'total_num_doc_esc_grad_com_licenciatura') + .field('SUM(docentes_sinopse.num_doc_esc_grad_sem_licenciatura)', 'total_num_doc_esc_grad_sem_licenciatura') + .field('docentes_sinopse.ano_censo', 'year') + .group('docentes_sinopse.ano_censo') + .order('docentes_sinopse.ano_censo') + .where(whereRule); + } else if (req.query.dims && req.query.dims.includes('location_entity')) { req.sql.from('docentes_sinopse') -- GitLab