From 77ea9f083cda5c11e4f57f55e816af71730c97d5 Mon Sep 17 00:00:00 2001 From: edsaibert <es23@inf.ufpr.br> Date: Tue, 28 Jan 2025 10:59:28 -0300 Subject: [PATCH 01/12] page not found error --- src/libs/routes_v1/api.js | 8 + .../routes_v1/superiorEnrollmentAggregate.js | 526 ++++++++++++++++++ 2 files changed, 534 insertions(+) create mode 100644 src/libs/routes_v1/superiorEnrollmentAggregate.js diff --git a/src/libs/routes_v1/api.js b/src/libs/routes_v1/api.js index 9880ac84..8d463a04 100644 --- a/src/libs/routes_v1/api.js +++ b/src/libs/routes_v1/api.js @@ -171,10 +171,17 @@ const adjustedLiquidFrequency = require(`${libs}/routes_v1/adjustedLiquidFrequen const iliteracyRate = require(`${libs}/routes_v1/iliteracyRate`); +// comentei para ver se o api.get abaixo ia dar certo (nao deu) +// const superiorEnrollmentAggregate = require(`${libs}/routes_v1/superiorEnrollmentAggregate`); + api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API v1 is running' }); }); +api.get('/superior_enrollment_aggregate', (req, res) => { + res.json({ msg: 'oi' }); +}) + // mount API routes_v1 api.use('/test', test); api.use('/user', user); @@ -244,6 +251,7 @@ api.use('/superior_education_conclusion_tax', superiorEducationConclusionTax) api.use('/basic_education_conclusion', basicEducationConclusion); api.use('/adjusted_liquid_frequency', adjustedLiquidFrequency); api.use('/iliteracy_rate', iliteracyRate); +// api.use('/superior_enrollment_aggregate', superiorEnrollmentAggregate); //Publication api.use('/publication', publication); diff --git a/src/libs/routes_v1/superiorEnrollmentAggregate.js b/src/libs/routes_v1/superiorEnrollmentAggregate.js new file mode 100644 index 00000000..800fbfe1 --- /dev/null +++ b/src/libs/routes_v1/superiorEnrollmentAggregate.js @@ -0,0 +1,526 @@ +/* +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 { result } = require('lodash'); + +const superiorEnrollmentAggregateApp = express.Router(); + +const libs = `${process.cwd()}/libs`; + +const log = require(`${libs}/log`)(module); + +const squel = require('squel'); + +const query = require(`${libs}/middlewares/query`).query; + +const response = require(`${libs}/middlewares/response`); + +const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); + +const aggregateData = require(`${libs}/middlewares/aggregateData`); + +const id2str = require(`${libs}/middlewares/id2str`); + +const config = require(`${libs}/config`); + +const addMissing = require(`${libs}/middlewares/addMissing`); + +const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware; + +superiorEnrollmentAggregateApp.use(cache('15 day')); + +let rqf = new ReqQueryFields(); + +// superiorEnrollmentAggregateApp.get('/years', (req, res, next) => { +// req.sql.from('escola') +// .field('DISTINCT escola.ano_censo', 'year') +// .where('escola.ano_censo >= 2021') +// next(); +// }, query, response('years')); + +// superiorEnrollmentAggregateApp.get('/adm_dependency', (req, res, next) => { +// req.result = [] + +// for (let i = 1; i <= 5; i++) { +// req.result.push({ +// id: i, name: id2str.admDependency(i) +// }); +// } +// next(); +// }, response('adm_dependency')); + +// superiorEnrollmentAggregateApp.get('/adm_dependency_detailed', (req, res, next) => { +// req.result = [] + +// for (let i = 1; i <= 8; i++) { +// req.result.push({ +// id: i, name: id2str.admDependencyPriv(i) +// }); +// } +// next(); +// }, response('adm_dependency_detailed')); + +// superiorEnrollmentAggregateApp.get('/government_agreement', (req, res, next) => { +// req.result = [] + +// for(let i = 1; i <= 6; ++i) { +// req.result.push({ +// id: i, +// name: id2str.governmentAgreement(i) +// }); +// }; +// next(); +// }, response('government_agreement')); + +// superiorEnrollmentAggregateApp.get('/education_level_mod_agg', (req, res, next) => { +// req.result = [] + +// for (let i = 1; i <= 13; i++) { +// req.result.push({ +// id: i, name: id2str.educationLevelMod(i) +// }); +// } +// next(); +// }, response('education_level_mod_agg')); + +// superiorEnrollmentAggregateApp.get('/integral_time_agg', (req, res, next) => { +// req.result = [] + +// for (let i = 0; i <= 3; i++) { +// req.result.push({ +// id: i, name: id2str.integralTime(i) +// }); +// } +// next(); +// }, response('integral_time_agg')); + +// superiorEnrollmentAggregateApp.get('/location', (req, res, next) => { +// req.result = [] + +// for (let i = 1; i <= 2; i++) { +// req.result.push({ +// id: i, name: id2str.location(i) +// }); +// } +// next(); +// }, response('location')); + +// superiorEnrollmentAggregateApp.get('/diff_location', (req, res, next) => { +// req.result = [] + +// for (let i = 0; i < 4; i++) { +// req.result.push({ +// id: i, name: id2str.diffLocation(i) +// }); +// } + +// req.result.push({ +// id: 8, name: 'Área onde se localizam povos e comunidades tradicionais' +// }) + +// next(); +// }, response('diff_location')); + +// superiorEnrollmentAggregateApp.get('/modality_integral_time', (req, res, next) => { +// req.result = [] + +// for (let i = 0; i <= 7; i++) { +// req.result.push({ +// id: i, name: id2str.educationLevelBasic(i) +// }); +// } + +// next(); +// }, response('modality_integral_time')); + +// superiorEnrollmentAggregateApp.get('/gender', (req, res, next) => { +// req.result = [] + +// for (let i = 1; i <= 2; i++) { +// req.result.push({ +// id: i, name: id2str.gender(i) +// }); +// } + +// next(); +// }, response('gender')); + +// superiorEnrollmentAggregateApp.get('/age_range', (req, res, next) => { +// req.result = [] + +// for (let i = 1; i <= 7; i++) { +// req.result.push({ +// id: i, name: id2str.ageRangeAggregate(i) +// }); +// } + +// next(); +// }, response('age_range')); + +// superiorEnrollmentAggregateApp.get('/ethnic_group', (req, res, next) => { +// req.result = [] + +// for (let i = 0; i <= 6; i++) { +// req.result.push({ +// id: i, name: id2str.ethnicGroup(i) +// }); +// } + +// next(); +// }, response('ethnic_group')); + +// superiorEnrollmentAggregateApp.get('/period_agg', (req, res, next) => { +// req.result = [] + +// for (let i = 0; i <= 5; i++) { +// req.result.push({ +// id: i, name: id2str.period(i) +// }); +// } + +// next(); +// }, response('period_agg')); + +// superiorEnrollmentAggregateApp.get('/region', (req, res, next) => { +// req.result = [] + +// for (let i = 0; i <= 5; i++) { +// req.result.push({ +// id: i, name: id2str.regionCode(i) +// }); +// } + +// next(); +// }, response('period_agg')); + +// superiorEnrollmentAggregateApp.get('/state', (req, res, next) => { +// req.result = [] +// for (let i = 11; i < 54; i++) { +// if (id2str.stateName(i) !== 'Não declarada') { +// req.result.push({ +// id: i, name: id2str.stateName(i) +// }); +// } +// } + +// next(); +// }, response('state')); + +// superiorEnrollmentAggregateApp.get('/special_education', (req, res, next) => { +// req.result = [] + +// for (let i = 1; i <= 2; i++) { +// req.result.push({ +// id: i, name: id2str.specialEducation(i) +// }); +// } + +// next(); +// }, response('special_education')); + + +// rqf.addField({ +// name: 'filter', +// field: false, +// where: true +// }).addField({ +// name: 'dims', +// field: true, +// where: false +// }).addValue({ +// name: 'adm_dependency', +// table: 'escola', +// tableField: 'dependencia_adm_id', +// resultField: 'adm_dependency_id', +// where: { +// relation: '=', +// type: 'integer', +// field: 'dependencia_adm_id' +// } +// }).addValue({ +// name: 'adm_dependency_detailed', +// table: 'escola', +// tableField: 'dependencia_adm_priv', +// resultField: 'adm_dependency_detailed_id', +// where: { +// relation: '=', +// type: 'integer', +// field: 'dependencia_adm_priv' +// } +// }).addValue({ +// name: 'education_level_mod', +// table: 'escola', +// tableField: 'etapas_mod_ensino_segmento_id', +// resultField: 'education_level_mod_id', +// where: { +// relation: '=', +// type: 'integer', +// field: 'etapas_mod_ensino_segmento_id' +// } +// }).addValue({ +// name:'integral_time', +// table: 'escola', +// tableField: 'tempo_integral', +// resultField: 'integral_time_id', +// where: { +// relation: '=', +// type: 'integer', +// field: 'tempo_integral' +// } +// }).addValue({ +// name: 'education_level_short', +// table: 'escola', +// tableField: 'etapa_resumida', +// resultField: 'education_level_short_id', +// where: { +// relation: '=', +// type: 'integer', +// field: 'etapa_resumida' +// } +// }).addValue({ +// name: 'region', +// table: 'regiao', +// tableField: ['nome', 'id'], +// resultField: ['region_name', 'region_id'], +// where: { +// relation: '=', +// type: 'integer', +// field: 'id' +// }, +// join: { +// primary: 'id', +// foreign: 'regiao_id', +// foreignTable: 'escola' +// } +// }).addValue({ +// name: 'mesoregion', +// table: 'municipio', +// tableField: ['nome_mesorregiao', 'mesorregiao_id'], +// resultField: ['mesoregion_name', 'mesoregion_id'], +// where: { +// relation: '=', +// type: 'integer', +// field: 'mesorregiao_id', +// table: 'municipio' +// }, +// join: { +// primary: 'id', +// foreign: 'municipio_id', +// foreignTable: 'escola' +// } +// }).addValue({ +// name: 'microregion', +// table: 'municipio', +// tableField: ['nome_microrregiao', 'microrregiao_id'], +// resultField: ['microregion_name', 'microregion_id'], +// where: { +// relation: '=', +// type: 'integer', +// field: 'microrregiao_id', +// table: 'municipio' +// }, +// join: { +// primary: 'id', +// foreign: 'municipio_id', +// foreignTable: 'escola' +// } +// }).addValue({ +// name: 'min_year', +// table: 'escola', +// tableField: 'ano_censo', +// resultField: 'year', +// where: { +// relation: '>=', +// type: 'integer', +// field: 'ano_censo', +// }, +// }).addValue({ +// name: 'max_year', +// table: 'escola', +// tableField: 'ano_censo', +// resultField: 'year', +// where: { +// relation: '<=', +// type: 'integer', +// field: 'ano_censo', +// }, +// }).addValueToField({ +// 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: 'escola' +// } +// }, 'dims').addValueToField({ +// name: 'state', +// table: 'estado', +// tableField: 'nome', +// resultField: 'state_name', +// where: { +// relation: '=', +// type: 'integer', +// field: 'id' +// }, +// join: { +// primary: 'id', +// foreign: 'estado_id', +// foreignTable: 'escola' +// } +// }, 'filter').addValueToField({ +// 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: 'escola' +// } +// }, 'dims').addValueToField({ +// name: 'city', +// table: 'municipio', +// tableField: 'nome', +// resultField: 'city_name', +// where: { +// relation: '=', +// type: 'integer', +// field: 'id' +// }, +// join: { +// primary: 'id', +// foreign: 'municipio_id', +// foreignTable: 'escola' +// } +// }, 'filter').addValueToField({ +// name: 'school', +// table: 'escola', +// tableField: ['nome_escola', 'id'], +// resultField: ['school_name', 'school_id'], +// where: { +// relation: '=', +// type: 'integer', +// field: 'id' +// }, +// join: { +// primary: ['id', 'ano_censo'], +// foreign: ['escola_id', 'ano_censo'], +// foreignTable: 'escola' +// } +// }, 'dims').addValueToField({ +// name: 'locale_id', +// table: 'escola', +// tableField: 'localizacao_id', +// resultField: 'locale_id', +// where: { +// relation: '=', +// type: 'integer', +// field: 'localizacao_id' +// } +// }, 'dims').addValueToField({ +// name: 'school_id', +// table: 'escola', +// tableField: 'id', +// resultField: 'school_id', +// where: { +// relation: '=', +// type: 'integer', +// field: 'id' +// }, +// join: { +// primary: ['id', 'ano_censo'], +// foreign: ['escola_id', 'ano_censo'], +// foreignTable: 'escola' +// } +// }, 'dims').addValueToField({ +// name: 'school', +// table: 'escola', +// tableField: 'nome_escola', +// resultField: 'school_name', +// where: { +// relation: '=', +// type: 'integer', +// field: 'id' +// }, +// join: { +// primary: ['id', 'ano_censo'], +// foreign: ['escola_id', 'ano_censo'], +// foreignTable: 'escola' +// } +// }, 'filter').addValue({ +// name: 'location', +// table: 'escola', +// tableField: 'localizacao_id', +// resultField: 'location_id', +// where: { +// relation: '=', +// type: 'integer', +// field: 'localizacao_id' +// } +// }).addValue({ +// name: 'diff_location', +// table: 'escola', +// tableField: 'localizacao_diferenciada_par', +// resultField: 'diff_location_id', +// where: { +// relation: '=', +// type: 'integer', +// field: 'localizacao_diferenciada_par', +// } +// }).addValue({ +// name: 'government_agreement', +// table: 'escola', +// tableField: 'dependencia_convenio_publico', +// resultField: 'government_agreement_id', +// where: { +// relation: '=', +// type: 'integer', +// field: 'dependencia_convenio_publico' +// } +// }); + +superiorEnrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + + req.sql.field('ano_censo', 'Ano') + .field('sum(qtd_matriculas)', 'Número de Matrículas') + .from('curso_superior_agregado') + .where('tp_nivel_acad = 1') + .where('qtd_cursos = 1') + .group('ano_censo') + .order('ano_censo'); + + console.log(req.sql.toString()); + next(); +}, id2str.transform(false), response('superiorEnrollmentAggregate')); + +module.exports = superiorEnrollmentAggregateApp; -- GitLab From ffe11074d9f22333cdfb01f232c0d142d12a4f03 Mon Sep 17 00:00:00 2001 From: tgcl21 <tgcl21@inf.ufpr.br> Date: Tue, 28 Jan 2025 11:27:36 -0300 Subject: [PATCH 02/12] Starter query works --- src/libs/routes_v1/api.js | 8 +- .../routes_v1/superiorEnrollmentAggregate.js | 545 +++++++++--------- 2 files changed, 275 insertions(+), 278 deletions(-) diff --git a/src/libs/routes_v1/api.js b/src/libs/routes_v1/api.js index 8d463a04..6f2de423 100644 --- a/src/libs/routes_v1/api.js +++ b/src/libs/routes_v1/api.js @@ -172,16 +172,12 @@ const adjustedLiquidFrequency = require(`${libs}/routes_v1/adjustedLiquidFrequen const iliteracyRate = require(`${libs}/routes_v1/iliteracyRate`); // comentei para ver se o api.get abaixo ia dar certo (nao deu) -// const superiorEnrollmentAggregate = require(`${libs}/routes_v1/superiorEnrollmentAggregate`); +const superiorEnrollmentAggregate = require(`${libs}/routes_v1/superiorEnrollmentAggregate`); api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API v1 is running' }); }); -api.get('/superior_enrollment_aggregate', (req, res) => { - res.json({ msg: 'oi' }); -}) - // mount API routes_v1 api.use('/test', test); api.use('/user', user); @@ -251,7 +247,7 @@ api.use('/superior_education_conclusion_tax', superiorEducationConclusionTax) api.use('/basic_education_conclusion', basicEducationConclusion); api.use('/adjusted_liquid_frequency', adjustedLiquidFrequency); api.use('/iliteracy_rate', iliteracyRate); -// api.use('/superior_enrollment_aggregate', superiorEnrollmentAggregate); +api.use('/superior_enrollment_aggregate', superiorEnrollmentAggregate); //Publication api.use('/publication', publication); diff --git a/src/libs/routes_v1/superiorEnrollmentAggregate.js b/src/libs/routes_v1/superiorEnrollmentAggregate.js index 800fbfe1..7042e514 100644 --- a/src/libs/routes_v1/superiorEnrollmentAggregate.js +++ b/src/libs/routes_v1/superiorEnrollmentAggregate.js @@ -19,6 +19,7 @@ along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. */ const express = require('express'); + const { result } = require('lodash'); const superiorEnrollmentAggregateApp = express.Router(); @@ -237,277 +238,277 @@ let rqf = new ReqQueryFields(); // }, response('special_education')); -// rqf.addField({ -// name: 'filter', -// field: false, -// where: true -// }).addField({ -// name: 'dims', -// field: true, -// where: false -// }).addValue({ -// name: 'adm_dependency', -// table: 'escola', -// tableField: 'dependencia_adm_id', -// resultField: 'adm_dependency_id', -// where: { -// relation: '=', -// type: 'integer', -// field: 'dependencia_adm_id' -// } -// }).addValue({ -// name: 'adm_dependency_detailed', -// table: 'escola', -// tableField: 'dependencia_adm_priv', -// resultField: 'adm_dependency_detailed_id', -// where: { -// relation: '=', -// type: 'integer', -// field: 'dependencia_adm_priv' -// } -// }).addValue({ -// name: 'education_level_mod', -// table: 'escola', -// tableField: 'etapas_mod_ensino_segmento_id', -// resultField: 'education_level_mod_id', -// where: { -// relation: '=', -// type: 'integer', -// field: 'etapas_mod_ensino_segmento_id' -// } -// }).addValue({ -// name:'integral_time', -// table: 'escola', -// tableField: 'tempo_integral', -// resultField: 'integral_time_id', -// where: { -// relation: '=', -// type: 'integer', -// field: 'tempo_integral' -// } -// }).addValue({ -// name: 'education_level_short', -// table: 'escola', -// tableField: 'etapa_resumida', -// resultField: 'education_level_short_id', -// where: { -// relation: '=', -// type: 'integer', -// field: 'etapa_resumida' -// } -// }).addValue({ -// name: 'region', -// table: 'regiao', -// tableField: ['nome', 'id'], -// resultField: ['region_name', 'region_id'], -// where: { -// relation: '=', -// type: 'integer', -// field: 'id' -// }, -// join: { -// primary: 'id', -// foreign: 'regiao_id', -// foreignTable: 'escola' -// } -// }).addValue({ -// name: 'mesoregion', -// table: 'municipio', -// tableField: ['nome_mesorregiao', 'mesorregiao_id'], -// resultField: ['mesoregion_name', 'mesoregion_id'], -// where: { -// relation: '=', -// type: 'integer', -// field: 'mesorregiao_id', -// table: 'municipio' -// }, -// join: { -// primary: 'id', -// foreign: 'municipio_id', -// foreignTable: 'escola' -// } -// }).addValue({ -// name: 'microregion', -// table: 'municipio', -// tableField: ['nome_microrregiao', 'microrregiao_id'], -// resultField: ['microregion_name', 'microregion_id'], -// where: { -// relation: '=', -// type: 'integer', -// field: 'microrregiao_id', -// table: 'municipio' -// }, -// join: { -// primary: 'id', -// foreign: 'municipio_id', -// foreignTable: 'escola' -// } -// }).addValue({ -// name: 'min_year', -// table: 'escola', -// tableField: 'ano_censo', -// resultField: 'year', -// where: { -// relation: '>=', -// type: 'integer', -// field: 'ano_censo', -// }, -// }).addValue({ -// name: 'max_year', -// table: 'escola', -// tableField: 'ano_censo', -// resultField: 'year', -// where: { -// relation: '<=', -// type: 'integer', -// field: 'ano_censo', -// }, -// }).addValueToField({ -// 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: 'escola' -// } -// }, 'dims').addValueToField({ -// name: 'state', -// table: 'estado', -// tableField: 'nome', -// resultField: 'state_name', -// where: { -// relation: '=', -// type: 'integer', -// field: 'id' -// }, -// join: { -// primary: 'id', -// foreign: 'estado_id', -// foreignTable: 'escola' -// } -// }, 'filter').addValueToField({ -// 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: 'escola' -// } -// }, 'dims').addValueToField({ -// name: 'city', -// table: 'municipio', -// tableField: 'nome', -// resultField: 'city_name', -// where: { -// relation: '=', -// type: 'integer', -// field: 'id' -// }, -// join: { -// primary: 'id', -// foreign: 'municipio_id', -// foreignTable: 'escola' -// } -// }, 'filter').addValueToField({ -// name: 'school', -// table: 'escola', -// tableField: ['nome_escola', 'id'], -// resultField: ['school_name', 'school_id'], -// where: { -// relation: '=', -// type: 'integer', -// field: 'id' -// }, -// join: { -// primary: ['id', 'ano_censo'], -// foreign: ['escola_id', 'ano_censo'], -// foreignTable: 'escola' -// } -// }, 'dims').addValueToField({ -// name: 'locale_id', -// table: 'escola', -// tableField: 'localizacao_id', -// resultField: 'locale_id', -// where: { -// relation: '=', -// type: 'integer', -// field: 'localizacao_id' -// } -// }, 'dims').addValueToField({ -// name: 'school_id', -// table: 'escola', -// tableField: 'id', -// resultField: 'school_id', -// where: { -// relation: '=', -// type: 'integer', -// field: 'id' -// }, -// join: { -// primary: ['id', 'ano_censo'], -// foreign: ['escola_id', 'ano_censo'], -// foreignTable: 'escola' -// } -// }, 'dims').addValueToField({ -// name: 'school', -// table: 'escola', -// tableField: 'nome_escola', -// resultField: 'school_name', -// where: { -// relation: '=', -// type: 'integer', -// field: 'id' -// }, -// join: { -// primary: ['id', 'ano_censo'], -// foreign: ['escola_id', 'ano_censo'], -// foreignTable: 'escola' -// } -// }, 'filter').addValue({ -// name: 'location', -// table: 'escola', -// tableField: 'localizacao_id', -// resultField: 'location_id', -// where: { -// relation: '=', -// type: 'integer', -// field: 'localizacao_id' -// } -// }).addValue({ -// name: 'diff_location', -// table: 'escola', -// tableField: 'localizacao_diferenciada_par', -// resultField: 'diff_location_id', -// where: { -// relation: '=', -// type: 'integer', -// field: 'localizacao_diferenciada_par', -// } -// }).addValue({ -// name: 'government_agreement', -// table: 'escola', -// tableField: 'dependencia_convenio_publico', -// resultField: 'government_agreement_id', -// where: { -// relation: '=', -// type: 'integer', -// field: 'dependencia_convenio_publico' -// } -// }); +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'adm_dependency', + table: 'escola', + tableField: 'dependencia_adm_id', + resultField: 'adm_dependency_id', + where: { + relation: '=', + type: 'integer', + field: 'dependencia_adm_id' + } +}).addValue({ + name: 'adm_dependency_detailed', + table: 'escola', + tableField: 'dependencia_adm_priv', + resultField: 'adm_dependency_detailed_id', + where: { + relation: '=', + type: 'integer', + field: 'dependencia_adm_priv' + } +}).addValue({ + name: 'education_level_mod', + table: 'escola', + tableField: 'etapas_mod_ensino_segmento_id', + resultField: 'education_level_mod_id', + where: { + relation: '=', + type: 'integer', + field: 'etapas_mod_ensino_segmento_id' + } +}).addValue({ + name:'integral_time', + table: 'escola', + tableField: 'tempo_integral', + resultField: 'integral_time_id', + where: { + relation: '=', + type: 'integer', + field: 'tempo_integral' + } + }).addValue({ + name: 'education_level_short', + table: 'escola', + tableField: 'etapa_resumida', + resultField: 'education_level_short_id', + where: { + relation: '=', + type: 'integer', + field: 'etapa_resumida' + } +}).addValue({ + name: 'region', + table: 'regiao', + tableField: ['nome', 'id'], + resultField: ['region_name', 'region_id'], + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'regiao_id', + foreignTable: 'escola' + } +}).addValue({ + name: 'mesoregion', + table: 'municipio', + tableField: ['nome_mesorregiao', 'mesorregiao_id'], + resultField: ['mesoregion_name', 'mesoregion_id'], + where: { + relation: '=', + type: 'integer', + field: 'mesorregiao_id', + table: 'municipio' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'escola' + } +}).addValue({ + name: 'microregion', + table: 'municipio', + tableField: ['nome_microrregiao', 'microrregiao_id'], + resultField: ['microregion_name', 'microregion_id'], + where: { + relation: '=', + type: 'integer', + field: 'microrregiao_id', + table: 'municipio' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'escola' + } +}).addValue({ + name: 'min_year', + table: 'escola', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + field: 'ano_censo', + }, +}).addValue({ + name: 'max_year', + table: 'escola', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + field: 'ano_censo', + }, +}).addValueToField({ + 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: 'escola' + } +}, 'dims').addValueToField({ + name: 'state', + table: 'estado', + tableField: 'nome', + resultField: 'state_name', + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'estado_id', + foreignTable: 'escola' + } +}, 'filter').addValueToField({ + 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: 'escola' + } +}, 'dims').addValueToField({ + name: 'city', + table: 'municipio', + tableField: 'nome', + resultField: 'city_name', + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'escola' + } +}, 'filter').addValueToField({ + name: 'school', + table: 'escola', + tableField: ['nome_escola', 'id'], + resultField: ['school_name', 'school_id'], + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: ['id', 'ano_censo'], + foreign: ['escola_id', 'ano_censo'], + foreignTable: 'escola' + } +}, 'dims').addValueToField({ + name: 'locale_id', + table: 'escola', + tableField: 'localizacao_id', + resultField: 'locale_id', + where: { + relation: '=', + type: 'integer', + field: 'localizacao_id' + } +}, 'dims').addValueToField({ + name: 'school_id', + table: 'escola', + tableField: 'id', + resultField: 'school_id', + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: ['id', 'ano_censo'], + foreign: ['escola_id', 'ano_censo'], + foreignTable: 'escola' + } +}, 'dims').addValueToField({ + name: 'school', + table: 'escola', + tableField: 'nome_escola', + resultField: 'school_name', + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: ['id', 'ano_censo'], + foreign: ['escola_id', 'ano_censo'], + foreignTable: 'escola' + } +}, 'filter').addValue({ + name: 'location', + table: 'escola', + tableField: 'localizacao_id', + resultField: 'location_id', + where: { + relation: '=', + type: 'integer', + field: 'localizacao_id' + } +}).addValue({ + name: 'diff_location', + table: 'escola', + tableField: 'localizacao_diferenciada_par', + resultField: 'diff_location_id', + where: { + relation: '=', + type: 'integer', + field: 'localizacao_diferenciada_par', + } +}).addValue({ + name: 'government_agreement', + table: 'escola', + tableField: 'dependencia_convenio_publico', + resultField: 'government_agreement_id', + where: { + relation: '=', + type: 'integer', + field: 'dependencia_convenio_publico' + } +}); superiorEnrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { @@ -521,6 +522,6 @@ superiorEnrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, nex console.log(req.sql.toString()); next(); -}, id2str.transform(false), response('superiorEnrollmentAggregate')); +}, query, id2str.transform(false), response('superior_enrollment_aggregate')); module.exports = superiorEnrollmentAggregateApp; -- GitLab From 15400c609bd24725a511d7e69db3ceb539c46e2e Mon Sep 17 00:00:00 2001 From: edsaibert <es23@inf.ufpr.br> Date: Wed, 5 Feb 2025 11:51:30 -0300 Subject: [PATCH 03/12] age_range_cescu --- src/libs/convert/ageRangeCescu.js | 43 +++ src/libs/middlewares/aggregateData.js | 7 +- src/libs/middlewares/id2str.js | 3 + src/libs/routes_v1/api.js | 1 - .../routes_v1/superiorEnrollmentAggregate.js | 322 +++++------------- 5 files changed, 142 insertions(+), 234 deletions(-) create mode 100644 src/libs/convert/ageRangeCescu.js diff --git a/src/libs/convert/ageRangeCescu.js b/src/libs/convert/ageRangeCescu.js new file mode 100644 index 00000000..60393c14 --- /dev/null +++ b/src/libs/convert/ageRangeCescu.js @@ -0,0 +1,43 @@ +/* +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 ageRange(id) { + switch (id) { + case 1: + return 'Até 17 anos de idade'; + case 2: + return 'De 18 a 24 anos de idade'; + case 3: + return 'De 25 a 29 anos de idade'; + case 4: + return 'De 30 a 34 anos de idade'; + case 5: + return 'De 35 a 39 anos de idade'; + case 6: + return 'De 40 a 49 anos de idade'; + case 7: + return 'De 50 a 59 anos de idade'; + case 8: + return 'De 60 ou mais anos de idade'; + default: + return 'Não declarada'; + } +}; + diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js index eed373dd..98234532 100644 --- a/src/libs/middlewares/aggregateData.js +++ b/src/libs/middlewares/aggregateData.js @@ -35,7 +35,9 @@ const convert = { contract_type_entity: 'contractType', total_doc: "totalDoc", education_degree_entity: "educationDegreeEntity", - government_agreement: "governmentAgreement" + government_agreement: "governmentAgreement", + school_type: "schoolType", + age_range_cescu: "ageRangeCescu" } function aggregateData(req, res, next) { @@ -62,7 +64,8 @@ function aggregateData(req, res, next) { 'age_range_entity', 'post_graduation_entity', 'contract_type_entity', - 'education_degree_entity' + 'education_degree_entity', + 'age_range_cescu' ] let id; const fields = req.query.dims.split(','); diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index d6c763c9..d4b3896b 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -43,6 +43,7 @@ const contractType = require(`${libs}/convert/contractType`); const ethnicGroupPnad = require(`${libs}/convert/ethnicGroupPnad`); const ageRange = require(`${libs}/convert/ageRange`); const ageRangeAll = require(`${libs}/convert/ageRangeAll`); +const ageRangeCescu = require(`${libs}/convert/ageRangeCescu`); const ageStudentCode = require(`${libs}/convert/ageStudentCode`); const fullAgeRange = require(`${libs}/convert/fullAgeRange`); const genderPnad = require(`${libs}/convert/genderPnad`); @@ -164,6 +165,7 @@ const ids = { age_range_all_id: ageRangeAll, age_range_aggregate_id: ageRangeAggregate, full_age_range_id: fullAgeRange, + age_range_cescu_id: ageRangeCescu, gender_pnad_id: genderPnad, fifth_household_income_id: fifthHouseholdIncome, extremes_household_income_id: extremesHouseholdIncome, @@ -312,6 +314,7 @@ module.exports = { ageRange, ageRangeAggregate, ageRangeAll, + ageRangeCescu, ageStudentCode, fullAgeRange, genderPnad, diff --git a/src/libs/routes_v1/api.js b/src/libs/routes_v1/api.js index 6f2de423..3ed477ef 100644 --- a/src/libs/routes_v1/api.js +++ b/src/libs/routes_v1/api.js @@ -171,7 +171,6 @@ const adjustedLiquidFrequency = require(`${libs}/routes_v1/adjustedLiquidFrequen const iliteracyRate = require(`${libs}/routes_v1/iliteracyRate`); -// comentei para ver se o api.get abaixo ia dar certo (nao deu) const superiorEnrollmentAggregate = require(`${libs}/routes_v1/superiorEnrollmentAggregate`); api.get('/', (req, res) => { diff --git a/src/libs/routes_v1/superiorEnrollmentAggregate.js b/src/libs/routes_v1/superiorEnrollmentAggregate.js index 7042e514..ed02530e 100644 --- a/src/libs/routes_v1/superiorEnrollmentAggregate.js +++ b/src/libs/routes_v1/superiorEnrollmentAggregate.js @@ -246,282 +246,142 @@ rqf.addField({ name: 'dims', field: true, where: false -}).addValue({ - name: 'adm_dependency', - table: 'escola', - tableField: 'dependencia_adm_id', - resultField: 'adm_dependency_id', - where: { - relation: '=', - type: 'integer', - field: 'dependencia_adm_id' - } -}).addValue({ - name: 'adm_dependency_detailed', - table: 'escola', - tableField: 'dependencia_adm_priv', - resultField: 'adm_dependency_detailed_id', - where: { - relation: '=', - type: 'integer', - field: 'dependencia_adm_priv' - } -}).addValue({ - name: 'education_level_mod', - table: 'escola', - tableField: 'etapas_mod_ensino_segmento_id', - resultField: 'education_level_mod_id', - where: { - relation: '=', - type: 'integer', - field: 'etapas_mod_ensino_segmento_id' - } -}).addValue({ - name:'integral_time', - table: 'escola', - tableField: 'tempo_integral', - resultField: 'integral_time_id', - where: { - relation: '=', - type: 'integer', - field: 'tempo_integral' - } - }).addValue({ - name: 'education_level_short', - table: 'escola', - tableField: 'etapa_resumida', - resultField: 'education_level_short_id', - where: { - relation: '=', - type: 'integer', - field: 'etapa_resumida' - } -}).addValue({ - name: 'region', - table: 'regiao', - tableField: ['nome', 'id'], - resultField: ['region_name', 'region_id'], - where: { - relation: '=', - type: 'integer', - field: 'id' - }, - join: { - primary: 'id', - foreign: 'regiao_id', - foreignTable: 'escola' - } -}).addValue({ - name: 'mesoregion', - table: 'municipio', - tableField: ['nome_mesorregiao', 'mesorregiao_id'], - resultField: ['mesoregion_name', 'mesoregion_id'], - where: { - relation: '=', - type: 'integer', - field: 'mesorregiao_id', - table: 'municipio' - }, - join: { - primary: 'id', - foreign: 'municipio_id', - foreignTable: 'escola' - } -}).addValue({ - name: 'microregion', - table: 'municipio', - tableField: ['nome_microrregiao', 'microrregiao_id'], - resultField: ['microregion_name', 'microregion_id'], - where: { - relation: '=', - type: 'integer', - field: 'microrregiao_id', - table: 'municipio' - }, - join: { - primary: 'id', - foreign: 'municipio_id', - foreignTable: 'escola' - } }).addValue({ name: 'min_year', - table: 'escola', + table: 'curso_superior_agregado', tableField: 'ano_censo', resultField: 'year', where: { relation: '>=', type: 'integer', - field: 'ano_censo', - }, + field: 'ano_censo' + } }).addValue({ name: 'max_year', - table: 'escola', - tableField: 'ano_censo', + table: 'curso_superior_agregado', + tableField: '', resultField: 'year', where: { relation: '<=', type: 'integer', - field: 'ano_censo', - }, -}).addValueToField({ - 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: 'escola' - } -}, 'dims').addValueToField({ - name: 'state', - table: 'estado', - tableField: 'nome', - resultField: 'state_name', - where: { - relation: '=', - type: 'integer', - field: 'id' - }, - join: { - primary: 'id', - foreign: 'estado_id', - foreignTable: 'escola' - } -}, 'filter').addValueToField({ - 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: 'escola' - } -}, 'dims').addValueToField({ - name: 'city', - table: 'municipio', - tableField: 'nome', - resultField: 'city_name', - where: { - relation: '=', - type: 'integer', - field: 'id' - }, - join: { - primary: 'id', - foreign: 'municipio_id', - foreignTable: 'escola' + field: 'ano_censo' } -}, 'filter').addValueToField({ - name: 'school', - table: 'escola', - tableField: ['nome_escola', 'id'], - resultField: ['school_name', 'school_id'], - where: { - relation: '=', - type: 'integer', - field: 'id' - }, - join: { - primary: ['id', 'ano_censo'], - foreign: ['escola_id', 'ano_censo'], - foreignTable: 'escola' - } -}, 'dims').addValueToField({ - name: 'locale_id', - table: 'escola', - tableField: 'localizacao_id', - resultField: 'locale_id', +}).addValue({ + name: 'tp_categ_adm', + table: 'curso_superior_agregado', + tableField: 'tp_categ_adm', + resultField: 'tp_categ_adm', where: { relation: '=', type: 'integer', - field: 'localizacao_id' + field: 'tp_categ_adm' } -}, 'dims').addValueToField({ - name: 'school_id', - table: 'escola', - tableField: 'id', - resultField: 'school_id', +}).addValue({ + name: 'cine_global', + table: 'curso_superior_agregado', + tableField: ['nome_cine_area_geral', 'cod_cine_area_geral'], + resultField: ['name_cine_global', 'cod_cine_global'], where: { relation: '=', type: 'integer', - field: 'id' + field: 'cod_cine_area_geral', }, - join: { - primary: ['id', 'ano_censo'], - foreign: ['escola_id', 'ano_censo'], - foreignTable: 'escola' - } -}, 'dims').addValueToField({ - name: 'school', - table: 'escola', - tableField: 'nome_escola', - resultField: 'school_name', +}).addValue({ + name: 'cine_sp', + table: 'curso_superior_agregado', + tableField: ['nome_cine_area_esp', 'cod_cine_area_esp'], + resultField: ['name_cine_sp', 'cod_cine_sp'], where: { relation: '=', type: 'integer', - field: 'id' - }, - join: { - primary: ['id', 'ano_censo'], - foreign: ['escola_id', 'ano_censo'], - foreignTable: 'escola' + field: 'cod_cine_area_esp' } -}, 'filter').addValue({ - name: 'location', - table: 'escola', - tableField: 'localizacao_id', - resultField: 'location_id', +}).addValue({ + name: 'cine_deatiled', + table: 'curso_superior_agregado', + tableField: ['nome_cine_area_detalhada', 'cod_cine_area_detalhada'], + resultField: ['name_cine_detailed', 'cod_cine_detailed'], where: { relation: '=', type: 'integer', - field: 'localizacao_id' + field: 'cod_cine_area_detalhada' } }).addValue({ - name: 'diff_location', - table: 'escola', - tableField: 'localizacao_diferenciada_par', - resultField: 'diff_location_id', + name: 'graduates', + table: 'curso_superior_agregado', + tableField: 'qtd_concluintes', + resultField: 'graduates', where: { relation: '=', type: 'integer', - field: 'localizacao_diferenciada_par', + field: 'qtd_concluintes' } }).addValue({ - name: 'government_agreement', - table: 'escola', - tableField: 'dependencia_convenio_publico', - resultField: 'government_agreement_id', + name: 'disabled_students', + table: 'curso_superior_agregado', + tableField: 'qtd_aluno_deficiente', + resultField: 'disabled_students', where: { relation: '=', type: 'integer', - field: 'dependencia_convenio_publico' + field: 'qtd_aluno_deficiente' } +}).addValue({ + }); superiorEnrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + if (req.query.dims && req.query.dims.includes("ethnic_group")){ + req.sql.field('ano_censo', 'year') + .field('sum(qtd_mat_branca)', 'total_branca') + .field('sum(qtd_mat_preta)', 'total_preta') + .field('sum(qtd_mat_parda)', 'total_parda') + .field('sum(qtd_mat_amarela)', 'total_amarela') + .field('sum(qtd_mat_indigena)', 'total_indigena') + .field('sum(qtd_mat_cor_nao_declarada)', 'total_nd') + .from('curso_superior_agregado') + .where('tp_nivel_acad = 1') + .group('ano_censo') + .order('ano_censo'); + } + else if (req.query.dims && req.query.dims.includes("school_type")){ + req.sql.field('ano_censo', 'year') + .field('sum(qtd_mat_proces_publica)', 'total_publica') + .field('sum(qtd_mat_proces_privada)', 'total_privada') + .field('sum(qtd_mat_proces_nao_informada)', 'total_nao_informada') + .from('curso_superior_agregado') + .where('tp_nivel_acad = 1') + .group('ano_censo') + .order('ano_censo'); + } + else if (req.query.dims && req.query.dims.includes("age_range_cescu")){ + req.sql.field('ano_censo', 'year') + .field('sum(qtd_mat_0_17)', 'total_0_17') + .field('sum(qtd_mat_18_24)', 'total_18_24') + .field('sum(qtd_mat_25_29)', 'total_25_29') + .field('sum(qtd_mat_30_34)', 'total_30_34') + .field('sum(qtd_mat_35_39)', 'total_35_39') + .field('sum(qtd_mat_40_49)', 'total_40_49') + .field('sum(qtd_mat_50_59)', 'total_50_59') + .field('sum(qtd_mat_60_mais)', 'total_60_mais') + .from('curso_superior_agregado') + .where('tp_nivel_acad = 1') + .group('ano_censo') + .order('ano_censo'); + } + else { + req.sql.field('ano_censo', 'Ano') + .field('SUM(qtd_matriculas)', 'Número de Matrículas') + .from('curso_superior_agregado') + .where('tp_nivel_acad = 1') + .group('ano_censo') + .order('ano_censo'); + } - req.sql.field('ano_censo', 'Ano') - .field('sum(qtd_matriculas)', 'Número de Matrículas') - .from('curso_superior_agregado') - .where('tp_nivel_acad = 1') - .where('qtd_cursos = 1') - .group('ano_censo') - .order('ano_censo'); - console.log(req.sql.toString()); + console.log(req.query.dims); + next(); -}, query, id2str.transform(false), response('superior_enrollment_aggregate')); +}, query, aggregateData, id2str.transform(false), response('superior_enrollment_aggregate')); module.exports = superiorEnrollmentAggregateApp; -- GitLab From a443dd6acceb8ac3d55218302e291b7214a5f68f Mon Sep 17 00:00:00 2001 From: edsaibert <es23@inf.ufpr.br> Date: Mon, 10 Feb 2025 11:50:55 -0300 Subject: [PATCH 04/12] problemas com uf reg e municipio --- src/libs/convert/modalityShiftSuperior.js | 30 +++ src/libs/middlewares/aggregateData.js | 3 +- src/libs/middlewares/id2str.js | 7 +- .../routes_v1/superiorEnrollmentAggregate.js | 172 +++++++++++++++--- 4 files changed, 182 insertions(+), 30 deletions(-) create mode 100644 src/libs/convert/modalityShiftSuperior.js diff --git a/src/libs/convert/modalityShiftSuperior.js b/src/libs/convert/modalityShiftSuperior.js new file mode 100644 index 00000000..64595063 --- /dev/null +++ b/src/libs/convert/modalityShiftSuperior.js @@ -0,0 +1,30 @@ +/* +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 shift(id) { + switch(id) { + case 1: + return 'Diurno'; + case 2: + return 'Noturno'; + default: + return 'Não especificado'; + } +} \ No newline at end of file diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js index 98234532..96272ddc 100644 --- a/src/libs/middlewares/aggregateData.js +++ b/src/libs/middlewares/aggregateData.js @@ -37,7 +37,8 @@ const convert = { education_degree_entity: "educationDegreeEntity", government_agreement: "governmentAgreement", school_type: "schoolType", - age_range_cescu: "ageRangeCescu" + age_range_cescu: "ageRangeCescu", + modality_shift_superior: "modalityShiftSuperior" } function aggregateData(req, res, next) { diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index d4b3896b..c5edb2ae 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -127,6 +127,7 @@ 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 modalityShiftSuperior = require(`${libs}/convert/modalityShiftSuperior`); const ids = { gender_id: gender, @@ -246,7 +247,8 @@ const ids = { post_graduation_entity: postGraduationEntity, special_education_entity: specialEducationEntity, total_doc: totalDoc, - education_degree_entity: educationDegreeEntity + education_degree_entity: educationDegreeEntity, + modality_shift_superior_id: modalityShiftSuperior, }; function transform(removeId=false) { @@ -389,5 +391,6 @@ module.exports = { postGraduationEntity, specialEducationEntity, totalDoc, - educationDegreeEntity + educationDegreeEntity, + modalityShiftSuperior, }; diff --git a/src/libs/routes_v1/superiorEnrollmentAggregate.js b/src/libs/routes_v1/superiorEnrollmentAggregate.js index ed02530e..e2c47728 100644 --- a/src/libs/routes_v1/superiorEnrollmentAggregate.js +++ b/src/libs/routes_v1/superiorEnrollmentAggregate.js @@ -30,6 +30,8 @@ const log = require(`${libs}/log`)(module); const squel = require('squel'); +const multiQuery = require(`${libs}/middlewares/multiQuery`); + const query = require(`${libs}/middlewares/query`).query; const response = require(`${libs}/middlewares/response`); @@ -327,61 +329,177 @@ rqf.addField({ field: 'qtd_aluno_deficiente' } }).addValue({ - + name: 'academic_level', + table: 'curso_superior_agregado', + tableField: 'tp_grau_acad', + resultField: 'academic_level', + where: { + relation: '=', + type: 'integer', + field: 'tp_grau_acad' + } +}).addValue({ + name: 'ies_name', + table: 'ies_ens_superior', + tableField: 'nome_ies', + resultField: 'ies_name', + where: { + relation: '=', + type: 'integer', + field: 'cod_ies' + }, + join: { + primary: ['cod_ies', 'ano_censo'], + foreign: ['cod_ies', 'ano_censo'], + foreignTable: 'curso_superior_agregado' + } +}).addValue({ + name: 'modality', + table: 'curso_superior_agregado', + tableField: 'tp_modal_ens', + resultField: 'modality', + where: { + relation: '=', + type: 'integer', + field: 'tp_modal_ens' + } +}).addValue({ + name: 'academic_organization', + table: 'curso_superior_agregado', + tableField: 'tp_org_acad', + resultField: 'academic_organization', + where: { + relation: '=', + type: 'integer', + field: 'tp_org_acad' + } }); +function matchQueries(queryPartial, queryTotal) { + let match = []; + queryTotal.forEach((result) => { + let newObj = {}; + let keys = Object.keys(result); + keys.forEach((key) => { + newObj[key] = result[key]; + }); + let index = keys.indexOf('cod'); + if(index > -1) keys.splice(index, 1); + let objMatch = null; + + for(let i = 0; i < queryPartial.length; ++i) { + let partial = queryPartial[i]; + let foundMatch = true; + for(let j = 0; j < keys.length; ++j) { + let key = keys[j]; + if(partial[key] !== result[key]) { + foundMatch = false; + break; + } + } + if(foundMatch) { + objMatch = partial; + break; + } + } + + if(objMatch) { + newObj.denominator = result.cod; + newObj.partial = objMatch.cod; + // newObj.total = (objMatch.total / result.total) * 100; + match.push(newObj); + } + }); + + return match; +} + superiorEnrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + req.querySet = []; + + let basic = req.sql.clone(); + let curso = req.sql.clone(); + let ies = req.sql.clone(); + + basic.field('curso_superior_agregado.ano_censo', 'year'); + if (req.query.dims && req.query.dims.includes("ethnic_group")){ - req.sql.field('ano_censo', 'year') - .field('sum(qtd_mat_branca)', 'total_branca') + basic.field.field('sum(qtd_mat_branca)', 'total_branca') .field('sum(qtd_mat_preta)', 'total_preta') .field('sum(qtd_mat_parda)', 'total_parda') .field('sum(qtd_mat_amarela)', 'total_amarela') .field('sum(qtd_mat_indigena)', 'total_indigena') - .field('sum(qtd_mat_cor_nao_declarada)', 'total_nd') - .from('curso_superior_agregado') - .where('tp_nivel_acad = 1') - .group('ano_censo') - .order('ano_censo'); + .field('sum(qtd_mat_cor_nao_declarada)', 'total_nd'); } else if (req.query.dims && req.query.dims.includes("school_type")){ - req.sql.field('ano_censo', 'year') - .field('sum(qtd_mat_proces_publica)', 'total_publica') + basic.field('sum(qtd_mat_proces_publica)', 'total_publica') .field('sum(qtd_mat_proces_privada)', 'total_privada') - .field('sum(qtd_mat_proces_nao_informada)', 'total_nao_informada') - .from('curso_superior_agregado') - .where('tp_nivel_acad = 1') - .group('ano_censo') - .order('ano_censo'); + .field('sum(qtd_mat_proces_nao_informada)', 'total_nao_informada'); } else if (req.query.dims && req.query.dims.includes("age_range_cescu")){ - req.sql.field('ano_censo', 'year') - .field('sum(qtd_mat_0_17)', 'total_0_17') + basic.field('sum(qtd_mat_0_17)', 'total_0_17') .field('sum(qtd_mat_18_24)', 'total_18_24') .field('sum(qtd_mat_25_29)', 'total_25_29') .field('sum(qtd_mat_30_34)', 'total_30_34') .field('sum(qtd_mat_35_39)', 'total_35_39') .field('sum(qtd_mat_40_49)', 'total_40_49') .field('sum(qtd_mat_50_59)', 'total_50_59') - .field('sum(qtd_mat_60_mais)', 'total_60_mais') - .from('curso_superior_agregado') + .field('sum(qtd_mat_60_mais)', 'total_60_mais'); + } + else if (req.query.dims && req.query.dims.includes("gender")){ + basic.field('sum(qtd_mat_fem)', 'total_fem') + .field('sum(qtd_mat_masc)', 'total_masc'); + } + else if (req.query.dims && req.query.dims.includes("modality_shift_superior")){ + basic.field('sum(qtd_mat_diurno)', 'total_diurno') + .field('sum(qtd_mat_noturno)', 'total_noturno'); + } + else if (req.query.dims && req.query.dims.includes("region")){ + curso.field('qtd_matriculas', 'enrollment') + curso.field('cod_reg', 'cod') + curso.field('nome_reg', 'cod_name') .where('tp_nivel_acad = 1') + .from('curso_superior_agregado') .group('ano_censo') .order('ano_censo'); - } - else { - req.sql.field('ano_censo', 'Ano') - .field('SUM(qtd_matriculas)', 'Número de Matrículas') - .from('curso_superior_agregado') + + ies.field('nome_regiao_ies', 'cod_name') .where('tp_nivel_acad = 1') + .from('ies_ens_superior') + .where('ano_censo > 2019') .group('ano_censo') .order('ano_censo'); } + else { + basic.field('SUM(qtd_matriculas)', 'enrollment'); + } + + basic.from('curso_superior_agregado') + .from('ies_ens_superior') + // .join('ies_ens_superior', null, 'ies_ens_superior.ano_censo = curso_superior_agregado.ano_censo') + .where('tp_nivel_acad = 1') + .group('curso_superior_agregado.ano_censo') + .order('curso_superior_agregado.ano_censo'); - console.log(req.sql.toString()); - console.log(req.query.dims); + // console.log(req.sql.toString()); + // // console.log(req.query.dims); + // console.log(req.sql.result); + + req.querySet.push(basic); + req.querySet.push(curso); + req.querySet.push(ies); next(); -}, query, aggregateData, id2str.transform(false), response('superior_enrollment_aggregate')); +}, multiQuery, query, aggregateData, id2str.transform(false), response('superior_enrollment_aggregate'), (req, res, next) => { + + if (req.result[1] || req.result[2]){ + let newObj = matchQueries(req.result[1], req.result[2]); + req.result = newObj; + } + else { + req.result = req.result[0]; + } + next(); +}); module.exports = superiorEnrollmentAggregateApp; -- GitLab From cae2bd906916e27239b3af3d7dd1ffb538c7a5d2 Mon Sep 17 00:00:00 2001 From: edsaibert <es23@inf.ufpr.br> Date: Mon, 24 Feb 2025 10:33:31 -0300 Subject: [PATCH 05/12] dimensions qtd_graduates --- .../routes_v1/superiorEnrollmentAggregate.js | 383 +++++------------- 1 file changed, 112 insertions(+), 271 deletions(-) diff --git a/src/libs/routes_v1/superiorEnrollmentAggregate.js b/src/libs/routes_v1/superiorEnrollmentAggregate.js index e2c47728..e37d4cb5 100644 --- a/src/libs/routes_v1/superiorEnrollmentAggregate.js +++ b/src/libs/routes_v1/superiorEnrollmentAggregate.js @@ -52,193 +52,80 @@ superiorEnrollmentAggregateApp.use(cache('15 day')); let rqf = new ReqQueryFields(); -// superiorEnrollmentAggregateApp.get('/years', (req, res, next) => { -// req.sql.from('escola') -// .field('DISTINCT escola.ano_censo', 'year') -// .where('escola.ano_censo >= 2021') -// next(); -// }, query, response('years')); - -// superiorEnrollmentAggregateApp.get('/adm_dependency', (req, res, next) => { -// req.result = [] - -// for (let i = 1; i <= 5; i++) { -// req.result.push({ -// id: i, name: id2str.admDependency(i) -// }); -// } -// next(); -// }, response('adm_dependency')); - -// superiorEnrollmentAggregateApp.get('/adm_dependency_detailed', (req, res, next) => { -// req.result = [] - -// for (let i = 1; i <= 8; i++) { -// req.result.push({ -// id: i, name: id2str.admDependencyPriv(i) -// }); -// } -// next(); -// }, response('adm_dependency_detailed')); - -// superiorEnrollmentAggregateApp.get('/government_agreement', (req, res, next) => { -// req.result = [] - -// for(let i = 1; i <= 6; ++i) { -// req.result.push({ -// id: i, -// name: id2str.governmentAgreement(i) -// }); -// }; -// next(); -// }, response('government_agreement')); - -// superiorEnrollmentAggregateApp.get('/education_level_mod_agg', (req, res, next) => { -// req.result = [] - -// for (let i = 1; i <= 13; i++) { -// req.result.push({ -// id: i, name: id2str.educationLevelMod(i) -// }); -// } -// next(); -// }, response('education_level_mod_agg')); - -// superiorEnrollmentAggregateApp.get('/integral_time_agg', (req, res, next) => { -// req.result = [] - -// for (let i = 0; i <= 3; i++) { -// req.result.push({ -// id: i, name: id2str.integralTime(i) -// }); -// } -// next(); -// }, response('integral_time_agg')); - -// superiorEnrollmentAggregateApp.get('/location', (req, res, next) => { -// req.result = [] - -// for (let i = 1; i <= 2; i++) { -// req.result.push({ -// id: i, name: id2str.location(i) -// }); -// } -// next(); -// }, response('location')); - -// superiorEnrollmentAggregateApp.get('/diff_location', (req, res, next) => { -// req.result = [] - -// for (let i = 0; i < 4; i++) { -// req.result.push({ -// id: i, name: id2str.diffLocation(i) -// }); -// } - -// req.result.push({ -// id: 8, name: 'Área onde se localizam povos e comunidades tradicionais' -// }) - -// next(); -// }, response('diff_location')); - -// superiorEnrollmentAggregateApp.get('/modality_integral_time', (req, res, next) => { -// req.result = [] - -// for (let i = 0; i <= 7; i++) { -// req.result.push({ -// id: i, name: id2str.educationLevelBasic(i) -// }); -// } - -// next(); -// }, response('modality_integral_time')); - -// superiorEnrollmentAggregateApp.get('/gender', (req, res, next) => { -// req.result = [] - -// for (let i = 1; i <= 2; i++) { -// req.result.push({ -// id: i, name: id2str.gender(i) -// }); -// } - -// next(); -// }, response('gender')); - -// superiorEnrollmentAggregateApp.get('/age_range', (req, res, next) => { -// req.result = [] - -// for (let i = 1; i <= 7; i++) { -// req.result.push({ -// id: i, name: id2str.ageRangeAggregate(i) -// }); -// } - -// next(); -// }, response('age_range')); - -// superiorEnrollmentAggregateApp.get('/ethnic_group', (req, res, next) => { -// req.result = [] - -// for (let i = 0; i <= 6; i++) { -// req.result.push({ -// id: i, name: id2str.ethnicGroup(i) -// }); -// } - -// next(); -// }, response('ethnic_group')); - -// superiorEnrollmentAggregateApp.get('/period_agg', (req, res, next) => { -// req.result = [] - -// for (let i = 0; i <= 5; i++) { -// req.result.push({ -// id: i, name: id2str.period(i) -// }); -// } - -// next(); -// }, response('period_agg')); - -// superiorEnrollmentAggregateApp.get('/region', (req, res, next) => { -// req.result = [] - -// for (let i = 0; i <= 5; i++) { -// req.result.push({ -// id: i, name: id2str.regionCode(i) -// }); -// } - -// next(); -// }, response('period_agg')); - -// superiorEnrollmentAggregateApp.get('/state', (req, res, next) => { -// req.result = [] -// for (let i = 11; i < 54; i++) { -// if (id2str.stateName(i) !== 'Não declarada') { -// req.result.push({ -// id: i, name: id2str.stateName(i) -// }); -// } -// } - -// next(); -// }, response('state')); - -// superiorEnrollmentAggregateApp.get('/special_education', (req, res, next) => { -// req.result = [] +superiorEnrollmentAggregateApp.get('/years', (req, res, next) => { + req.sql.from('curso_superior_agregado') + .field('DISTINCT curso_superior_agregado.ano_censo', 'year') + .where('curso_superior_agregado.ano_censo >= 2020') + next(); +}, query, response('years')); -// for (let i = 1; i <= 2; i++) { -// req.result.push({ -// id: i, name: id2str.specialEducation(i) -// }); -// } +superiorEnrollmentAggregateApp.get('/qtd_graduates', (req, res, next) => { + req.sql.from('curso_superior_agregado') + .field('DISTINCT SUM(curso_superior_agregado.qtd_concluintes)', 'qtd_graduates') + .where('curso_superior_agregado.ano_censo >= 2020') + next(); + +}) -// next(); -// }, response('special_education')); +superiorEnrollmentAggregateApp.get('/tp_categ_adm', (req, res, next) => { + req.result = [] + for (let i = 1; i <= 5; i++) { + req.result.push({ + id: i, name: id2str.admDependency(i) + }); + } + next(); +}, response('adm_dependency')); + +superiorEnrollmentAggregateApp.get('/cine_global', (req, res, next) => { + req.result = []; + for(let i = 0; i <= 10; ++i) { + req.result.push({ + id: i, + name: id2str.cineGeral(i) + }); + }; + next(); +}, response('cine_global')); + +superiorEnrollmentAggregateApp.get('/cine_specific', (req, res, next) => { + req.result = []; + const defaultCase = null; + for(let i = 0; i <= 104; ++i) { + let obj = { + id: i, + name: id2str.cineSpecific(i) + }; + if (obj.name !== id1str.cineSpecific(defaultCase)){ + req.result.push(obj); + } + }; + req.result.push({ + id: defaultCase, + name: id2str.cineSpecific(defaultCase) + }); + next(); +}, response('cine_specific')); + +superiorEnrollmentAggregateApp.get('/cine_detailed', (req, res, next) => { + req.result = []; + const defaultCase = null; + for(let i = 11; i <= 1041; ++i) { + let obj = { + id: i, + name: id2str.cineDetailed(i) + }; + if (obj.name !== id2str.cineDetailed(defaultCase)){ + req.result.push(obj); + } + }; + req.result.push({ + id: defaultCase, + name: id2str.cineDetailed(defaultCase) + }); + next(); +}, response('cine_detailed')); rqf.addField({ name: 'filter', @@ -373,58 +260,45 @@ rqf.addField({ type: 'integer', field: 'tp_org_acad' } -}); - -function matchQueries(queryPartial, queryTotal) { - let match = []; - queryTotal.forEach((result) => { - let newObj = {}; - let keys = Object.keys(result); - keys.forEach((key) => { - newObj[key] = result[key]; - }); - let index = keys.indexOf('cod'); - if(index > -1) keys.splice(index, 1); - let objMatch = null; - - for(let i = 0; i < queryPartial.length; ++i) { - let partial = queryPartial[i]; - let foundMatch = true; - for(let j = 0; j < keys.length; ++j) { - let key = keys[j]; - if(partial[key] !== result[key]) { - foundMatch = false; - break; - } - } - if(foundMatch) { - objMatch = partial; - break; - } - } - - if(objMatch) { - newObj.denominator = result.cod; - newObj.partial = objMatch.cod; - // newObj.total = (objMatch.total / result.total) * 100; - match.push(newObj); - } - }); +}).addValue({ + name: 'region_agg', + table: 'curso_superior_agregado', + tableField: 'nome_reg', + resultField: 'reg_name', + where: { + relation: '=', + type: 'integer', + field: 'cod_reg' + } +}).addValue({ + name: 'uf_agg', + table: 'curso_superior_agregado', + tableField: 'nome_uf', + resultField: 'uf_name', + where: { + relation: '=', + type: 'integer', + field: 'cod_uf' + } +}).addValue({ + name: 'mun_agg', + table: 'curso_superior_agregado', + tableField: 'nome_mun', + resultField: 'mun_name', + where: { + relation: '=', + type: 'integer', + field: 'cod_mun' + } +}) - return match; -} superiorEnrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { - req.querySet = []; - - let basic = req.sql.clone(); - let curso = req.sql.clone(); - let ies = req.sql.clone(); - basic.field('curso_superior_agregado.ano_censo', 'year'); + req.sql.field('curso_superior_agregado.ano_censo', 'year'); if (req.query.dims && req.query.dims.includes("ethnic_group")){ - basic.field.field('sum(qtd_mat_branca)', 'total_branca') + req.sql.field.field('sum(qtd_mat_branca)', 'total_branca') .field('sum(qtd_mat_preta)', 'total_preta') .field('sum(qtd_mat_parda)', 'total_parda') .field('sum(qtd_mat_amarela)', 'total_amarela') @@ -432,12 +306,12 @@ superiorEnrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, nex .field('sum(qtd_mat_cor_nao_declarada)', 'total_nd'); } else if (req.query.dims && req.query.dims.includes("school_type")){ - basic.field('sum(qtd_mat_proces_publica)', 'total_publica') + req.sql.field('sum(qtd_mat_proces_publica)', 'total_publica') .field('sum(qtd_mat_proces_privada)', 'total_privada') .field('sum(qtd_mat_proces_nao_informada)', 'total_nao_informada'); } else if (req.query.dims && req.query.dims.includes("age_range_cescu")){ - basic.field('sum(qtd_mat_0_17)', 'total_0_17') + req.sql.field('sum(qtd_mat_0_17)', 'total_0_17') .field('sum(qtd_mat_18_24)', 'total_18_24') .field('sum(qtd_mat_25_29)', 'total_25_29') .field('sum(qtd_mat_30_34)', 'total_30_34') @@ -447,59 +321,26 @@ superiorEnrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, nex .field('sum(qtd_mat_60_mais)', 'total_60_mais'); } else if (req.query.dims && req.query.dims.includes("gender")){ - basic.field('sum(qtd_mat_fem)', 'total_fem') + req.sql.field('sum(qtd_mat_fem)', 'total_fem') .field('sum(qtd_mat_masc)', 'total_masc'); } else if (req.query.dims && req.query.dims.includes("modality_shift_superior")){ - basic.field('sum(qtd_mat_diurno)', 'total_diurno') + req.sql.field('sum(qtd_mat_diurno)', 'total_diurno') .field('sum(qtd_mat_noturno)', 'total_noturno'); } - else if (req.query.dims && req.query.dims.includes("region")){ - curso.field('qtd_matriculas', 'enrollment') - curso.field('cod_reg', 'cod') - curso.field('nome_reg', 'cod_name') - .where('tp_nivel_acad = 1') - .from('curso_superior_agregado') - .group('ano_censo') - .order('ano_censo'); - - ies.field('nome_regiao_ies', 'cod_name') - .where('tp_nivel_acad = 1') - .from('ies_ens_superior') - .where('ano_censo > 2019') - .group('ano_censo') - .order('ano_censo'); - } else { - basic.field('SUM(qtd_matriculas)', 'enrollment'); + req.sql.field('SUM(qtd_matriculas)', 'enrollment'); } - basic.from('curso_superior_agregado') - .from('ies_ens_superior') - // .join('ies_ens_superior', null, 'ies_ens_superior.ano_censo = curso_superior_agregado.ano_censo') + req.sql.from('curso_superior_agregado') .where('tp_nivel_acad = 1') .group('curso_superior_agregado.ano_censo') .order('curso_superior_agregado.ano_censo'); - // console.log(req.sql.toString()); - // // console.log(req.query.dims); - // console.log(req.sql.result); - req.querySet.push(basic); - req.querySet.push(curso); - req.querySet.push(ies); + console.log(req.sql.toString()); next(); -}, multiQuery, query, aggregateData, id2str.transform(false), response('superior_enrollment_aggregate'), (req, res, next) => { - - if (req.result[1] || req.result[2]){ - let newObj = matchQueries(req.result[1], req.result[2]); - req.result = newObj; - } - else { - req.result = req.result[0]; - } - next(); -}); +}, multiQuery, query, aggregateData, id2str.transform(false), response('superior_enrollment_aggregate')); module.exports = superiorEnrollmentAggregateApp; -- GitLab From e2b79a9570b8d5ab0eb8964117d468c4b734c3b8 Mon Sep 17 00:00:00 2001 From: edsaibert <es23@inf.ufpr.br> Date: Mon, 10 Mar 2025 09:46:29 -0300 Subject: [PATCH 06/12] region state city agg --- .../routes_v1/superiorEnrollmentAggregate.js | 83 ++++++++++++++++++- 1 file changed, 80 insertions(+), 3 deletions(-) diff --git a/src/libs/routes_v1/superiorEnrollmentAggregate.js b/src/libs/routes_v1/superiorEnrollmentAggregate.js index e37d4cb5..e9a28788 100644 --- a/src/libs/routes_v1/superiorEnrollmentAggregate.js +++ b/src/libs/routes_v1/superiorEnrollmentAggregate.js @@ -65,7 +65,32 @@ superiorEnrollmentAggregateApp.get('/qtd_graduates', (req, res, next) => { .where('curso_superior_agregado.ano_censo >= 2020') next(); -}) +}, query, response('qtd_graduates')); + +superiorEnrollmentAggregateApp.get('/ies_name', (req, res, next) => { + req.sql.from('curso_superior_agregado') + .field('DISTINCT curso_superior_agregado.cod_ies', 'ies_cod') + .field('curso_superior_agregado.nome_ies', 'ies_name') + .where('curso_superior_agregado.ano_censo >= 2020') + next(); +}, query, response('ies_name')); + +superiorEnrollmentAggregateApp.get('/uf_agg', (req, res, next) => { + req.sql.from('curso_superior_agregado') + .field('DISTINCT curso_superior_agregado.cod_uf', 'uf_cod') + .field('curso_superior_agregado.nome_uf', 'uf_name') + .where('curso_superior_agregado.ano_censo >= 2020') + next(); +}, query, response('uf_agg')); + +superiorEnrollmentAggregateApp.get('/city_agg', (req, res, next) => { + req.sql.from('curso_superior_agregado') + .field('DISTINCT curso_superior_agregado.cod_mun', 'city_cod') + .field('curso_superior_agregado.nome_mun', 'city_name') + .where('curso_superior_agregado.ano_censo >= 2020') + .order('curso_superior_agregado.cod_mun') + next(); +}, query, response('city_agg')); superiorEnrollmentAggregateApp.get('/tp_categ_adm', (req, res, next) => { req.result = [] @@ -127,6 +152,58 @@ superiorEnrollmentAggregateApp.get('/cine_detailed', (req, res, next) => { next(); }, response('cine_detailed')); +superiorEnrollmentAggregateApp.get('/academic_level', (req, res, next) => { + req.result = []; + const defaultCase = null; + for (let i = 0; i <= 3; ++i) { + let obj = { + id: i, + name: id2str.academicLevel(i) + }; + if (obj.name !== id2str.academicLevel(defaultCase)){ + req.result.push(obj); + } + } + req.result.push({ + id: defaultCase, + name: id2str.academicLevel(defaultCase) + }); + next(); +}, response('academic_level')); + +superiorEnrollmentAggregateApp.get('/modality', (req, res, next) => { + req.result = []; + for (let i = 1; i <= 2; ++i) { + req.result.push({ + id: i, + name: id2str.modalityShiftSuperior(i) + }) + } + next(); +}, response('modality')); + +superiorEnrollmentAggregateApp.get('/academic_organization', (req, res, next) => { + req.result = []; + for (let i = 1; i <= 5; ++i) { + req.result.push({ + id: i, + name: id2str.academicOrganization(i) + }) + } + next(); +}, response('academic_organization')); + +superiorEnrollmentAggregateApp.get('/region_agg', (req, res, next) => { + req.result = []; + for (let i = 1; i <= 5; ++i) { + req.result.push({ + id: i, + name: id2str.regionCode(i) + }) + } + next(); +}, response('region_agg')); + rqf.addField({ name: 'filter', field: false, @@ -281,10 +358,10 @@ rqf.addField({ field: 'cod_uf' } }).addValue({ - name: 'mun_agg', + name: 'city_agg', table: 'curso_superior_agregado', tableField: 'nome_mun', - resultField: 'mun_name', + resultField: 'city_name', where: { relation: '=', type: 'integer', -- GitLab From 2f94eac60f818b84b3b64ff6682407f5ff2a04b3 Mon Sep 17 00:00:00 2001 From: es23 <es23@inf.ufpr.br> Date: Wed, 2 Apr 2025 12:00:51 -0300 Subject: [PATCH 07/12] fix filters --- .../routes_v1/superiorEnrollmentAggregate.js | 85 ++++++++++--------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/src/libs/routes_v1/superiorEnrollmentAggregate.js b/src/libs/routes_v1/superiorEnrollmentAggregate.js index e9a28788..7c1350c7 100644 --- a/src/libs/routes_v1/superiorEnrollmentAggregate.js +++ b/src/libs/routes_v1/superiorEnrollmentAggregate.js @@ -59,38 +59,33 @@ superiorEnrollmentAggregateApp.get('/years', (req, res, next) => { next(); }, query, response('years')); -superiorEnrollmentAggregateApp.get('/qtd_graduates', (req, res, next) => { - req.sql.from('curso_superior_agregado') - .field('DISTINCT SUM(curso_superior_agregado.qtd_concluintes)', 'qtd_graduates') - .where('curso_superior_agregado.ano_censo >= 2020') - next(); - -}, query, response('qtd_graduates')); - superiorEnrollmentAggregateApp.get('/ies_name', (req, res, next) => { req.sql.from('curso_superior_agregado') - .field('DISTINCT curso_superior_agregado.cod_ies', 'ies_cod') - .field('curso_superior_agregado.nome_ies', 'ies_name') + .from('ies_ens_superior') + .field('DISTINCT curso_superior_agregado.cod_ies', 'id') + .field('ies_ens_superior.nome_ies', 'name') + .where('ies_ens_superior.cod_ies = curso_superior_agregado.cod_ies') .where('curso_superior_agregado.ano_censo >= 2020') next(); }, query, response('ies_name')); -superiorEnrollmentAggregateApp.get('/uf_agg', (req, res, next) => { +superiorEnrollmentAggregateApp.get('/state', (req, res, next) => { req.sql.from('curso_superior_agregado') - .field('DISTINCT curso_superior_agregado.cod_uf', 'uf_cod') - .field('curso_superior_agregado.nome_uf', 'uf_name') + .field('DISTINCT curso_superior_agregado.cod_uf', 'id') + .field('curso_superior_agregado.nome_uf', 'name') .where('curso_superior_agregado.ano_censo >= 2020') + .where('curso_superior_agregado.nome_uf IS NOT NULL') next(); -}, query, response('uf_agg')); +}, query, response('state')); -superiorEnrollmentAggregateApp.get('/city_agg', (req, res, next) => { +superiorEnrollmentAggregateApp.get('/city', (req, res, next) => { req.sql.from('curso_superior_agregado') - .field('DISTINCT curso_superior_agregado.cod_mun', 'city_cod') - .field('curso_superior_agregado.nome_mun', 'city_name') + .field('DISTINCT curso_superior_agregado.cod_mun', 'id') + .field('curso_superior_agregado.nome_mun', 'name') .where('curso_superior_agregado.ano_censo >= 2020') .order('curso_superior_agregado.cod_mun') next(); -}, query, response('city_agg')); +}, query, response('city')); superiorEnrollmentAggregateApp.get('/tp_categ_adm', (req, res, next) => { req.result = [] @@ -101,7 +96,7 @@ superiorEnrollmentAggregateApp.get('/tp_categ_adm', (req, res, next) => { }); } next(); -}, response('adm_dependency')); +}, response('tp_categ_adm')); superiorEnrollmentAggregateApp.get('/cine_global', (req, res, next) => { req.result = []; @@ -122,7 +117,7 @@ superiorEnrollmentAggregateApp.get('/cine_specific', (req, res, next) => { id: i, name: id2str.cineSpecific(i) }; - if (obj.name !== id1str.cineSpecific(defaultCase)){ + if (obj.name !== id2str.cineSpecific(defaultCase)){ req.result.push(obj); } }; @@ -193,7 +188,7 @@ superiorEnrollmentAggregateApp.get('/academic_organization', (req, res, next) => next(); }, response('academic_organization')); -superiorEnrollmentAggregateApp.get('/region_agg', (req, res, next) => { +superiorEnrollmentAggregateApp.get('/region', (req, res, next) => { req.result = []; for (let i = 1; i <= 5; ++i) { req.result.push({ @@ -202,7 +197,7 @@ superiorEnrollmentAggregateApp.get('/region_agg', (req, res, next) => { }) } next(); -}, response('region_agg')); +}, response('region')); rqf.addField({ name: 'filter', @@ -236,7 +231,7 @@ rqf.addField({ name: 'tp_categ_adm', table: 'curso_superior_agregado', tableField: 'tp_categ_adm', - resultField: 'tp_categ_adm', + resultField: 'tp_categ_adm_id', where: { relation: '=', type: 'integer', @@ -246,27 +241,27 @@ rqf.addField({ name: 'cine_global', table: 'curso_superior_agregado', tableField: ['nome_cine_area_geral', 'cod_cine_area_geral'], - resultField: ['name_cine_global', 'cod_cine_global'], + resultField: ['cine_global_name', 'cine_global_id'], where: { relation: '=', type: 'integer', field: 'cod_cine_area_geral', }, }).addValue({ - name: 'cine_sp', + name: 'cine_specific', table: 'curso_superior_agregado', tableField: ['nome_cine_area_esp', 'cod_cine_area_esp'], - resultField: ['name_cine_sp', 'cod_cine_sp'], + resultField: ['cine_sp_name', 'cine_sp_id'], where: { relation: '=', type: 'integer', field: 'cod_cine_area_esp' } }).addValue({ - name: 'cine_deatiled', + name: 'cine_detailed', table: 'curso_superior_agregado', tableField: ['nome_cine_area_detalhada', 'cod_cine_area_detalhada'], - resultField: ['name_cine_detailed', 'cod_cine_detailed'], + resultField: ['cine_detailed_name', 'cine_detailed_id'], where: { relation: '=', type: 'integer', @@ -276,7 +271,7 @@ rqf.addField({ name: 'graduates', table: 'curso_superior_agregado', tableField: 'qtd_concluintes', - resultField: 'graduates', + resultField: 'graduates_id', where: { relation: '=', type: 'integer', @@ -286,7 +281,7 @@ rqf.addField({ name: 'disabled_students', table: 'curso_superior_agregado', tableField: 'qtd_aluno_deficiente', - resultField: 'disabled_students', + resultField: 'disabled_students_id', where: { relation: '=', type: 'integer', @@ -296,7 +291,7 @@ rqf.addField({ name: 'academic_level', table: 'curso_superior_agregado', tableField: 'tp_grau_acad', - resultField: 'academic_level', + resultField: 'academic_level_id', where: { relation: '=', type: 'integer', @@ -306,7 +301,7 @@ rqf.addField({ name: 'ies_name', table: 'ies_ens_superior', tableField: 'nome_ies', - resultField: 'ies_name', + resultField: 'ies_id', where: { relation: '=', type: 'integer', @@ -321,7 +316,7 @@ rqf.addField({ name: 'modality', table: 'curso_superior_agregado', tableField: 'tp_modal_ens', - resultField: 'modality', + resultField: 'modality_id', where: { relation: '=', type: 'integer', @@ -331,37 +326,37 @@ rqf.addField({ name: 'academic_organization', table: 'curso_superior_agregado', tableField: 'tp_org_acad', - resultField: 'academic_organization', + resultField: 'academic_organization_id', where: { relation: '=', type: 'integer', field: 'tp_org_acad' } }).addValue({ - name: 'region_agg', + name: 'region', table: 'curso_superior_agregado', tableField: 'nome_reg', - resultField: 'reg_name', + resultField: 'reg_id', where: { relation: '=', type: 'integer', field: 'cod_reg' } }).addValue({ - name: 'uf_agg', + name: 'state', table: 'curso_superior_agregado', tableField: 'nome_uf', - resultField: 'uf_name', + resultField: 'uf_id', where: { relation: '=', type: 'integer', field: 'cod_uf' } }).addValue({ - name: 'city_agg', + name: 'city', table: 'curso_superior_agregado', tableField: 'nome_mun', - resultField: 'city_name', + resultField: 'city_id', where: { relation: '=', type: 'integer', @@ -375,7 +370,7 @@ superiorEnrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, nex req.sql.field('curso_superior_agregado.ano_censo', 'year'); if (req.query.dims && req.query.dims.includes("ethnic_group")){ - req.sql.field.field('sum(qtd_mat_branca)', 'total_branca') + req.sql.field('sum(qtd_mat_branca)', 'total_branca') .field('sum(qtd_mat_preta)', 'total_preta') .field('sum(qtd_mat_parda)', 'total_parda') .field('sum(qtd_mat_amarela)', 'total_amarela') @@ -405,8 +400,14 @@ superiorEnrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, nex req.sql.field('sum(qtd_mat_diurno)', 'total_diurno') .field('sum(qtd_mat_noturno)', 'total_noturno'); } + else if (req.query.dims && req.query.dims.includes("qtd_graduates_agg")){ + req.sql.field('SUM(curso_superior_agregado.qtd_concluintes)', 'total'); + } + else if (req.query.dims && req.query.dims.includes("disabled_students_agg")){ + req.sql.field('SUM(curso_superior_agregado.qtd_aluno_deficiente)', 'total') + } else { - req.sql.field('SUM(qtd_matriculas)', 'enrollment'); + req.sql.field('SUM(qtd_matriculas)', 'total'); } req.sql.from('curso_superior_agregado') -- GitLab From 020926cb53cc0e4c365c238b6069b3ff5486a126 Mon Sep 17 00:00:00 2001 From: es23 <es23@inf.ufpr.br> Date: Tue, 22 Apr 2025 09:49:50 -0300 Subject: [PATCH 08/12] minor changes --- src/libs/routes_v1/superiorEnrollmentAggregate.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/routes_v1/superiorEnrollmentAggregate.js b/src/libs/routes_v1/superiorEnrollmentAggregate.js index 7c1350c7..718f0745 100644 --- a/src/libs/routes_v1/superiorEnrollmentAggregate.js +++ b/src/libs/routes_v1/superiorEnrollmentAggregate.js @@ -87,16 +87,16 @@ superiorEnrollmentAggregateApp.get('/city', (req, res, next) => { next(); }, query, response('city')); -superiorEnrollmentAggregateApp.get('/tp_categ_adm', (req, res, next) => { +superiorEnrollmentAggregateApp.get('/tp_categ_adm_agg', (req, res, next) => { req.result = [] - for (let i = 1; i <= 5; i++) { + for (let i = 1; i <= 5; ++i) { req.result.push({ id: i, name: id2str.admDependency(i) }); } next(); -}, response('tp_categ_adm')); +}, response('tp_categ_adm_agg')); superiorEnrollmentAggregateApp.get('/cine_global', (req, res, next) => { req.result = []; @@ -220,7 +220,7 @@ rqf.addField({ }).addValue({ name: 'max_year', table: 'curso_superior_agregado', - tableField: '', + tableField: 'ano_censo', resultField: 'year', where: { relation: '<=', @@ -228,7 +228,7 @@ rqf.addField({ field: 'ano_censo' } }).addValue({ - name: 'tp_categ_adm', + name: 'tp_categ_adm_agg', table: 'curso_superior_agregado', tableField: 'tp_categ_adm', resultField: 'tp_categ_adm_id', -- GitLab From 88022a55523c274ec654b6943a3021f2c1cc6a88 Mon Sep 17 00:00:00 2001 From: es23 <es23@inf.ufpr.br> Date: Thu, 29 May 2025 10:35:58 -0300 Subject: [PATCH 09/12] fix admDependency --- src/libs/convert/admDependencyCursos.js | 41 +++++++++++++++++++ src/libs/middlewares/id2str.js | 3 ++ .../routes_v1/superiorEnrollmentAggregate.js | 14 ++++--- 3 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 src/libs/convert/admDependencyCursos.js diff --git a/src/libs/convert/admDependencyCursos.js b/src/libs/convert/admDependencyCursos.js new file mode 100644 index 00000000..cf9235e3 --- /dev/null +++ b/src/libs/convert/admDependencyCursos.js @@ -0,0 +1,41 @@ +/* +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 admDependencyCursos(id) { + switch (id) { + case 1: + return 'Pública Federal'; + case 2: + return 'Pública Estadual'; + case 3: + return 'Pública Municipal'; + case 4: + return 'Privada com fins lucrativos'; + case 5: + return 'Privada sem fins lucrativos'; + case 6: + return 'Confessional'; + case 7: + return 'Especial'; + default: + return 'Não classificada'; + } +}; + diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index c5edb2ae..d816b743 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -24,6 +24,7 @@ const period = require(`${libs}/convert/period`); const schoolYear = require(`${libs}/convert/schoolYear`); const admDependency = require(`${libs}/convert/admDependency`); const admDependencyPriv = require(`${libs}/convert/admDependencyPriv`); +const admDependencyCursos = require(`${libs}/convert/admDependencyCursos`) const location = require(`${libs}/convert/location`); const ruralLocation = require(`${libs}/convert/ruralLocation`); const ethnicGroup = require(`${libs}/convert/ethnicGroup`); @@ -141,6 +142,7 @@ const ids = { adm_dependency_id: admDependency, adm_dependency_detailed_id: admDependencyPriv, adm_dependency_public_id: admDependencyPub, + adm_dependency_cursos_id: admDependencyCursos, location_id: location, rural_location_id: ruralLocation, location_detailed_id: ruralLocation, @@ -301,6 +303,7 @@ module.exports = { educationLevelSchoolYear, admDependency, admDependencyPriv, + admDependencyCursos, location, ruralLocation, ethnicGroup, diff --git a/src/libs/routes_v1/superiorEnrollmentAggregate.js b/src/libs/routes_v1/superiorEnrollmentAggregate.js index 718f0745..7ac687cf 100644 --- a/src/libs/routes_v1/superiorEnrollmentAggregate.js +++ b/src/libs/routes_v1/superiorEnrollmentAggregate.js @@ -87,16 +87,20 @@ superiorEnrollmentAggregateApp.get('/city', (req, res, next) => { next(); }, query, response('city')); -superiorEnrollmentAggregateApp.get('/tp_categ_adm_agg', (req, res, next) => { +superiorEnrollmentAggregateApp.get('/adm_dependency_cursos', (req, res, next) => { req.result = [] for (let i = 1; i <= 5; ++i) { req.result.push({ - id: i, name: id2str.admDependency(i) + id: i, name: id2str.admDependencyCursos(i) }); } + + req.result.push({ + id: 7, name: id2str.admDependencyCursos(7) + }) next(); -}, response('tp_categ_adm_agg')); +}, response('adm_dependency_cursos')); superiorEnrollmentAggregateApp.get('/cine_global', (req, res, next) => { req.result = []; @@ -228,10 +232,10 @@ rqf.addField({ field: 'ano_censo' } }).addValue({ - name: 'tp_categ_adm_agg', + name: 'adm_dependency_cursos', table: 'curso_superior_agregado', tableField: 'tp_categ_adm', - resultField: 'tp_categ_adm_id', + resultField: 'adm_dependency_cursos_id', where: { relation: '=', type: 'integer', -- GitLab From b6f9ec626197c64ca4bcee8f000fa07ec278dc8b Mon Sep 17 00:00:00 2001 From: es23 <es23@inf.ufpr.br> Date: Fri, 30 May 2025 11:42:15 -0300 Subject: [PATCH 10/12] fix aggregation bugs --- src/libs/middlewares/aggregateData.js | 3 +- .../routes_v1/superiorEnrollmentAggregate.js | 45 ++++++++++++++----- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js index 96272ddc..0bbadad9 100644 --- a/src/libs/middlewares/aggregateData.js +++ b/src/libs/middlewares/aggregateData.js @@ -66,7 +66,8 @@ function aggregateData(req, res, next) { 'post_graduation_entity', 'contract_type_entity', 'education_degree_entity', - 'age_range_cescu' + 'age_range_cescu', + 'modality_shift_superior' ] let id; const fields = req.query.dims.split(','); diff --git a/src/libs/routes_v1/superiorEnrollmentAggregate.js b/src/libs/routes_v1/superiorEnrollmentAggregate.js index 7ac687cf..85aec138 100644 --- a/src/libs/routes_v1/superiorEnrollmentAggregate.js +++ b/src/libs/routes_v1/superiorEnrollmentAggregate.js @@ -59,7 +59,7 @@ superiorEnrollmentAggregateApp.get('/years', (req, res, next) => { next(); }, query, response('years')); -superiorEnrollmentAggregateApp.get('/ies_name', (req, res, next) => { +superiorEnrollmentAggregateApp.get('/universityLocalOffer', (req, res, next) => { req.sql.from('curso_superior_agregado') .from('ies_ens_superior') .field('DISTINCT curso_superior_agregado.cod_ies', 'id') @@ -67,7 +67,7 @@ superiorEnrollmentAggregateApp.get('/ies_name', (req, res, next) => { .where('ies_ens_superior.cod_ies = curso_superior_agregado.cod_ies') .where('curso_superior_agregado.ano_censo >= 2020') next(); -}, query, response('ies_name')); +}, query, response('universityLocalOffer')); superiorEnrollmentAggregateApp.get('/state', (req, res, next) => { req.sql.from('curso_superior_agregado') @@ -255,7 +255,7 @@ rqf.addField({ name: 'cine_specific', table: 'curso_superior_agregado', tableField: ['nome_cine_area_esp', 'cod_cine_area_esp'], - resultField: ['cine_sp_name', 'cine_sp_id'], + resultField: ['cine_specific_name', 'cine_specific_id'], where: { relation: '=', type: 'integer', @@ -302,10 +302,10 @@ rqf.addField({ field: 'tp_grau_acad' } }).addValue({ - name: 'ies_name', + name: 'universityLocalOffer', table: 'ies_ens_superior', - tableField: 'nome_ies', - resultField: 'ies_id', + tableField: ['nome_ies'], + resultField: ['universityLocalOffer_name'], where: { relation: '=', type: 'integer', @@ -339,8 +339,8 @@ rqf.addField({ }).addValue({ name: 'region', table: 'curso_superior_agregado', - tableField: 'nome_reg', - resultField: 'reg_id', + tableField: ['nome_reg', 'cod_reg'], + resultField: ['region_name', 'region_id'], where: { relation: '=', type: 'integer', @@ -349,8 +349,8 @@ rqf.addField({ }).addValue({ name: 'state', table: 'curso_superior_agregado', - tableField: 'nome_uf', - resultField: 'uf_id', + tableField: ['cod_uf'], + resultField: ['state_id'], where: { relation: '=', type: 'integer', @@ -359,8 +359,8 @@ rqf.addField({ }).addValue({ name: 'city', table: 'curso_superior_agregado', - tableField: 'nome_mun', - resultField: 'city_id', + tableField: ['nome_mun', 'cod_mun'], + resultField: ['city_name', 'city_id'], where: { relation: '=', type: 'integer', @@ -368,8 +368,28 @@ rqf.addField({ } }) +function whereCondition(req) { + let where = ""; + const dims = req.query.dims; + + if (dims && dims.includes("city")){ + where += `curso_superior_agregado.nome_mun is not null` + } + + if (dims && dims.includes("region")){ + where += `curso_superior_agregado.nome_reg is not null` + } + + if (dims && dims.includes("state")){ + where += `curso_superior_agregado.cod_uf <> 99` + } + + return where; +} + superiorEnrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + let where = whereCondition(req); req.sql.field('curso_superior_agregado.ano_censo', 'year'); @@ -416,6 +436,7 @@ superiorEnrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, nex req.sql.from('curso_superior_agregado') .where('tp_nivel_acad = 1') + .where(`${where}`) .group('curso_superior_agregado.ano_censo') .order('curso_superior_agregado.ano_censo'); -- GitLab From a2440a9b12e703f93ffcab9689ae77329f9c6672 Mon Sep 17 00:00:00 2001 From: es23 <es23@inf.ufpr.br> Date: Tue, 3 Jun 2025 10:42:21 -0300 Subject: [PATCH 11/12] add school_type --- src/libs/middlewares/aggregateData.js | 5 +++-- src/libs/routes_v1/superiorEnrollmentAggregate.js | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js index 0bbadad9..3535879f 100644 --- a/src/libs/middlewares/aggregateData.js +++ b/src/libs/middlewares/aggregateData.js @@ -38,7 +38,7 @@ const convert = { government_agreement: "governmentAgreement", school_type: "schoolType", age_range_cescu: "ageRangeCescu", - modality_shift_superior: "modalityShiftSuperior" + modality_shift_superior: "modalityShiftSuperior", } function aggregateData(req, res, next) { @@ -67,7 +67,8 @@ function aggregateData(req, res, next) { 'contract_type_entity', 'education_degree_entity', 'age_range_cescu', - 'modality_shift_superior' + 'modality_shift_superior', + 'school_type' ] let id; const fields = req.query.dims.split(','); diff --git a/src/libs/routes_v1/superiorEnrollmentAggregate.js b/src/libs/routes_v1/superiorEnrollmentAggregate.js index 85aec138..0e543d92 100644 --- a/src/libs/routes_v1/superiorEnrollmentAggregate.js +++ b/src/libs/routes_v1/superiorEnrollmentAggregate.js @@ -430,6 +430,11 @@ superiorEnrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, nex else if (req.query.dims && req.query.dims.includes("disabled_students_agg")){ req.sql.field('SUM(curso_superior_agregado.qtd_aluno_deficiente)', 'total') } + else if (req.query.dims && req.query.dims.includes("school_type")){ + req.sql.field('SUM(curso_superior_agregado.qtd_mat_proces_publica)', 'total_publica') + .field('SUM(curso_superior_agregado.qtd_mat_proces_privada)', 'total_privada') + .field('SUM(curso_superior_agregado.qtd_mat_proces_nao_informada)', 'total_nao_informada'); + } else { req.sql.field('SUM(qtd_matriculas)', 'total'); } -- GitLab From ff131c8e54c1ff86b2a3007b2207208374a08977 Mon Sep 17 00:00:00 2001 From: es23 <es23@inf.ufpr.br> Date: Tue, 3 Jun 2025 10:57:27 -0300 Subject: [PATCH 12/12] gender agg fix --- src/libs/routes_v1/superiorEnrollmentAggregate.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/routes_v1/superiorEnrollmentAggregate.js b/src/libs/routes_v1/superiorEnrollmentAggregate.js index 0e543d92..16b3ef4b 100644 --- a/src/libs/routes_v1/superiorEnrollmentAggregate.js +++ b/src/libs/routes_v1/superiorEnrollmentAggregate.js @@ -417,8 +417,8 @@ superiorEnrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, nex .field('sum(qtd_mat_60_mais)', 'total_60_mais'); } else if (req.query.dims && req.query.dims.includes("gender")){ - req.sql.field('sum(qtd_mat_fem)', 'total_fem') - .field('sum(qtd_mat_masc)', 'total_masc'); + req.sql.field('sum(qtd_mat_masc)', 'total_masc') + .field('sum(qtd_mat_fem)', 'total_fem'); } else if (req.query.dims && req.query.dims.includes("modality_shift_superior")){ req.sql.field('sum(qtd_mat_diurno)', 'total_diurno') -- GitLab