From 482c2882d39d315700049ad6a87006bbd7e3ca27 Mon Sep 17 00:00:00 2001 From: fgs21 <fgs21@inf.ufpr.br> Date: Thu, 5 Sep 2024 09:27:35 -0300 Subject: [PATCH 1/6] [ADD] Creating courseAggregate route --- src/libs/routes_v1/api.js | 3 + src/libs/routes_v1/courseAggregate.js | 520 ++++++++++++++++++++++++++ 2 files changed, 523 insertions(+) create mode 100644 src/libs/routes_v1/courseAggregate.js diff --git a/src/libs/routes_v1/api.js b/src/libs/routes_v1/api.js index ba036951..d84fc342 100644 --- a/src/libs/routes_v1/api.js +++ b/src/libs/routes_v1/api.js @@ -149,6 +149,8 @@ const enrollmentAggregate = require(`${libs}/routes_v1/enrollmentAggregate`); const employeesAggregate = require(`${libs}/routes_v1/employeesAggregate`); +const courseAggregate = require(`${libs}/routes_v1/courseAggregate`); + const email = require(`${libs}/routes_v1/email`); api.get('/', (req, res) => { @@ -214,6 +216,7 @@ api.use('/new_pnad', newPnad); api.use('/rate_school_new', rateSchoolNew) api.use('/enrollmentAggregate', enrollmentAggregate); api.use('/employeesAggregate', employeesAggregate); +api.use('/course_aggregate', courseAggregate); //Publication diff --git a/src/libs/routes_v1/courseAggregate.js b/src/libs/routes_v1/courseAggregate.js new file mode 100644 index 00000000..9b372c38 --- /dev/null +++ b/src/libs/routes_v1/courseAggregate.js @@ -0,0 +1,520 @@ +/* +Copyright (C) 2024 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 CourseAggregateApp = express.Router(); + +const libs = `${process.cwd()}/libs`; + +const squel = require('squel'); + +const query = require(`${libs}/middlewares/query`).query; + +const response = require(`${libs}/middlewares/response`); + +const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); + +const id2str = require(`${libs}/middlewares/id2str`); + +const config = require(`${libs}/config`); + +const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware; + +let rqf = new ReqQueryFields(); + +CourseAggregateApp.use(cache('15 day')); + +CourseAggregateApp.get('/years', (req, res, next) => { + req.sql.from('curso_superior_agregado') + .field('DISTINCT curso_superior_agregado.ano_censo', 'year') + next(); +}, query, response('years')); + +courseAggregateApp.get('/upper_adm_dependency', (req, res, next) => { + req.result = []; + for(let i = 1; i <= 7; ++i) { + req.result.push({ + id: i, + name: id2str.upperAdmDependency(i) + }); + }; + next(); +}, response('upper_adm_dependency')); + +courseCountApp.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')); + +courseCountApp.get('/academic_level', (req, res, next) => { + req.result = []; + for(let i = 1; i <= 4; ++i) { + req.result.push({ + id: i, + name: id2str.academicLevel(i) + }); + }; + next(); +}, response('academic_level')); + +CourseAggregateApp.get('/new_pnad_adm_dependency', (req, res, next) => { + req.result = [] + for (let i = 1; i < 3; i++) { + req.result.push({ + id: i, name: id2str.newPnadAdmDependency(i) + }); + } + req.result.push({id: 99, name: id2str.newPnadAdmDependency(99)}); + next(); +}, response('new_pnad_adm_dependency')); + +CourseAggregateApp.get('/region', (req, res, next) => { + req.result = [] + for (let i = 1; i < 6; i++) { + req.result.push({ + id: i, name: id2str.regionCode(i) + }); + } + + next(); +}, response('region')); + +CourseAggregateApp.get('/cap_code', (req, res, next) => { + req.result = [] + for (let i = 11; i < 54; i++) { + if (id2str.capitalCode(i) !== 'Não informado') { + req.result.push({ + id: i, name: id2str.capitalCode(i) + }); + } + } + req.result.push({id: 99, name: id2str.capitalCode(99)}); + + next(); +}, response('cap_code')); + +CourseAggregateApp.get('/metro_code', (req, res, next) => { + req.result = [] + for (let i = 13; i < 53; i++) { + if (id2str.metroCode(i) !== 'Não informado') { + req.result.push({ + id: i, name: id2str.metroCode(i) + }); + } + } + req.result.push({id: 99, name: id2str.metroCode(99)}); + + next(); +}, response('metro_code')); + +CourseAggregateApp.get('/attended_modality', (req, res, next) => { + req.result = [] + for (let i = 1; i < 16; i++) { + req.result.push({ + id: i, name: id2str.attendedModality(i) + }); + } + // Remove the option with id equals 10 => This option exists in the database, a better solution to this would be remove the option from the database + req.result.splice(req.result.findIndex((item) => item.id === 10), 1); + req.result.push({id: 99, name: id2str.attendedModality(99)}); + next(); +}, response('attended_modality')); + +CourseAggregateApp.get('/income_range', (req, res, next) => { + req.result = [] + for (let i = 1; i < 8; i++) { + req.result.push({ + id: i, name: id2str.incomeRange(i) + }); + } + req.result.push({id: 9, name: id2str.incomeRange(9)}); + next(); +}, response('income_range')); + +CourseAggregateApp.get('/attends_school', (req, res, next) => { + req.result = [] + for (let i = 1; i < 3; i++) { + req.result.push({ + id: i, name: id2str.attendsSchool(i) + }); + } + next(); +}, response('attends_school')); + +CourseAggregateApp.get('/gender', (req, res, next) => { + req.result = [] + for (let i = 1; i < 3; i++) { + req.result.push({ + id: i, name: id2str.gender(i) + }); + } + next(); +}, response('gender')); + +CourseAggregateApp.get('/new_pnad_ethnic_group', (req, res, next) => { + req.result = [] + for (let i = 1; i < 6; i++) { + req.result.push({ + id: i, name: id2str.ethnicGroupNewPnad(i) + }); + } + req.result.push({id: 9, name: id2str.ethnicGroupNewPnad(9)}); + next(); +}, response('new_pnad_ethnic_group')); + +CourseAggregateApp.get('/bolsa_familia', (req, res, next) => { + req.result = [] + for (let i = 1; i < 3; i++) { + req.result.push({ + id: i, name: id2str.attendsSchool(i) + }); + } + req.result.push({id: 9, name: id2str.attendsSchool(9)}); + next(); +}, response('bolsa_familia')); + +CourseAggregateApp.get('/modality', (req, res, next) => { + req.result = [] + for (let i = 1; i < 4; i++) { + req.result.push({ + id: i, name: id2str.modality(i) + }); + } + req.result.push({id: 99, name: id2str.modality(99)}); + next(); +}, response('modality')); + +CourseAggregateApp.get('/modality_shift', (req, res, next) => { + req.result = [] + for (let i = 1; i < 8; i++) { + req.result.push({ + id: i, name: id2str.modalityShift(i) + }); + } + req.result.push({id: 9, name: id2str.modalityShift(9)}); + req.result.push({id: 99, name: id2str.modalityShift(99)}); + next(); +}, response('modality_shift')); + +CourseAggregateApp.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) + }); + } + } + req.result.push({id: 99, name: id2str.stateName(99)}); + + next(); +}, response('state')); + +CourseAggregateApp.get('/age_range_all', (req, res, next) => { + req.result = [] + for (let i = 1; i < 12; i++) { + req.result.push({ + id: i, name: id2str.ageRangeAll(i) + }); + } + + next(); +}, response('age_range_all')); + + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'adm_category', + table: 'curso_superior_agregado', + tableField: 'id', + where: { + relation: '=', + type: 'integer', + field: 'id' + } +}).addValue({ + name: 'state', + table: 'estado', + tableField: ['id', 'nome'], + resultField: ['state_id', 'state_nome'], + where: { + relation: '=', + type: 'integer', + field: 'id', + }, + join: { + primary: 'id', + foreign: 'cod_uf', + foreignTable: 'curso_superior_agregado' + } +}).addValue({ + name: 'state_not', + table: 'estado', + tableField: ['nome', 'id'], + resultField: ['state_name', 'state_id'], + where: { + relation: '<>', + type: 'integer', + field: 'cod_uf', + table: 'curso_superior_agregado' + }, + join: { + primary: 'id', + foreign: 'cod_uf', + foreignTable: 'curso_superior_agregado' + } +}).addValue({ + name: 'years_of_study', + table: 'curso_superior_agregado', + tableField: 'anos_de_estudo', + resultField: 'years_of_study_id', + where: { + relation: '=', + type: 'integer', + field: 'anos_de_estudo' + } +}).addValue({ + name: 'instruction_level', + table: 'curso_superior_agregado', + tableField: 'nivel_de_instrucao', + resultField: 'instruction_level_id', + where: { + relation: '=', + type: 'integer', + field: 'nivel_de_instrucao' + } +}).addValue({ + name: 'new_pnad_adm_dependency', + table: 'curso_superior_agregado', + tableField: 'dependencia_adm', + resultField: 'new_pnad_adm_dependency_id', + where: { + relation: '=', + type: 'integer', + field: 'dependencia_adm' + } +}).addValue({ + name: 'attends_school', + table: 'curso_superior_agregado', + tableField: 'frequenta_escola', + resultField: 'attends_school_id', + where: { + relation: '=', + type: 'integer', + field: 'frequenta_escola' + } +}).addValue({ + name: 'modality', + table: 'curso_superior_agregado', + tableField: 'modalidade', + resultField: 'modality_id', + where: { + relation: '=', + type: 'integer', + field: 'modalidade' + } +}).addValue({ + name: 'attended_modality', + table: 'curso_superior_agregado', + tableField: 'nivel_etapa_modalidade_freq', + resultField: 'attended_modality_id', + where: { + relation: '=', + type: 'integer', + field: 'nivel_etapa_modalidade_freq' + } +}).addValue({ + name: 'illiteracy', + table: 'curso_superior_agregado', + tableField: 'analfabetismo', + resultField: 'illiteracy_id', + where: { + relation: '=', + type: 'integer', + field: 'analfabetismo' + } +}).addValue({ + name: 'modality_shift', + table: 'curso_superior_agregado', + tableField: 'turno_nivel_etapa', + resultField: 'modality_shift_id', + where: { + relation: '=', + type: 'integer', + field: 'turno_nivel_etapa' + } +}).addValue({ + name: 'bolsa_familia', + table: 'curso_superior_agregado', + tableField: 'recebeu_rendimentos_de_programa_bolsa_familia', + resultField: 'bolsa_familia_id', + where: { + relation: '=', + type: 'integer', + field: 'recebeu_rendimentos_de_programa_bolsa_familia' + } +}).addValue({ + name: 'new_pnad_ethnic_group', + table: 'curso_superior_agregado', + tableField: 'cor_raca', + resultField: 'new_pnad_ethnic_group_id', + where: { + relation: '=', + type: 'integer', + field: 'cor_raca' + } +}).addValue({ + name: 'age_range_all', + table: 'curso_superior_agregado', + tableField: 'faixa_etaria', + resultField: 'age_range_all_id', + where: { + relation: '=', + type: 'integer', + field: 'faixa_etaria' + } +}).addValue({ + name: 'income_range', + table: 'curso_superior_agregado', + tableField: 'faixa_rendimento_aux', + resultField: 'income_range_id', + where: { + relation: '=', + type: 'integer', + field: 'faixa_rendimento_aux' + } +}).addValue({ + name: 'gender', + table: 'curso_superior_agregado', + tableField: 'sexo', + resultField: 'gender_id', + where: { + relation: '=', + type: 'integer', + field: 'sexo' + } +}).addValue({ + name: 'cap_code', + table: 'curso_superior_agregado', + tableField: 'cod_cap', + resultField: 'cap_code_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_cap' + } +}).addValue({ + name: 'region', + table: 'curso_superior_agregado', + tableField: 'cod_regiao', + resultField: 'region_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_regiao' + } +}).addValue({ + name: 'metro_code', + table: 'curso_superior_agregado', + tableField: 'cod_rm_ride', + resultField: 'metro_code_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_rm_ride' + } +}).addValue({ + name: 'min_year', + table: 'curso_superior_agregado', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'max_year', + table: 'curso_superior_agregado', + tableField: '', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + field: 'ano_censo' + } +}).addField({ + name: 'search', + field: false, + where: true +}).addValueToField({ + name: 'name', + table: 'curso_superior_agregado', + tableField: 'nome', + where: { + relation: 'LIKE', + type: 'string', + field: 'nome' + } +}, 'search').addValue({ + name: 'mesoregion', + table: 'curso_superior_agregado', + tableField: 'mesorregiao_id', + where: { + relation: '=', + type: 'integer', + field: 'mesorregiao_id' + } +}).addValue({ + name: 'microregion', + table: 'curso_superior_agregado', + tableField: 'microrregiao_id', + where: { + relation: '=', + type: 'integer', + field: 'microrregiao_id' + } +}); + +CourseAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + req.sql.from('curso_superior_agregado') + .field('count(distinct(cod_curso))', 'total') + .field('curso_superior_agregado.ano_censo', 'year') + .group('curso_superior_agregado.ano_censo') + .order('curso_superior_agregado.ano_censo') + console.log(req.sql.toString()) + next(); +}, query, id2str.transform(false), response('curso_superior_agregado')); + +module.exports = CourseAggregateApp; -- GitLab From e2818eeef576e3edcea33e46a4cd53d26201cd37 Mon Sep 17 00:00:00 2001 From: fgs21 <fgs21@inf.ufpr.br> Date: Wed, 11 Sep 2024 10:45:04 -0300 Subject: [PATCH 2/6] [ADD] First test version done, updating to test in development --- src/libs/routes_v1/courseAggregate.js | 347 +++++++++----------------- 1 file changed, 119 insertions(+), 228 deletions(-) diff --git a/src/libs/routes_v1/courseAggregate.js b/src/libs/routes_v1/courseAggregate.js index 9b372c38..9be3a7ed 100644 --- a/src/libs/routes_v1/courseAggregate.js +++ b/src/libs/routes_v1/courseAggregate.js @@ -48,7 +48,7 @@ CourseAggregateApp.get('/years', (req, res, next) => { next(); }, query, response('years')); -courseAggregateApp.get('/upper_adm_dependency', (req, res, next) => { +CourseAggregateApp.get('/upper_adm_dependency', (req, res, next) => { req.result = []; for(let i = 1; i <= 7; ++i) { req.result.push({ @@ -59,7 +59,7 @@ courseAggregateApp.get('/upper_adm_dependency', (req, res, next) => { next(); }, response('upper_adm_dependency')); -courseCountApp.get('/academic_organization', (req, res, next) => { +CourseAggregateAppApp.get('/academic_organization', (req, res, next) => { req.result = []; for(let i = 1; i <= 5; ++i) { req.result.push({ @@ -70,7 +70,7 @@ courseCountApp.get('/academic_organization', (req, res, next) => { next(); }, response('academic_organization')); -courseCountApp.get('/academic_level', (req, res, next) => { +CourseAggregateAppApp.get('/academic_level', (req, res, next) => { req.result = []; for(let i = 1; i <= 4; ++i) { req.result.push({ @@ -81,16 +81,16 @@ courseCountApp.get('/academic_level', (req, res, next) => { next(); }, response('academic_level')); -CourseAggregateApp.get('/new_pnad_adm_dependency', (req, res, next) => { - req.result = [] - for (let i = 1; i < 3; i++) { +CourseAggregateApp.get('/upper_education_mod', (req, res, next) => { + req.result = []; + for(let i = 1; i <= 2; ++i) { req.result.push({ - id: i, name: id2str.newPnadAdmDependency(i) + id: i, + name: id2str.upperEducationMod(i) }); - } - req.result.push({id: 99, name: id2str.newPnadAdmDependency(99)}); + }; next(); -}, response('new_pnad_adm_dependency')); +}, response('upper_education_mod')); CourseAggregateApp.get('/region', (req, res, next) => { req.result = [] @@ -131,94 +131,72 @@ CourseAggregateApp.get('/metro_code', (req, res, next) => { next(); }, response('metro_code')); -CourseAggregateApp.get('/attended_modality', (req, res, next) => { - req.result = [] - for (let i = 1; i < 16; i++) { - req.result.push({ - id: i, name: id2str.attendedModality(i) - }); - } - // Remove the option with id equals 10 => This option exists in the database, a better solution to this would be remove the option from the database - req.result.splice(req.result.findIndex((item) => item.id === 10), 1); - req.result.push({id: 99, name: id2str.attendedModality(99)}); +CourseAggregateAppApp.get('/is_free', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Classificado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; next(); -}, response('attended_modality')); +}, response('is_free')); -CourseAggregateApp.get('/income_range', (req, res, next) => { - req.result = [] - for (let i = 1; i < 8; i++) { - req.result.push({ - id: i, name: id2str.incomeRange(i) - }); - } - req.result.push({id: 9, name: id2str.incomeRange(9)}); - next(); -}, response('income_range')); -CourseAggregateApp.get('/attends_school', (req, res, next) => { - req.result = [] - for (let i = 1; i < 3; i++) { - req.result.push({ - id: i, name: id2str.attendsSchool(i) - }); - } - next(); -}, response('attends_school')); - -CourseAggregateApp.get('/gender', (req, res, next) => { - req.result = [] - for (let i = 1; i < 3; i++) { - req.result.push({ - id: i, name: id2str.gender(i) - }); - } - next(); -}, response('gender')); - -CourseAggregateApp.get('/new_pnad_ethnic_group', (req, res, next) => { - req.result = [] - for (let i = 1; i < 6; i++) { +CourseAggregateApp.get('/cine_geral', (req, res, next) => { + req.result = []; + for(let i = 1; i <= 10; ++i) { req.result.push({ - id: i, name: id2str.ethnicGroupNewPnad(i) + id: i, + name: id2str.cineGeral(i) }); - } - req.result.push({id: 9, name: id2str.ethnicGroupNewPnad(9)}); + }; next(); -}, response('new_pnad_ethnic_group')); +}, response('cine_geral')); -CourseAggregateApp.get('/bolsa_familia', (req, res, next) => { - req.result = [] - for (let i = 1; i < 3; i++) { - req.result.push({ - id: i, name: id2str.attendsSchool(i) - }); - } - req.result.push({id: 9, name: id2str.attendsSchool(9)}); +CourseAggregateApp.get('/cine_specific', (req, res, next) => { + req.result = []; + const defaultCase = null; + for(let i = 1; i <= 104; ++i) { + let obj = { + id: i, + name: id2str.cineSpecific(i) + }; + if (obj.name !== id2str.cineSpecific(defaultCase)){ + req.result.push(obj); + } + }; + req.result.push({ + id: defaultCase, + name: id2str.cineSpecific(defaultCase) + }); next(); -}, response('bolsa_familia')); +}, response('cine_specific')); -CourseAggregateApp.get('/modality', (req, res, next) => { - req.result = [] - for (let i = 1; i < 4; i++) { - req.result.push({ - id: i, name: id2str.modality(i) - }); - } - req.result.push({id: 99, name: id2str.modality(99)}); +CourseAggregateApp.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('modality')); +}, response('cine_detailed')); -CourseAggregateApp.get('/modality_shift', (req, res, next) => { - req.result = [] - for (let i = 1; i < 8; i++) { - req.result.push({ - id: i, name: id2str.modalityShift(i) - }); - } - req.result.push({id: 9, name: id2str.modalityShift(9)}); - req.result.push({id: 99, name: id2str.modalityShift(99)}); +CourseAggregateApp.get('/university', (req, res, next) => { + req.sql.from('curso_superior_agregado') + .field('DISTINCT curso_superior_agregado.cod_ies', 'cod') + .field('ies_ens_superior.cod_ies', 'nome') + .join('ies_ens_superior', null, 'curso_superior_agregado.cod_ies = ies_ens_superior.cod_ies and curso_superior_agregado.ano_censo = ies_ens_superior.ano_censo') next(); -}, response('modality_shift')); +}, query, response('university')); CourseAggregateApp.get('/state', (req, res, next) => { req.result = [] @@ -234,18 +212,6 @@ CourseAggregateApp.get('/state', (req, res, next) => { next(); }, response('state')); -CourseAggregateApp.get('/age_range_all', (req, res, next) => { - req.result = [] - for (let i = 1; i < 12; i++) { - req.result.push({ - id: i, name: id2str.ageRangeAll(i) - }); - } - - next(); -}, response('age_range_all')); - - rqf.addField({ name: 'filter', field: false, @@ -255,13 +221,14 @@ rqf.addField({ field: true, where: false }).addValue({ - name: 'adm_category', + name: 'upper_adm_dependency', table: 'curso_superior_agregado', - tableField: 'id', + tableField: 'tp_categ_adm', + resultField: 'upper_adm_dependency_id', where: { relation: '=', type: 'integer', - field: 'id' + field: 'tp_categ_adm' } }).addValue({ name: 'state', @@ -279,150 +246,89 @@ rqf.addField({ foreignTable: 'curso_superior_agregado' } }).addValue({ - name: 'state_not', - table: 'estado', - tableField: ['nome', 'id'], - resultField: ['state_name', 'state_id'], - where: { - relation: '<>', - type: 'integer', - field: 'cod_uf', - table: 'curso_superior_agregado' - }, - join: { - primary: 'id', - foreign: 'cod_uf', - foreignTable: 'curso_superior_agregado' - } -}).addValue({ - name: 'years_of_study', - table: 'curso_superior_agregado', - tableField: 'anos_de_estudo', - resultField: 'years_of_study_id', - where: { - relation: '=', - type: 'integer', - field: 'anos_de_estudo' - } -}).addValue({ - name: 'instruction_level', - table: 'curso_superior_agregado', - tableField: 'nivel_de_instrucao', - resultField: 'instruction_level_id', - where: { - relation: '=', - type: 'integer', - field: 'nivel_de_instrucao' - } -}).addValue({ - name: 'new_pnad_adm_dependency', - table: 'curso_superior_agregado', - tableField: 'dependencia_adm', - resultField: 'new_pnad_adm_dependency_id', - where: { - relation: '=', - type: 'integer', - field: 'dependencia_adm' - } -}).addValue({ - name: 'attends_school', - table: 'curso_superior_agregado', - tableField: 'frequenta_escola', - resultField: 'attends_school_id', - where: { - relation: '=', - type: 'integer', - field: 'frequenta_escola' - } -}).addValue({ - name: 'modality', - table: 'curso_superior_agregado', - tableField: 'modalidade', - resultField: 'modality_id', - where: { - relation: '=', - type: 'integer', - field: 'modalidade' - } -}).addValue({ - name: 'attended_modality', + name: 'academic_organization', table: 'curso_superior_agregado', - tableField: 'nivel_etapa_modalidade_freq', - resultField: 'attended_modality_id', + tableField: 'tp_org_acad', + resultField: 'academic_organization_id', where: { relation: '=', type: 'integer', - field: 'nivel_etapa_modalidade_freq' + field: 'tp_org_aca' } }).addValue({ - name: 'illiteracy', + name: 'academic_level', table: 'curso_superior_agregado', - tableField: 'analfabetismo', - resultField: 'illiteracy_id', + tableField: 'tp_grau_acad', + resultField: 'academic_level_id', where: { relation: '=', type: 'integer', - field: 'analfabetismo' + field: 'tp_grau_acad' } }).addValue({ - name: 'modality_shift', + name: 'upper_education_mod', table: 'curso_superior_agregado', - tableField: 'turno_nivel_etapa', - resultField: 'modality_shift_id', + tableField: 'tp_modal_ens', + resultField: 'upper_education_mod_id', where: { relation: '=', type: 'integer', - field: 'turno_nivel_etapa' + field: 'tp_modal_ens' } }).addValue({ - name: 'bolsa_familia', + name: 'is_free', table: 'curso_superior_agregado', - tableField: 'recebeu_rendimentos_de_programa_bolsa_familia', - resultField: 'bolsa_familia_id', + tableField: 'in_gratuito', + resultField: 'is_free_id', where: { relation: '=', - type: 'integer', - field: 'recebeu_rendimentos_de_programa_bolsa_familia' + type: 'boolean', + field: 'in_gratuito' } }).addValue({ - name: 'new_pnad_ethnic_group', + name: 'cine_geral', table: 'curso_superior_agregado', - tableField: 'cor_raca', - resultField: 'new_pnad_ethnic_group_id', + tableField: 'cod_cine_area_geral', + resultField: 'cine_geral_id', where: { relation: '=', type: 'integer', - field: 'cor_raca' + field: 'cod_cine_area_geral' } }).addValue({ - name: 'age_range_all', + name: 'cine_specific', table: 'curso_superior_agregado', - tableField: 'faixa_etaria', - resultField: 'age_range_all_id', + tableField: 'cod_cine_area_esp', + resultField: 'cine_specific_id', where: { relation: '=', type: 'integer', - field: 'faixa_etaria' + field: 'cod_cine_area_esp' } }).addValue({ - name: 'income_range', + name: 'cine_detailed', table: 'curso_superior_agregado', - tableField: 'faixa_rendimento_aux', - resultField: 'income_range_id', + tableField: 'cod_cine_area_detalhada', + resultField: 'cine_detailed_id', where: { relation: '=', type: 'integer', - field: 'faixa_rendimento_aux' + field: 'cod_cine_area_detalhada' } }).addValue({ - name: 'gender', - table: 'curso_superior_agregado', - tableField: 'sexo', - resultField: 'gender_id', + name: 'university', + table: 'ies_ens_superior', + tableField: ['cod_ies', 'nome_ies'], + resultField: ['university_id', 'university_name'], where: { relation: '=', type: 'integer', - field: 'sexo' + field: 'cod_ies' + }, + join: { + primary: ['cod_ies', 'ano_censo'], + foreign: ['cod_ies', 'ano_censo'], + foreignTable: 'curso_superior_agregado' } }).addValue({ name: 'cap_code', @@ -474,36 +380,21 @@ rqf.addField({ type: 'integer', field: 'ano_censo' } -}).addField({ - name: 'search', - field: false, - where: true -}).addValueToField({ - name: 'name', - table: 'curso_superior_agregado', - tableField: 'nome', - where: { - relation: 'LIKE', - type: 'string', - field: 'nome' - } -}, 'search').addValue({ - name: 'mesoregion', - table: 'curso_superior_agregado', - tableField: 'mesorregiao_id', - where: { - relation: '=', - type: 'integer', - field: 'mesorregiao_id' - } }).addValue({ - name: 'microregion', - table: 'curso_superior_agregado', - tableField: 'microrregiao_id', + name: 'city', + table: 'municipio', + tableField: ['id', 'nome'], + resultField: ['city_id', 'city_name'], where: { relation: '=', type: 'integer', - field: 'microrregiao_id' + field: 'id', + table: 'municipio' + }, + join: { + primary: 'id', + foreign: 'cod_mun', + foreignTable: 'curso_superior_agregado' } }); @@ -515,6 +406,6 @@ CourseAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .order('curso_superior_agregado.ano_censo') console.log(req.sql.toString()) next(); -}, query, id2str.transform(false), response('curso_superior_agregado')); +}, query, id2str.transform(false), response('course_aggregate')); module.exports = CourseAggregateApp; -- GitLab From 6ccbd774768cc7382f684fe2eaed6b53bc62fe96 Mon Sep 17 00:00:00 2001 From: fgs21 <fgs21@inf.ufpr.br> Date: Wed, 11 Sep 2024 11:04:56 -0300 Subject: [PATCH 3/6] [FIX] CourseAggregateApp name fix --- src/libs/routes_v1/courseAggregate.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/routes_v1/courseAggregate.js b/src/libs/routes_v1/courseAggregate.js index 9be3a7ed..b9dc7f61 100644 --- a/src/libs/routes_v1/courseAggregate.js +++ b/src/libs/routes_v1/courseAggregate.js @@ -59,7 +59,7 @@ CourseAggregateApp.get('/upper_adm_dependency', (req, res, next) => { next(); }, response('upper_adm_dependency')); -CourseAggregateAppApp.get('/academic_organization', (req, res, next) => { +CourseAggregateApp.get('/academic_organization', (req, res, next) => { req.result = []; for(let i = 1; i <= 5; ++i) { req.result.push({ @@ -70,7 +70,7 @@ CourseAggregateAppApp.get('/academic_organization', (req, res, next) => { next(); }, response('academic_organization')); -CourseAggregateAppApp.get('/academic_level', (req, res, next) => { +CourseAggregateApp.get('/academic_level', (req, res, next) => { req.result = []; for(let i = 1; i <= 4; ++i) { req.result.push({ @@ -131,7 +131,7 @@ CourseAggregateApp.get('/metro_code', (req, res, next) => { next(); }, response('metro_code')); -CourseAggregateAppApp.get('/is_free', (req, res, next) => { +CourseAggregateApp.get('/is_free', (req, res, next) => { req.result = [ {id: null, name: 'Não Classificado'}, {id: 0, name: 'Não'}, -- GitLab From be1511b4c0a548c3b377d1e65d0811ce4dd6bc94 Mon Sep 17 00:00:00 2001 From: fgs21 <fgs21@inf.ufpr.br> Date: Wed, 11 Sep 2024 11:33:16 -0300 Subject: [PATCH 4/6] [FIX] Fixing 'where' of the base query --- src/libs/routes_v1/courseAggregate.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/routes_v1/courseAggregate.js b/src/libs/routes_v1/courseAggregate.js index b9dc7f61..5ec2a3cb 100644 --- a/src/libs/routes_v1/courseAggregate.js +++ b/src/libs/routes_v1/courseAggregate.js @@ -402,6 +402,7 @@ CourseAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { req.sql.from('curso_superior_agregado') .field('count(distinct(cod_curso))', 'total') .field('curso_superior_agregado.ano_censo', 'year') + .where('curso_superior_agregado.tp_nivel_acad = 1 AND qtd_cursos = 1') .group('curso_superior_agregado.ano_censo') .order('curso_superior_agregado.ano_censo') console.log(req.sql.toString()) -- GitLab From c965932fb5948165ceaaf6931764cd4eec0babf5 Mon Sep 17 00:00:00 2001 From: fgs21 <fgs21@inf.ufpr.br> Date: Thu, 12 Sep 2024 09:37:57 -0300 Subject: [PATCH 5/6] [FIX] Fixing /course_aggregate/university query --- src/libs/routes_v1/courseAggregate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/routes_v1/courseAggregate.js b/src/libs/routes_v1/courseAggregate.js index 5ec2a3cb..dbfb002f 100644 --- a/src/libs/routes_v1/courseAggregate.js +++ b/src/libs/routes_v1/courseAggregate.js @@ -193,7 +193,7 @@ CourseAggregateApp.get('/cine_detailed', (req, res, next) => { CourseAggregateApp.get('/university', (req, res, next) => { req.sql.from('curso_superior_agregado') .field('DISTINCT curso_superior_agregado.cod_ies', 'cod') - .field('ies_ens_superior.cod_ies', 'nome') + .field('ies_ens_superior.nome_ies', 'nome') .join('ies_ens_superior', null, 'curso_superior_agregado.cod_ies = ies_ens_superior.cod_ies and curso_superior_agregado.ano_censo = ies_ens_superior.ano_censo') next(); }, query, response('university')); -- GitLab From 2e905451cf7003030c9178cc31c7e8b3715265bf Mon Sep 17 00:00:00 2001 From: fgs21 <fgs21@inf.ufpr.br> Date: Fri, 13 Sep 2024 11:20:07 -0300 Subject: [PATCH 6/6] [FIX] Region filter column name fixed --- src/libs/routes_v1/courseAggregate.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/routes_v1/courseAggregate.js b/src/libs/routes_v1/courseAggregate.js index dbfb002f..01773c05 100644 --- a/src/libs/routes_v1/courseAggregate.js +++ b/src/libs/routes_v1/courseAggregate.js @@ -343,12 +343,12 @@ rqf.addField({ }).addValue({ name: 'region', table: 'curso_superior_agregado', - tableField: 'cod_regiao', + tableField: 'cod_reg', resultField: 'region_id', where: { relation: '=', type: 'integer', - field: 'cod_regiao' + field: 'cod_reg' } }).addValue({ name: 'metro_code', -- GitLab