From 2ba2642d8c90059ed9738d4b808712b85e4fc25c Mon Sep 17 00:00:00 2001 From: Joao Pedro <jpv.ramalho2013@gmail.com> Date: Mon, 10 Mar 2025 11:53:05 -0300 Subject: [PATCH 01/45] [ADD] indicador despesas --- docker-compose.yml | 11 ++ entrypoint.sh | 5 + gulpfile.babel.js | 22 ++-- gulpfile.template.js | 20 ++++ src/libs/convert/expenses.js | 41 +++++++ src/libs/middlewares/aggregateData.js | 10 +- src/libs/middlewares/expensesParser.js | 23 ++++ src/libs/middlewares/id2str.js | 7 +- src/libs/routes_v1/api.js | 7 +- src/libs/routes_v1/expenses.js | 148 +++++++++++++++++++++++++ 10 files changed, 274 insertions(+), 20 deletions(-) create mode 100644 docker-compose.yml create mode 100644 entrypoint.sh create mode 100644 gulpfile.template.js create mode 100644 src/libs/convert/expenses.js create mode 100644 src/libs/middlewares/expensesParser.js create mode 100644 src/libs/routes_v1/expenses.js diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..85266ff9 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +services: + simcaq-node: + container_name: simcaq-node + build: . + ports: + - '3000:3000' + develop: + watch: + - action: sync + path: . + target: /API diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 00000000..04db5192 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/bash +echo "Starting simcaq-node" +gulp watch &> /dev/null & +cd build +NODE_ENV=production gulp run diff --git a/gulpfile.babel.js b/gulpfile.babel.js index c661d5af..1d0724e1 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -43,12 +43,12 @@ gulp.task('compile', ['lint'], () => { gulp.src('src/**/*.js') .pipe(cache.filter()) // cache source files .pipe(babel()) // compile only modified files - // .pipe(cache.cache()) // cache compiled files + .pipe(cache.cache()) // cache compiled files .pipe(gulp.dest('build')); // move compiled files to build directory }); gulp.task('build', ['compile'], () => { - var filesToCopy = [ 'config.json', 'package.json' ]; + var filesToCopy = [ 'config.json', 'package.json', '.eslintignore', '.eslintrc.json' ]; // copy configuration file to build directory gulp.src(filesToCopy) .pipe(gulp.dest('build')); @@ -93,24 +93,16 @@ gulp.task('test', ['pre-test'], () => { }); }); -gulp.task('watch', ['compile'], () => { +gulp.task('watch', () => { console.log('Watching source directory for changes'); - gulp.watch('src/**/*.js').on('change', () => { + return gulp.watch('src/**/*.js').on('change', () => { console.log('Recompiling source'); gulp.start('compile'); console.log('Source recompilation done'); }); }); -gulp.task('run', () => { - process.chdir('build'); - nodemon({ - script: 'server.js', - tasks: ['watch'], - ignore: ["test/test.js", "gulpfile.babel.js"], - ext: 'js html json', - env: { 'NODE_ENV': process.env.NODE_ENV } - }); +gulp.task('default', () => { + console.log("Não execuatar apenas gulp, execute da forma:"); + console.log("\t\tgulp <task>"); }); - -gulp.task('default', ['run']); diff --git a/gulpfile.template.js b/gulpfile.template.js new file mode 100644 index 00000000..3de679df --- /dev/null +++ b/gulpfile.template.js @@ -0,0 +1,20 @@ +const gulp = require('gulp'); + +const nodemon = require('gulp-nodemon'); + +gulp.task('run', () => { + // process.chdir('build'); + nodemon({ + script: 'server.js', + // tasks: ['watch'], + ignore: ["test/test.js", "gulpfile.babel.js"], + ext: 'js html json', + env: { 'NODE_ENV': process.env.NODE_ENV } + }); +}); + +gulp.task('default', () => { + console.log("Não execuatar apenas gulp, execute da forma:"); + console.log("\t\tgulp <task>"); +}); + diff --git a/src/libs/convert/expenses.js b/src/libs/convert/expenses.js new file mode 100644 index 00000000..82bf080b --- /dev/null +++ b/src/libs/convert/expenses.js @@ -0,0 +1,41 @@ +/* +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/>. +*/ + +module.exports = function regionCode(id) { + switch (id) { + case 1: + return "Nome Ente" + case 2: + return 'Despesas'; + case 3: + return 'Matrículas Públicas'; + case 4: + return 'Matrículas Públicas Mais Conveniada'; + case 5: + return 'Despesas Aluno Ano Pública' + case 6: + return 'Despesas Aluno Mês Pública'; + case 7: + return 'Despesas Aluno Ano Pública Mais Conveniada'; + case 8: + return 'Despesas Aluno Mês Pública Mais Conveniada'; + } +}; + diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js index eed373dd..a4429af8 100644 --- a/src/libs/middlewares/aggregateData.js +++ b/src/libs/middlewares/aggregateData.js @@ -35,10 +35,12 @@ const convert = { contract_type_entity: 'contractType', total_doc: "totalDoc", education_degree_entity: "educationDegreeEntity", - government_agreement: "governmentAgreement" + government_agreement: "governmentAgreement", + despesas_alunos: "expenses" } function aggregateData(req, res, next) { + console.log("Teste if agg"); if (req.query.dims) { const newResult = [] const aggregateFields = [ @@ -62,7 +64,8 @@ function aggregateData(req, res, next) { 'age_range_entity', 'post_graduation_entity', 'contract_type_entity', - 'education_degree_entity' + 'education_degree_entity', + 'despesas_alunos' ] let id; const fields = req.query.dims.split(','); @@ -70,9 +73,12 @@ function aggregateData(req, res, next) { let currentNonAggregateField; // Verifica se o filtro passado está presente nos filtros agregados + console.log("fields:"); + console.log(fields); fields.forEach(field => {if (aggregateFields.includes(field)) currentAggregateField = field; else currentNonAggregateField = field}); if (currentAggregateField) { req.result.forEach((r) => { + console.log("aggregate data aaa"); // Alguns filtros começam com o id = 0 outros id = 1 id = ['ethnic_group', 'integral_time_agg'].includes(currentAggregateField) ? 0 : 1; for (const property in r) { diff --git a/src/libs/middlewares/expensesParser.js b/src/libs/middlewares/expensesParser.js new file mode 100644 index 00000000..a791f1e3 --- /dev/null +++ b/src/libs/middlewares/expensesParser.js @@ -0,0 +1,23 @@ +/* +Middleware que remove o campo "region" quando o campo "city" está ativo nos filtros. +Devido à limitações na tabela de dados, quando ambos campos estão ativos o filtro por +"região" funciona incorretamente. +*/ +module.exports = function expensesParser(req, res, next) { + console.log(req.query); + + if (req.query && req.query.filter) { + const jsonString = `{${req.query.filter.replace(/(\w+):/g, '"$1":')}}`; + const obj = JSON.parse(jsonString); + + if ("city" in obj && "region" in obj) { + delete obj.region; + const customString = Object.entries(obj) + .map(([key, value]) => `${key}:"${value}"`) + .join(','); + req.query.filter = customString; + } + } + + next(); +}; diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index f366d90a..324511a7 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -126,6 +126,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 expenses = require(`${libs}/convert/expenses.js`) const ids = { gender_id: gender, @@ -244,7 +245,8 @@ const ids = { post_graduation_entity: postGraduationEntity, special_education_entity: specialEducationEntity, total_doc: totalDoc, - education_degree_entity: educationDegreeEntity + education_degree_entity: educationDegreeEntity, + despesas_id: expenses }; function transform(removeId=false) { @@ -385,5 +387,6 @@ module.exports = { postGraduationEntity, specialEducationEntity, totalDoc, - educationDegreeEntity + educationDegreeEntity, + expenses }; diff --git a/src/libs/routes_v1/api.js b/src/libs/routes_v1/api.js index bffc8b5d..494d13c8 100644 --- a/src/libs/routes_v1/api.js +++ b/src/libs/routes_v1/api.js @@ -157,6 +157,11 @@ const email = require(`${libs}/routes_v1/email`); const uniLocalOfferAggregate = require(`${libs}/routes_v1/uniLocalOfferAggregate`) +const expenses = require(`${libs}/routes_v1/expenses`) + +const expensesParser = require(`${libs}/middlewares/expensesParser`); + + api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API v1 is running' }); }); @@ -223,7 +228,7 @@ api.use('/employeesAggregate', employeesAggregate); api.use('/course_aggregate', courseAggregate); api.use('/federativeEntity', federativeEntity); api.use('/uni_offer_aggregate', uniLocalOfferAggregate); - +api.use('/expenses', expensesParser, expenses); //Publication api.use('/publication', publication); diff --git a/src/libs/routes_v1/expenses.js b/src/libs/routes_v1/expenses.js new file mode 100644 index 00000000..b860673e --- /dev/null +++ b/src/libs/routes_v1/expenses.js @@ -0,0 +1,148 @@ +/* +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 ExpensesApp = 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; + +const aggregateData = require(`${libs}/middlewares/aggregateData`); + +let rqf = new ReqQueryFields(); + +ExpensesApp.use(cache('15 day')); + +ExpensesApp.get('/years', (req, res, next) => { + req.sql.from('despesas') + .field('DISTINCT despesas.ano_censo', 'year') + .where('despesas.ano_censo is not null') + next(); +}, query, response('years')) + +// rqf.addValue({ +// name: 'location', +// table: 'despesas', +// tableField: 'nome_ente', +// resultField: 'location_id', +// where: { +// relation: '=', +// type: 'integer', +// field: 'localizacao_id' +// } +// }); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'min_year', + table: 'despesas', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'max_year', + table: 'despesas', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'region', + table: 'estado', + tableField: ['nome_ente', 'cod_ibge', 'id', 'regiao_id'], + resultField: ['state_name', 'state_cod_ibge', 'state_id', 'region_id'], + where: { + relation: '=', + type: 'integer', + field: 'regiao_id', + }, + join: { + primary: 'id', + foreign: 'cod_ibge', + foreignTable: 'despesas' + } +}) + + +ExpensesApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + + if (req.query.dims && req.query.dims.includes('despesas')) { + let whereCondition = req.query.filter.includes("region") ? "" : "despesas.cod_ibge = 0"; + let filterId; + const filters = req.query.filter.split(","); + filters.forEach((filter) => { + if (filter.includes("state") || filter.includes("city")) { + filterId = Number(filter.split(":")[1].replace(/"/g, "")); + whereCondition = `despesas.cod_ibge = ${filterId}` + } + }) + + console.log("Filtro 2"); + console.log(filters); + + req.sql.from('despesas') + .field('despesas.ano_censo', 'year') + .field('despesas.nome_ente', 'total_nome_ente') + .field('despesas.despesas', 'total_despesas') + .field('matriculas_publica', 'total_matriculas_publica') + .field('matriculas_publicas_mais_conveniada', 'total_matriculas_publicas_mais_conveniada') + .field('gasto_aluno_ano_publica', 'total_gasto_aluno_ano_publica') + .field('gasto_aluno_mes_publica', 'total_gasto_aluno_mes_publica') + .field('gasto_aluno_ano_publica_mais_conveniada', 'total_gasto_aluno_ano_publica_mais_conveniada') + .field('gasto_aluno_mes_publica_mais_conveniada', 'total_gasto_aluno_mes_publica_mais_conveniada') + .where(`${whereCondition}`) + .order('despesas.cod_ibge') + } + + console.log("Requisição !") + console.log(req.query) + + next(); +}, query, aggregateData, id2str.transform(false), response('expenses')); + +module.exports = ExpensesApp; \ No newline at end of file -- GitLab From 34e4b51b897b98437013dc023018a406de3279c4 Mon Sep 17 00:00:00 2001 From: Lewis <lgtg20@inf.ufpr.br> Date: Tue, 18 Mar 2025 10:48:02 -0300 Subject: [PATCH 02/45] feat: add age range conversion for 19 to 64 years and update related routes --- src/libs/convert/ageRange19to64.js | 38 +++++++++++++++++++ src/libs/middlewares/id2str.js | 8 ++-- .../routes_v1/basicEducationConclusion.js | 12 +++--- 3 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 src/libs/convert/ageRange19to64.js diff --git a/src/libs/convert/ageRange19to64.js b/src/libs/convert/ageRange19to64.js new file mode 100644 index 00000000..47020867 --- /dev/null +++ b/src/libs/convert/ageRange19to64.js @@ -0,0 +1,38 @@ +/* +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 ageRange19to64(id) { + switch (id) { + case 6: + return '19 a 24 anos'; + case 7: + return '25 a 29 anos'; + case 8: + return '30 a 40 anos'; + case 9: + return '41 a 50 anos'; + case 10: + return '51 a 64 anos'; + case 11: + return 'Mais que 64 anos'; + default: + return 'Não declarada'; + } +}; diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index 730d620e..e144fb97 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -128,6 +128,7 @@ const totalDoc = require(`${libs}/convert/totalDoc`); const educationDegreeEntity = require(`${libs}/convert/educationDegreeEntity`); const revenue = require(`${libs}/convert/revenue`); const studentCost = require(`${libs}/convert/studentCost`); +const ageRange19to64 = require(`${libs}/convert/ageRange19to64`); const ids = { gender_id: gender, @@ -248,7 +249,8 @@ const ids = { total_doc: totalDoc, education_degree_entity: educationDegreeEntity, receitas_id: revenue, - student_cost: studentCost + student_cost: studentCost, + age_range_19_to_64_id: ageRange19to64 }; function transform(removeId=false) { @@ -258,7 +260,6 @@ function transform(removeId=false) { } // Para cada objeto do resultado req.result.forEach((obj) => { - console.log(obj), Object.keys(obj).forEach((key) => { // Se não há uma função especificada, retorna if(typeof ids[key] === 'undefined') return; @@ -392,5 +393,6 @@ module.exports = { totalDoc, educationDegreeEntity, revenue, - studentCost + studentCost, + ageRange19to64 }; diff --git a/src/libs/routes_v1/basicEducationConclusion.js b/src/libs/routes_v1/basicEducationConclusion.js index fb745299..0d84822c 100644 --- a/src/libs/routes_v1/basicEducationConclusion.js +++ b/src/libs/routes_v1/basicEducationConclusion.js @@ -242,16 +242,16 @@ basicEducationConclusion.get('/state', (req, res, next) => { next(); }, response('state')); -basicEducationConclusion.get('/age_range_all', (req, res, next) => { +basicEducationConclusion.get('/age_range_19_to_64', (req, res, next) => { req.result = [] - for (let i = 1; i < 12; i++) { + for (let i = 6; i <= 11; i++) { req.result.push({ - id: i, name: id2str.ageRangeAll(i) + id: i, name: id2str.ageRange19to64(i) }); } next(); -}, response('age_range_all')); +}, response('age_range_19_to_64')); basicEducationConclusion.get('/location', (req, res, next) => { req.result = [] @@ -414,10 +414,10 @@ rqf.addField({ field: 'cor_raca' } }).addValue({ - name: 'age_range_all', + name: 'age_range_19_to_64', table: 'pnad_novo', tableField: 'faixa_etaria', - resultField: 'age_range_all_id', + resultField: 'age_range_19_to_64_id', where: { relation: '=', type: 'integer', -- GitLab From cbd00f501832a3b8d307f6baeae2aea2a1cf5eed Mon Sep 17 00:00:00 2001 From: Lewis <lgtg20@inf.ufpr.br> Date: Tue, 18 Mar 2025 11:31:46 -0300 Subject: [PATCH 03/45] fix: remove hardcoded capital code and adjust query conditions for cap_code dimension --- src/libs/routes_v1/basicEducationConclusion.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libs/routes_v1/basicEducationConclusion.js b/src/libs/routes_v1/basicEducationConclusion.js index 0d84822c..a30c3afd 100644 --- a/src/libs/routes_v1/basicEducationConclusion.js +++ b/src/libs/routes_v1/basicEducationConclusion.js @@ -120,7 +120,6 @@ basicEducationConclusion.get('/cap_code', (req, res, next) => { }); } } - req.result.push({id: 99, name: id2str.capitalCode(99)}); next(); }, response('cap_code')); @@ -604,6 +603,10 @@ basicEducationConclusion.get('/', rqf.parse(), rqf.build(), (req, res, next) => totalPopEdBasMaior19.where("faixa_rendimento_aux_tx is not null"); } + if (req.query.dims && req.query.dims.includes("cap_code")) { + totalPopMaior19.where("cod_cap < 99"); + } + req.querySet.push(totalPopEdBasMaior19); req.querySet.push(totalPopMaior19); -- GitLab From 4b0c6191a435fb9837980dea4947f4da571db16b Mon Sep 17 00:00:00 2001 From: Joao Pedro <jpv.ramalho2013@gmail.com> Date: Tue, 18 Mar 2025 11:38:56 -0300 Subject: [PATCH 04/45] =?UTF-8?q?[mod]=20remo=C3=A7=C3=A3o=20de=20console.?= =?UTF-8?q?log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libs/convert/expenses.js | 18 ++++++++++-------- src/libs/middlewares/expensesParser.js | 2 -- src/libs/routes_v1/expenses.js | 9 ++------- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/libs/convert/expenses.js b/src/libs/convert/expenses.js index 82bf080b..5cd28c4e 100644 --- a/src/libs/convert/expenses.js +++ b/src/libs/convert/expenses.js @@ -21,21 +21,23 @@ along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. module.exports = function regionCode(id) { switch (id) { case 1: - return "Nome Ente" + return "Ano"; case 2: - return 'Despesas'; + return "Entidade"; case 3: - return 'Matrículas Públicas'; + return 'Despesas'; case 4: - return 'Matrículas Públicas Mais Conveniada'; + return 'Matrículas Públicas'; case 5: - return 'Despesas Aluno Ano Pública' + return 'Matrículas Públicas Mais Conveniada'; case 6: - return 'Despesas Aluno Mês Pública'; + return 'Despesas Aluno Ano Pública' case 7: - return 'Despesas Aluno Ano Pública Mais Conveniada'; + return 'Despesas Aluno Mês Pública'; case 8: - return 'Despesas Aluno Mês Pública Mais Conveniada'; + return 'Despesas Aluno Ano Pública Mais Conveniada'; + case 9: + return 'Despesas Aluno Mês Pública Mais Conveniada'; } }; diff --git a/src/libs/middlewares/expensesParser.js b/src/libs/middlewares/expensesParser.js index a791f1e3..5ba0c8eb 100644 --- a/src/libs/middlewares/expensesParser.js +++ b/src/libs/middlewares/expensesParser.js @@ -4,8 +4,6 @@ Devido à limitações na tabela de dados, quando ambos campos estão ativos o f "região" funciona incorretamente. */ module.exports = function expensesParser(req, res, next) { - console.log(req.query); - if (req.query && req.query.filter) { const jsonString = `{${req.query.filter.replace(/(\w+):/g, '"$1":')}}`; const obj = JSON.parse(jsonString); diff --git a/src/libs/routes_v1/expenses.js b/src/libs/routes_v1/expenses.js index b860673e..36248659 100644 --- a/src/libs/routes_v1/expenses.js +++ b/src/libs/routes_v1/expenses.js @@ -122,11 +122,9 @@ ExpensesApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { } }) - console.log("Filtro 2"); - console.log(filters); - req.sql.from('despesas') .field('despesas.ano_censo', 'year') + .field('despesas.ano_censo', 'total_ano') .field('despesas.nome_ente', 'total_nome_ente') .field('despesas.despesas', 'total_despesas') .field('matriculas_publica', 'total_matriculas_publica') @@ -136,12 +134,9 @@ ExpensesApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .field('gasto_aluno_ano_publica_mais_conveniada', 'total_gasto_aluno_ano_publica_mais_conveniada') .field('gasto_aluno_mes_publica_mais_conveniada', 'total_gasto_aluno_mes_publica_mais_conveniada') .where(`${whereCondition}`) - .order('despesas.cod_ibge') + .order('despesas.ano_censo') } - console.log("Requisição !") - console.log(req.query) - next(); }, query, aggregateData, id2str.transform(false), response('expenses')); -- GitLab From 22690a1e8fd5d64d2a745d6b8a9fd5b50ec570db Mon Sep 17 00:00:00 2001 From: Lewis <lgtg20@inf.ufpr.br> Date: Thu, 20 Mar 2025 10:22:50 -0300 Subject: [PATCH 05/45] fix: update income_range id and income_range variable pulled from db --- .../routes_v1/basicEducationConclusion.js | 81 +++++++++---------- 1 file changed, 38 insertions(+), 43 deletions(-) diff --git a/src/libs/routes_v1/basicEducationConclusion.js b/src/libs/routes_v1/basicEducationConclusion.js index a30c3afd..3b22f4d3 100644 --- a/src/libs/routes_v1/basicEducationConclusion.js +++ b/src/libs/routes_v1/basicEducationConclusion.js @@ -36,9 +36,9 @@ const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); const id2str = require(`${libs}/middlewares/id2str`); -const config = require(`${libs}/config`); +const config = require(`${libs}/config`); -const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware; +const cache = require('apicache').options({ debug: config.debug, statusCodes: { include: [200] } }).middleware; let rqf = new ReqQueryFields(); @@ -46,8 +46,8 @@ basicEducationConclusion.use(cache('15 day')); basicEducationConclusion.get('/years', (req, res, next) => { req.sql.from('pnad_novo') - .field('DISTINCT pnad_novo.ano_ref', 'year') - .where('pnad_novo.ano_ref >= 2019') + .field('DISTINCT pnad_novo.ano_ref', 'year') + .where('pnad_novo.ano_ref >= 2019') next(); }, query, response('years')); @@ -60,7 +60,7 @@ basicEducationConclusion.get('/illiteracy', (req, res, next) => { }); } - req.result.push({id: 9, name: id2str.illiteracy(9)}); + req.result.push({ id: 9, name: id2str.illiteracy(9) }); next(); }, response('illiteracy')); @@ -73,7 +73,7 @@ basicEducationConclusion.get('/years_of_study', (req, res, next) => { }); } - req.result.push({id: 99, name: id2str.yearsOfStudy(99)}); + req.result.push({ id: 99, name: id2str.yearsOfStudy(99) }); next(); }, response('years_of_study')); @@ -85,7 +85,7 @@ basicEducationConclusion.get('/instruction_level', (req, res, next) => { id: i, name: id2str.instructionLevel(i) }); } - req.result.push({id: 99, name: id2str.instructionLevel(99)}); + req.result.push({ id: 99, name: id2str.instructionLevel(99) }); next(); }, response('instruction_level')); @@ -96,7 +96,7 @@ basicEducationConclusion.get('/new_pnad_adm_dependency', (req, res, next) => { id: i, name: id2str.newPnadAdmDependency(i) }); } - req.result.push({id: 99, name: id2str.newPnadAdmDependency(99)}); + req.result.push({ id: 99, name: id2str.newPnadAdmDependency(99) }); next(); }, response('new_pnad_adm_dependency')); @@ -115,9 +115,9 @@ basicEducationConclusion.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: i, name: id2str.capitalCode(i) + }); } } @@ -128,12 +128,12 @@ basicEducationConclusion.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: i, name: id2str.metroCode(i) + }); } } - req.result.push({id: 99, name: id2str.metroCode(99)}); + req.result.push({ id: 99, name: id2str.metroCode(99) }); next(); }, response('metro_code')); @@ -147,7 +147,7 @@ basicEducationConclusion.get('/attended_modality', (req, res, next) => { } // 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)}); + req.result.push({ id: 99, name: id2str.attendedModality(99) }); next(); }, response('attended_modality')); @@ -158,7 +158,7 @@ basicEducationConclusion.get('/income_range', (req, res, next) => { id: i, name: id2str.incomeRange(i) }); } - req.result.push({id: 10, name: id2str.incomeRange(10)}); + req.result.push({ id: 9, name: id2str.incomeRange(9) }); next(); }, response('income_range')); @@ -189,7 +189,7 @@ basicEducationConclusion.get('/new_pnad_ethnic_group', (req, res, next) => { id: i, name: id2str.ethnicGroupNewPnad(i) }); } - req.result.push({id: 9, name: id2str.ethnicGroupNewPnad(9)}); + req.result.push({ id: 9, name: id2str.ethnicGroupNewPnad(9) }); next(); }, response('new_pnad_ethnic_group')); @@ -200,7 +200,7 @@ basicEducationConclusion.get('/bolsa_familia', (req, res, next) => { id: i, name: id2str.attendsSchool(i) }); } - req.result.push({id: 9, name: id2str.attendsSchool(9)}); + req.result.push({ id: 9, name: id2str.attendsSchool(9) }); next(); }, response('bolsa_familia')); @@ -211,7 +211,7 @@ basicEducationConclusion.get('/modality', (req, res, next) => { id: i, name: id2str.modality(i) }); } - req.result.push({id: 99, name: id2str.modality(99)}); + req.result.push({ id: 99, name: id2str.modality(99) }); next(); }, response('modality')); @@ -222,8 +222,8 @@ basicEducationConclusion.get('/modality_shift', (req, res, next) => { id: i, name: id2str.modalityShift(i) }); } - req.result.push({id: 9, name: id2str.modalityShift(9)}); - req.result.push({id: 99, name: id2str.modalityShift(99)}); + req.result.push({ id: 9, name: id2str.modalityShift(9) }); + req.result.push({ id: 99, name: id2str.modalityShift(99) }); next(); }, response('modality_shift')); @@ -236,7 +236,7 @@ basicEducationConclusion.get('/state', (req, res, next) => { }); } } - req.result.push({id: 99, name: id2str.stateName(99)}); + req.result.push({ id: 99, name: id2str.stateName(99) }); next(); }, response('state')); @@ -425,12 +425,12 @@ rqf.addField({ }).addValue({ name: 'income_range', table: 'pnad_novo', - tableField: 'faixa_rendimento_aux_tx', + tableField: 'faixa_rendimento_aux', resultField: 'income_range_id', where: { relation: '=', type: 'integer', - field: 'faixa_rendimento_aux_tx' + field: 'faixa_rendimento_aux' } }).addValue({ name: 'gender', @@ -544,26 +544,26 @@ function matchQueries(queryPartial, queryTotal) { newObj[key] = result[key]; }); let index = keys.indexOf('total'); - if(index > -1) keys.splice(index, 1); + if (index > -1) keys.splice(index, 1); let objMatch = null; - for(let i = 0; i < queryPartial.length; ++i) { + for (let i = 0; i < queryPartial.length; ++i) { let partial = queryPartial[i]; let foundMatch = true; - for(let j = 0; j < keys.length; ++j) { + for (let j = 0; j < keys.length; ++j) { let key = keys[j]; - if(partial[key] !== result[key]) { + if (partial[key] !== result[key]) { foundMatch = false; break; } } - if(foundMatch) { + if (foundMatch) { objMatch = partial; break; } } - if(objMatch) { + if (objMatch) { newObj.denominator = result.total; newObj.partial = objMatch.total; newObj.total = (objMatch.total / result.total) * 100; @@ -576,10 +576,10 @@ function matchQueries(queryPartial, queryTotal) { basicEducationConclusion.get('/', rqf.parse(), rqf.build(), (req, res, next) => { req.querySet = []; - + // Subquery para total_pop_maior_19 com filtros dinâmicos let totalPopMaior19 = req.sql.clone(); - totalPopMaior19.from("pnad_novo") + totalPopMaior19.from("pnad_novo") .field("ano_ref", "year") .field("SUM(peso_domicilio_pessoas_com_cal)", "total") .where("idade_morador_31_03 >= 19") @@ -589,7 +589,7 @@ basicEducationConclusion.get('/', rqf.parse(), rqf.build(), (req, res, next) => // Subquery para total_pop_ed_bas_maior_19 com filtros dinâmicos let totalPopEdBasMaior19 = req.sql.clone(); - totalPopEdBasMaior19.from("pnad_novo") + totalPopEdBasMaior19.from("pnad_novo") .field("ano_ref", "year") .field("SUM(peso_domicilio_pessoas_com_cal)", "total") .where("idade_morador_31_03 >= 19") @@ -598,11 +598,6 @@ basicEducationConclusion.get('/', rqf.parse(), rqf.build(), (req, res, next) => .group("ano_ref") .order("ano_ref"); - if (req.query.dims && req.query.dims.includes("income_range")) { - totalPopMaior19.where("faixa_rendimento_aux_tx is not null"); - totalPopEdBasMaior19.where("faixa_rendimento_aux_tx is not null"); - } - if (req.query.dims && req.query.dims.includes("cap_code")) { totalPopMaior19.where("cod_cap < 99"); } @@ -612,10 +607,10 @@ basicEducationConclusion.get('/', rqf.parse(), rqf.build(), (req, res, next) => next(); }, multiQuery, (req, res, next) => { - // The multiple requests are made. Then we need to calculate the percetange. So the function - // below is used - let newObj = matchQueries(req.result[0], req.result[1]); - req.result = newObj; + // The multiple requests are made. Then we need to calculate the percetange. So the function + // below is used + let newObj = matchQueries(req.result[0], req.result[1]); + req.result = newObj; next(); }, id2str.transform(false), response('basic_education_conclusion')); -- GitLab From 07cad15f7de076317d6bf05d8ce0ae5a1171c56f Mon Sep 17 00:00:00 2001 From: Lewis <lgtg20@inf.ufpr.br> Date: Fri, 21 Mar 2025 11:10:55 -0300 Subject: [PATCH 06/45] feat: add cap_code and metro_code endpoints; update income_range field reference --- src/libs/routes_v1/adjustedLiquidFrequency.js | 62 ++++++++++++++++++- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/src/libs/routes_v1/adjustedLiquidFrequency.js b/src/libs/routes_v1/adjustedLiquidFrequency.js index 5b79740d..0be735c8 100644 --- a/src/libs/routes_v1/adjustedLiquidFrequency.js +++ b/src/libs/routes_v1/adjustedLiquidFrequency.js @@ -62,6 +62,34 @@ adjustedLiquidFrequency.get('/income_range', (req, res, next) => { next(); }, response('income_range')); +adjustedLiquidFrequency.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')); + +adjustedLiquidFrequency.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')); + adjustedLiquidFrequency.get('/gender', (req, res, next) => { req.result = [] for (let i = 1; i < 3; i++) { @@ -152,6 +180,16 @@ rqf.addField({ foreign: 'cod_uf', foreignTable: 'pnad_novo' } +}).addValue({ + name: 'cap_code', + table: 'pnad_novo', + tableField: 'cod_cap', + resultField: 'cap_code_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_cap' + } }).addValue({ name: 'bolsa_familia', table: 'pnad_novo', @@ -175,12 +213,12 @@ rqf.addField({ }).addValue({ name: 'income_range', table: 'pnad_novo', - tableField: 'faixa_rendimento_aux_tx', + tableField: 'faixa_rendimento_aux', resultField: 'income_range_id', where: { relation: '=', type: 'integer', - field: 'faixa_rendimento_aux_tx' + field: 'faixa_rendimento_aux' } }).addValue({ name: 'age_range_all', @@ -202,6 +240,16 @@ rqf.addField({ type: 'integer', field: 'sexo' } +}).addValue({ + name: 'metro_code', + table: 'pnad_novo', + tableField: 'cod_rm_ride', + resultField: 'metro_code_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_rm_ride' + } }).addValue({ name: 'region', table: 'pnad_novo', @@ -293,7 +341,9 @@ adjustedLiquidFrequency.get('/', rqf.parse(), (req, res, next) => { ${dimensions.gender ? " AND total_pop.gender_id = pnad_novo.sexo" : ""} ${dimensions.bolsa_familia ? "AND total_pop.bolsa_familia_id = pnad_novo.recebeu_rendimentos_de_programa_bolsa_familia" : ""} ${dimensions.new_pnad_ethnic_group ? "AND total_pop.new_pnad_ethnic_group_id = pnad_novo.cor_raca" : ""} - ${dimensions.income_range ? "AND total_pop.income_range_id = pnad_novo.faixa_rendimento_aux_tx" : ""} + ${dimensions.income_range ? "AND total_pop.income_range_id = pnad_novo.faixa_rendimento_aux" : ""} + ${dimensions.cap_code ? "AND total_pop.cap_code_id = pnad_novo.cod_cap" : ""} + ${dimensions.metro_code ? "AND pnad_novo.cod_rm_ride <> 99 AND total_pop.metro_code_id = pnad_novo.cod_rm_ride" : ""} ` // Subquery: total_apoio_freq @@ -337,6 +387,12 @@ adjustedLiquidFrequency.get('/', rqf.parse(), (req, res, next) => { if (dimensions.income_range) mainQuery.field("total_apoio_freq.income_range_id") + if (dimensions.cap_code) + mainQuery.field("total_apoio_freq.cap_code_id") + + if (dimensions.metro_code) + mainQuery.field("total_apoio_freq.metro_code_id") + req.sql = mainQuery; next(); -- GitLab From 6e60258cd671c69d95a19b3927951a2e9fcddb06 Mon Sep 17 00:00:00 2001 From: Lewis <lgtg20@inf.ufpr.br> Date: Thu, 27 Mar 2025 10:26:34 -0300 Subject: [PATCH 07/45] fix: update revenue labels and clean up console logs; add type endpoint to studentRevenue --- .gitignore | 1 + src/libs/convert/revenue.js | 18 ++----- src/libs/middlewares/aggregateData.js | 4 -- src/libs/routes_v1/activity.js | 1 - src/libs/routes_v1/studentRevenue.js | 71 ++++++++++++++++++++------- 5 files changed, 58 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index 2fa21185..780dbd8f 100644 --- a/.gitignore +++ b/.gitignore @@ -30,5 +30,6 @@ DockerfileAntigo src/libs/db/postgres.js docker-compose.yml entrypoint.sh +gulpfile* gulpfile.template.js diff --git a/src/libs/convert/revenue.js b/src/libs/convert/revenue.js index 18cfeb8c..006e2662 100644 --- a/src/libs/convert/revenue.js +++ b/src/libs/convert/revenue.js @@ -21,22 +21,14 @@ along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. module.exports = function regionCode(id) { switch (id) { case 1: - return "Ano"; + return 'Receitas'; case 2: - return "Nome Ente" + return 'Rede pública (anual)' case 3: - return 'Receitas'; + return 'Rede pública (mensal)'; case 4: - return 'Matrículas Públicas'; + return 'Rede pública e conveniada (anual)'; case 5: - return 'Matrículas Públicas Mais Conveniada'; - case 6: - return 'Receita Aluno Ano Pública' - case 7: - return 'Receita Aluno Mês Pública'; - case 8: - return 'Receita Aluno Ano Pública Mais Conveniada'; - case 9: - return 'Receita Aluno Mês Pública Mais Conveniada'; + return 'Rede pública e conveniada (mensal)'; } }; diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js index fccb7453..e004f653 100644 --- a/src/libs/middlewares/aggregateData.js +++ b/src/libs/middlewares/aggregateData.js @@ -42,7 +42,6 @@ const convert = { } function aggregateData(req, res, next) { - console.log("Teste if agg"); if (req.query.dims) { const newResult = [] const aggregateFields = [ @@ -78,12 +77,9 @@ function aggregateData(req, res, next) { let currentNonAggregateField; // Verifica se o filtro passado está presente nos filtros agregados - console.log("fields:"); - console.log(fields); fields.forEach(field => {if (aggregateFields.includes(field)) currentAggregateField = field; else currentNonAggregateField = field}); if (currentAggregateField) { req.result.forEach((r) => { - console.log("aggregate data aaa"); // Alguns filtros começam com o id = 0 outros id = 1 id = ['ethnic_group', 'integral_time_agg'].includes(currentAggregateField) ? 0 : 1; for (const property in r) { diff --git a/src/libs/routes_v1/activity.js b/src/libs/routes_v1/activity.js index cb35c2de..1cc63016 100644 --- a/src/libs/routes_v1/activity.js +++ b/src/libs/routes_v1/activity.js @@ -199,7 +199,6 @@ activityApp.put('/:id', passport.authenticate('bearer', { session: false }), aut } }); } - console.log("TEste"); act.type = req.body.tipo || act.type; act.title = req.body.titulo || act.title; act.subtitle = req.body.subtitulo || act.subtitle; diff --git a/src/libs/routes_v1/studentRevenue.js b/src/libs/routes_v1/studentRevenue.js index b595fb00..17da5f27 100644 --- a/src/libs/routes_v1/studentRevenue.js +++ b/src/libs/routes_v1/studentRevenue.js @@ -36,9 +36,9 @@ const aggregateData = require(`${libs}/middlewares/aggregateData`); const id2str = require(`${libs}/middlewares/id2str`); -const config = require(`${libs}/config`); +const config = require(`${libs}/config`); -const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware; +const cache = require('apicache').options({ debug: config.debug, statusCodes: { include: [200] } }).middleware; let rqf = new ReqQueryFields(); @@ -46,11 +46,19 @@ studentRevenueApp.use(cache('15 day')); studentRevenueApp.get('/years', (req, res, next) => { req.sql.from('receitas') - .field('DISTINCT receitas.ano', 'year') - .where('receitas.ano is not null') + .field('DISTINCT receitas.ano', 'year') + .where('receitas.ano is not null') next(); }, query, response('years')); +studentRevenueApp.get('/type', (req, res, next) => { + req.result = [] + + req.result.push({ id: 1, name: "Rede Estadual" }); + req.result.push({ id: 2, name: "Rede Municipal" }); + next(); +}, response('type')); + rqf.addField({ name: 'filter', field: false, @@ -96,9 +104,13 @@ rqf.addField({ } }) -studentRevenueApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { +studentRevenueApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { if (req.query.dims && req.query.dims.includes('receitas')) { + let obj = {}; + console.log(req.query.filter) let whereCondition = req.query.filter.includes("region") ? "" : "receitas.cod_ibge = 0"; + + let typeFilter = false; let filterId; const filters = req.query.filter.split(","); filters.forEach((filter) => { @@ -108,20 +120,41 @@ studentRevenueApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { } }) - req.sql.from('receitas') - .field('receitas.ano', 'year') - .field('receitas.ano', 'total_ano') - .field('receitas.nome_ente', 'total_nome_ente') - .field('receitas.receitas', 'total_receitas') - .field('matriculas_publica', 'total_matriculas_publica') - .field('matriculas_publicas_mais_conveniada', 'total_matriculas_publicas_mais_conveniada') - .field('receuta_aluno_ano_publica', 'total_receita_aluno_ano_publica') - .field('receita_aluno_mes_publica', 'total_receita_aluno_mes_publica') - .field('receita_aluno_ano_publica_mais_conveniada', 'total_receita_aluno_ano_publica_mais_conveniada') - .field('receita_aluno_mes_publica_mais_conveniada', 'total_receita_aluno_mes_publica_mais_conveniada') - .where(`${whereCondition}`) - .order('receitas.cod_ibge') - .order('receitas.ano') + if (req.query.filter) { + const jsonString = `{${req.query.filter.replace(/(\w+):/g, '"$1":')}}`; + obj = JSON.parse(jsonString); + if (obj.type) { + if (obj.type.includes("1") && !obj.type.includes("2")) + whereCondition = "receitas.cod_ibge >= 11 and receitas.cod_ibge <= 53" + else if (obj.type.includes("2") && !obj.type.includes("1")) + whereCondition = "receitas.cod_ibge > 53" + + typeFilter = true; + } + } + if (typeFilter && (!obj.state && !obj.city && !obj.region)) { + req.sql.from('receitas') + .field('receitas.ano', 'year') + // .field('receitas.ano', 'total_ano') + .field('SUM(receitas.receitas)', 'total_receitas') + .field('SUM(receuta_aluno_ano_publica)', '(total_receita_aluno_ano_publica)') + .field('SUM(receita_aluno_mes_publica)', 'total_receita_aluno_mes_publica') + .field('SUM(receita_aluno_ano_publica_mais_conveniada)', 'total_receita_aluno_ano_publica_mais_conveniada') + .field('SUM(receita_aluno_mes_publica_mais_conveniada)', 'total_receita_aluno_mes_publica_mais_conveniada') + .where(`${whereCondition}`) + .group('receitas.ano') + } else if (!typeFilter) { + req.sql.from('receitas') + .field('receitas.ano', 'year') + .field('SUM(receitas.receitas)', 'total_receitas') + .field('SUM(receuta_aluno_ano_publica)', '(total_receita_aluno_ano_publica)') + .field('SUM(receita_aluno_mes_publica)', 'total_receita_aluno_mes_publica') + .field('SUM(receita_aluno_ano_publica_mais_conveniada)', 'total_receita_aluno_ano_publica_mais_conveniada') + .field('SUM(receita_aluno_mes_publica_mais_conveniada)', 'total_receita_aluno_mes_publica_mais_conveniada') + .where(`${whereCondition}`) + .group('receitas.ano') + + } } next(); -- GitLab From 90979225bcb09b879dbe7aa36548986714e48385 Mon Sep 17 00:00:00 2001 From: Lewis <lgtg20@inf.ufpr.br> Date: Thu, 27 Mar 2025 11:28:49 -0300 Subject: [PATCH 08/45] feat: update region codes and add type endpoint; enhance student revenue and cost queries --- src/libs/convert/expenses.js | 18 +++-------- src/libs/routes_v1/studentCost.js | 47 +++++++++++++++++++--------- src/libs/routes_v1/studentRevenue.js | 14 +-------- 3 files changed, 38 insertions(+), 41 deletions(-) diff --git a/src/libs/convert/expenses.js b/src/libs/convert/expenses.js index 5cd28c4e..2d8ff384 100644 --- a/src/libs/convert/expenses.js +++ b/src/libs/convert/expenses.js @@ -21,23 +21,13 @@ along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. module.exports = function regionCode(id) { switch (id) { case 1: - return "Ano"; + return 'Rede pública (anual)' case 2: - return "Entidade"; + return 'Rede pública (mensal)'; case 3: - return 'Despesas'; + return 'Rede pública e conveniada (anual)'; case 4: - return 'Matrículas Públicas'; - case 5: - return 'Matrículas Públicas Mais Conveniada'; - case 6: - return 'Despesas Aluno Ano Pública' - case 7: - return 'Despesas Aluno Mês Pública'; - case 8: - return 'Despesas Aluno Ano Pública Mais Conveniada'; - case 9: - return 'Despesas Aluno Mês Pública Mais Conveniada'; + return 'Rede pública e conveniada (mensal)'; } }; diff --git a/src/libs/routes_v1/studentCost.js b/src/libs/routes_v1/studentCost.js index fdcf7270..74aa91a2 100644 --- a/src/libs/routes_v1/studentCost.js +++ b/src/libs/routes_v1/studentCost.js @@ -51,6 +51,14 @@ studentCostApp.get('/years', (req, res, next) => { next(); }, query, response('years')); +studentCostApp.get('/type', (req, res, next) => { + req.result = [] + + req.result.push({ id: 1, name: "Rede Estadual" }); + req.result.push({ id: 2, name: "Rede Municipal" }); + next(); +}, response('type')); + rqf.addField({ name: 'filter', field: false, @@ -98,8 +106,10 @@ rqf.addField({ studentCostApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { if (req.query.dims && req.query.dims.includes('despesas')) { + let obj = {}; let whereCondition = req.query.filter.includes("region") ? "" : "despesas.cod_ibge = 0"; let filterId; + let typeFilter = false; const filters = req.query.filter.split(","); filters.forEach((filter) => { if (filter.includes("state") || filter.includes("city")) { @@ -108,20 +118,29 @@ studentCostApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { } }) - req.sql.from('despesas') - .field('despesas.ano_censo', 'year') - .field('despesas.ano_censo', 'total_ano') - .field('despesas.nome_ente', 'total_nome_ente') - .field('despesas.despesas', 'total_despesas') - .field('matriculas_publica', 'total_matriculas_publica') - .field('matriculas_publicas_mais_conveniada', 'total_matriculas_publicas_mais_conveniada') - .field('gasto_aluno_ano_publica', 'total_gasto_aluno_ano_publica') - .field('gasto_aluno_mes_publica', 'total_gasto_aluno_mes_publica') - .field('gasto_aluno_ano_publica_mais_conveniada', 'total_gasto_aluno_ano_publica_mais_conveniada') - .field('gasto_aluno_mes_publica_mais_conveniada', 'total_gasto_aluno_mes_publica_mais_conveniada') - .where(`${whereCondition}`) - .order('despesas.cod_ibge') - .order('despesas.ano_censo') + if (req.query.filter) { + const jsonString = `{${req.query.filter.replace(/(\w+):/g, '"$1":')}}`; + obj = JSON.parse(jsonString); + if (obj.type) { + if (obj.type.includes("1") && !obj.type.includes("2")) + whereCondition = "despesas.cod_ibge >= 11 and despesas.cod_ibge <= 53" + else if (obj.type.includes("2") && !obj.type.includes("1")) + whereCondition = "despesas.cod_ibge > 53" + + typeFilter = true; + } + } + + if (!typeFilter || (typeFilter && (!obj.state && !obj.city && !obj.region))) { + req.sql.from('despesas') + .field('despesas.ano_censo', 'year') + .field('SUM(gasto_aluno_ano_publica)', 'total_gasto_aluno_ano_publica') + .field('SUM(gasto_aluno_mes_publica)', 'total_gasto_aluno_mes_publica') + .field('SUM(gasto_aluno_ano_publica_mais_conveniada)', 'total_gasto_aluno_ano_publica_mais_conveniada') + .field('SUM(gasto_aluno_mes_publica_mais_conveniada)', 'total_gasto_aluno_mes_publica_mais_conveniada') + .where(`${whereCondition}`) + .group('despesas.ano_censo') + } } next(); diff --git a/src/libs/routes_v1/studentRevenue.js b/src/libs/routes_v1/studentRevenue.js index 17da5f27..2b62671d 100644 --- a/src/libs/routes_v1/studentRevenue.js +++ b/src/libs/routes_v1/studentRevenue.js @@ -132,10 +132,9 @@ studentRevenueApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { typeFilter = true; } } - if (typeFilter && (!obj.state && !obj.city && !obj.region)) { + if (!typeFilter || (typeFilter && (!obj.state && !obj.city && !obj.region))) { req.sql.from('receitas') .field('receitas.ano', 'year') - // .field('receitas.ano', 'total_ano') .field('SUM(receitas.receitas)', 'total_receitas') .field('SUM(receuta_aluno_ano_publica)', '(total_receita_aluno_ano_publica)') .field('SUM(receita_aluno_mes_publica)', 'total_receita_aluno_mes_publica') @@ -143,17 +142,6 @@ studentRevenueApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .field('SUM(receita_aluno_mes_publica_mais_conveniada)', 'total_receita_aluno_mes_publica_mais_conveniada') .where(`${whereCondition}`) .group('receitas.ano') - } else if (!typeFilter) { - req.sql.from('receitas') - .field('receitas.ano', 'year') - .field('SUM(receitas.receitas)', 'total_receitas') - .field('SUM(receuta_aluno_ano_publica)', '(total_receita_aluno_ano_publica)') - .field('SUM(receita_aluno_mes_publica)', 'total_receita_aluno_mes_publica') - .field('SUM(receita_aluno_ano_publica_mais_conveniada)', 'total_receita_aluno_ano_publica_mais_conveniada') - .field('SUM(receita_aluno_mes_publica_mais_conveniada)', 'total_receita_aluno_mes_publica_mais_conveniada') - .where(`${whereCondition}`) - .group('receitas.ano') - } } -- GitLab From 02bd81387b7ca1b868d4ab0cdddc282c1d64fac0 Mon Sep 17 00:00:00 2001 From: Lewis <lgtg20@inf.ufpr.br> Date: Fri, 28 Mar 2025 09:18:11 -0300 Subject: [PATCH 09/45] fix: update region codes in revenue conversion; remove unused field from student revenue query --- src/libs/convert/revenue.js | 8 +++----- src/libs/routes_v1/studentRevenue.js | 1 - 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/libs/convert/revenue.js b/src/libs/convert/revenue.js index 006e2662..fb3c819a 100644 --- a/src/libs/convert/revenue.js +++ b/src/libs/convert/revenue.js @@ -21,14 +21,12 @@ along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. module.exports = function regionCode(id) { switch (id) { case 1: - return 'Receitas'; - case 2: return 'Rede pública (anual)' - case 3: + case 2: return 'Rede pública (mensal)'; - case 4: + case 3: return 'Rede pública e conveniada (anual)'; - case 5: + case 4: return 'Rede pública e conveniada (mensal)'; } }; diff --git a/src/libs/routes_v1/studentRevenue.js b/src/libs/routes_v1/studentRevenue.js index 2b62671d..8136ea0a 100644 --- a/src/libs/routes_v1/studentRevenue.js +++ b/src/libs/routes_v1/studentRevenue.js @@ -135,7 +135,6 @@ studentRevenueApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { if (!typeFilter || (typeFilter && (!obj.state && !obj.city && !obj.region))) { req.sql.from('receitas') .field('receitas.ano', 'year') - .field('SUM(receitas.receitas)', 'total_receitas') .field('SUM(receuta_aluno_ano_publica)', '(total_receita_aluno_ano_publica)') .field('SUM(receita_aluno_mes_publica)', 'total_receita_aluno_mes_publica') .field('SUM(receita_aluno_ano_publica_mais_conveniada)', 'total_receita_aluno_ano_publica_mais_conveniada') -- GitLab From f6f6b64c966b19ba75217f55721806b0061630d3 Mon Sep 17 00:00:00 2001 From: Lewis <lgtg20@inf.ufpr.br> Date: Fri, 28 Mar 2025 09:21:34 -0300 Subject: [PATCH 10/45] refactor: remove console.log statements from route handlers --- src/libs/routes_v1/enrollmentAggregate.js | 2 -- src/libs/routes_v1/newPnad.js | 1 - src/libs/routes_v1/studentRevenue.js | 1 - 3 files changed, 4 deletions(-) diff --git a/src/libs/routes_v1/enrollmentAggregate.js b/src/libs/routes_v1/enrollmentAggregate.js index 7e8cd3fa..a561f137 100644 --- a/src/libs/routes_v1/enrollmentAggregate.js +++ b/src/libs/routes_v1/enrollmentAggregate.js @@ -512,8 +512,6 @@ rqf.addField({ // Return all cities enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { - console.log(req.query); - if (req.query.dims && req.query.dims.includes('gender')) { req.sql.from('escola') diff --git a/src/libs/routes_v1/newPnad.js b/src/libs/routes_v1/newPnad.js index 5bfb7b8a..e9549404 100644 --- a/src/libs/routes_v1/newPnad.js +++ b/src/libs/routes_v1/newPnad.js @@ -518,7 +518,6 @@ PnadNovoApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .field('pnad_novo.ano_ref', 'year') .group('pnad_novo.ano_ref') .order('pnad_novo.ano_ref') - console.log(req.sql.toString()) next(); }, query, id2str.transform(false), response('pnad_novo')); diff --git a/src/libs/routes_v1/studentRevenue.js b/src/libs/routes_v1/studentRevenue.js index 8136ea0a..271566af 100644 --- a/src/libs/routes_v1/studentRevenue.js +++ b/src/libs/routes_v1/studentRevenue.js @@ -107,7 +107,6 @@ rqf.addField({ studentRevenueApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { if (req.query.dims && req.query.dims.includes('receitas')) { let obj = {}; - console.log(req.query.filter) let whereCondition = req.query.filter.includes("region") ? "" : "receitas.cod_ibge = 0"; let typeFilter = false; -- GitLab From bc2d1627848df30b2a2b458ad9b075ca7798c3f6 Mon Sep 17 00:00:00 2001 From: Joao Pedro <jpv.ramalho2013@gmail.com> Date: Wed, 2 Apr 2025 11:09:36 -0300 Subject: [PATCH 11/45] [add] funcionando a rota do back --- src/libs/convert/potentialRevenue.js | 42 ++++++ src/libs/middlewares/aggregateData.js | 2 + src/libs/middlewares/id2str.js | 3 + .../middlewares/potentialRevenueParser.js | 21 +++ src/libs/middlewares/studentRevenueParser.js | 2 +- src/libs/routes_v1/api.js | 5 + src/libs/routes_v1/potentialRevenue.js | 131 ++++++++++++++++++ 7 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 src/libs/convert/potentialRevenue.js create mode 100644 src/libs/middlewares/potentialRevenueParser.js create mode 100644 src/libs/routes_v1/potentialRevenue.js diff --git a/src/libs/convert/potentialRevenue.js b/src/libs/convert/potentialRevenue.js new file mode 100644 index 00000000..18cfeb8c --- /dev/null +++ b/src/libs/convert/potentialRevenue.js @@ -0,0 +1,42 @@ +/* +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/>. +*/ + +module.exports = function regionCode(id) { + switch (id) { + case 1: + return "Ano"; + case 2: + return "Nome Ente" + case 3: + return 'Receitas'; + case 4: + return 'Matrículas Públicas'; + case 5: + return 'Matrículas Públicas Mais Conveniada'; + case 6: + return 'Receita Aluno Ano Pública' + case 7: + return 'Receita Aluno Mês Pública'; + case 8: + return 'Receita Aluno Ano Pública Mais Conveniada'; + case 9: + return 'Receita Aluno Mês Pública Mais Conveniada'; + } +}; diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js index fccb7453..e7839a07 100644 --- a/src/libs/middlewares/aggregateData.js +++ b/src/libs/middlewares/aggregateData.js @@ -37,6 +37,7 @@ const convert = { education_degree_entity: "educationDegreeEntity", government_agreement: "governmentAgreement", despesas_alunos: "expenses", + receita_potencial: "potentialRevenue", receitas: "revenue", despesas: "studentCost" } @@ -69,6 +70,7 @@ function aggregateData(req, res, next) { 'education_degree_entity', 'despesas_alunos', 'receitas', + 'receita_potencial', 'despesas' ]; const baseFields = ["school"] diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index 61cd5e77..a05fe0ee 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -127,6 +127,7 @@ const postGraduationEntity = require(`${libs}/convert/postGraduationEntity`); const totalDoc = require(`${libs}/convert/totalDoc`); const educationDegreeEntity = require(`${libs}/convert/educationDegreeEntity`); const expenses = require(`${libs}/convert/expenses.js`) +const potentialRevenue = require(`${libs}/convert/potentialRevenue.js`) const revenue = require(`${libs}/convert/revenue`); const studentCost = require(`${libs}/convert/studentCost`); const ageRange19to64 = require(`${libs}/convert/ageRange19to64`); @@ -250,6 +251,7 @@ const ids = { total_doc: totalDoc, education_degree_entity: educationDegreeEntity, despesas_id: expenses, + receita_potencial_id: potentialRevenue, receitas_id: revenue, student_cost: studentCost, age_range_19_to_64_id: ageRange19to64 @@ -395,6 +397,7 @@ module.exports = { totalDoc, educationDegreeEntity, expenses, + potentialRevenue, revenue, studentCost, ageRange19to64 diff --git a/src/libs/middlewares/potentialRevenueParser.js b/src/libs/middlewares/potentialRevenueParser.js new file mode 100644 index 00000000..23ceb652 --- /dev/null +++ b/src/libs/middlewares/potentialRevenueParser.js @@ -0,0 +1,21 @@ +/* +Middleware que remove o campo "region" quando o campo "city" está ativo nos filtros. +Devido à limitações na tabela de dados, quando ambos campos estão ativos o filtro por +"região" funciona incorretamente. +*/ +module.exports = function potentialRevenueParser(req, res, next) { + if (req.query && req.query.filter) { + const jsonString = `{${req.query.filter.replace(/(\w+):/g, '"$1":')}}`; + const obj = JSON.parse(jsonString); + + if ("city" in obj && "region" in obj) { + delete obj.region; + const customString = Object.entries(obj) + .map(([key, value]) => `${key}:"${value}"`) + .join(','); + req.query.filter = customString; + } + } + + next(); +}; diff --git a/src/libs/middlewares/studentRevenueParser.js b/src/libs/middlewares/studentRevenueParser.js index d11f98f5..876dfb75 100644 --- a/src/libs/middlewares/studentRevenueParser.js +++ b/src/libs/middlewares/studentRevenueParser.js @@ -19,4 +19,4 @@ module.exports = function studentRevenueParser(req, res, next) { } next(); -}; +}; \ No newline at end of file diff --git a/src/libs/routes_v1/api.js b/src/libs/routes_v1/api.js index 041e0b38..4868ab3c 100644 --- a/src/libs/routes_v1/api.js +++ b/src/libs/routes_v1/api.js @@ -161,6 +161,10 @@ const expenses = require(`${libs}/routes_v1/expenses`); const expensesParser = require(`${libs}/middlewares/expensesParser`); +const potentialRevenue = require(`${libs}/routes_v1/potentialRevenue`); + +const potentialRevenueParser = require(`${libs}/middlewares/potentialRevenueParser`); + const yearsOfStudy = require(`${libs}/routes_v1/yearsOfStudy`) const studentsReceivingAidTax = require(`${libs}/routes_v1/studentsReceivingAidTax`) @@ -251,6 +255,7 @@ api.use('/course_aggregate', courseAggregate); api.use('/federativeEntity', federativeEntity); api.use('/uni_offer_aggregate', uniLocalOfferAggregate); api.use('/expenses', expensesParser, expenses); +api.use('/potential_revenue', potentialRevenueParser, potentialRevenue); api.use('/years_of_study', yearsOfStudy) api.use('/students_receiving_aid_tax', studentsReceivingAidTax); api.use('/superior_education_conclusion_tax', superiorEducationConclusionTax) diff --git a/src/libs/routes_v1/potentialRevenue.js b/src/libs/routes_v1/potentialRevenue.js new file mode 100644 index 00000000..d52bf6bf --- /dev/null +++ b/src/libs/routes_v1/potentialRevenue.js @@ -0,0 +1,131 @@ +/* +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 potentialRevenueApp = 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; + +const aggregateData = require(`${libs}/middlewares/aggregateData`); + +let rqf = new ReqQueryFields(); + +potentialRevenueApp.use(cache('15 day')); + +potentialRevenueApp.get('/years', (req, res, next) => { + req.sql.from('receitas') + .field('DISTINCT receitas.ano', 'year') + .where('receitas.ano is not null') + next(); +}, query, response('years')) + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'min_year', + table: 'receitas', + tableField: 'ano', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + field: 'ano' + } +}).addValue({ + name: 'max_year', + table: 'receitas', + tableField: 'ano', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + field: 'ano' + } +}).addValue({ + name: 'region', + table: 'estado', + tableField: ['nome_ente', 'cod_ibge', 'id', 'regiao_id'], + resultField: ['state_name', 'state_cod_ibge', 'state_id', 'region_id'], + where: { + relation: '=', + type: 'integer', + field: 'regiao_id', + }, + join: { + primary: 'id', + foreign: 'cod_ibge', + foreignTable: 'receitas' + } +}) + + +potentialRevenueApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + + if (req.query.dims && req.query.dims.includes('receitas')) { + let whereCondition = req.query.filter.includes("region") ? "" : "receitas.cod_ibge = 0"; + let filterId; + const filters = req.query.filter.split(","); + filters.forEach((filter) => { + if (filter.includes("state") || filter.includes("city")) { + filterId = Number(filter.split(":")[1].replace(/"/g, "")); + whereCondition = `receitas.cod_ibge = ${filterId}` + } + }) + + req.sql.from('receitas') + .field('receitas.ano', 'year') + .field('receitas.ano', 'total_ano') + .field('receitas.nome_ente', 'total_nome_ente') + .field('receitas.receitas', 'total_receitas') + .field('matriculas_publica', 'total_matriculas_publica') + .field('matriculas_publicas_mais_conveniada', 'total_matriculas_publicas_mais_conveniada') + .field('receuta_aluno_ano_publica', 'total_receuta_aluno_ano_publica') + .field('receita_aluno_mes_publica', 'total_receita_aluno_mes_publica') + .field('receita_aluno_ano_publica_mais_conveniada', 'total_receita_aluno_ano_publica_mais_conveniada') + .field('receita_aluno_mes_publica_mais_conveniada', 'total_receita_aluno_mes_publica_mais_conveniada') + .where(`${whereCondition}`) + .order('receitas.ano') + } + + next(); +}, query, aggregateData, id2str.transform(false), response('potentialRevenue')); + +module.exports = potentialRevenueApp; \ No newline at end of file -- GitLab From 890a63387909e3ec8b4e6360c65b762f10061f74 Mon Sep 17 00:00:00 2001 From: fgs21 <fgs21@inf.ufpr.br> Date: Tue, 8 Apr 2025 10:53:43 -0300 Subject: [PATCH 12/45] [ADD] route working! --- .gitignore | 1 + src/libs/convert/ageRangePopSchool.js | 40 ++ src/libs/middlewares/id2str.js | 11 +- src/libs/routes_v1/api.js | 4 + src/libs/routes_v1/populationOutOfSchool.js | 532 ++++++++++++++++++++ src/libs/routes_v1/school.js | 2 + 6 files changed, 587 insertions(+), 3 deletions(-) create mode 100644 src/libs/convert/ageRangePopSchool.js create mode 100644 src/libs/routes_v1/populationOutOfSchool.js diff --git a/.gitignore b/.gitignore index 2fa21185..8079ab20 100644 --- a/.gitignore +++ b/.gitignore @@ -31,4 +31,5 @@ src/libs/db/postgres.js docker-compose.yml entrypoint.sh gulpfile.template.js +gulpfile.babel.js diff --git a/src/libs/convert/ageRangePopSchool.js b/src/libs/convert/ageRangePopSchool.js new file mode 100644 index 00000000..dc5ef13e --- /dev/null +++ b/src/libs/convert/ageRangePopSchool.js @@ -0,0 +1,40 @@ +/* +Copyright (C) 2025 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 ageRangePopSchool(id) { + switch (id) { + case 1: + return '0 a 3 anos'; + case 2: + return '4 a 5 anos'; + case 3: + return '6 a 10 anos'; + case 4: + return '11 a 14 anos'; + case 5: + return '15 a 17 anos'; + case 6: + return '18 a 24 anos'; + case 7: + return 'Acima de 24 anos'; + default: + return 'Não declarada'; + } +}; diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index 730d620e..025bbb6b 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -18,6 +18,8 @@ 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 ageRangePopSchool = require("../convert/ageRangePopSchool"); + const libs = `${process.cwd()}/libs`; const gender = require(`${libs}/convert/gender`); const period = require(`${libs}/convert/period`); @@ -128,6 +130,7 @@ const totalDoc = require(`${libs}/convert/totalDoc`); const educationDegreeEntity = require(`${libs}/convert/educationDegreeEntity`); const revenue = require(`${libs}/convert/revenue`); const studentCost = require(`${libs}/convert/studentCost`); +const ageRangeOutSchool = require(`${libs}/convert/ageRangePopSchool`); const ids = { gender_id: gender, @@ -248,7 +251,8 @@ const ids = { total_doc: totalDoc, education_degree_entity: educationDegreeEntity, receitas_id: revenue, - student_cost: studentCost + student_cost: studentCost, + age_range_pop_school_id: ageRangePopSchool }; function transform(removeId=false) { @@ -258,7 +262,7 @@ function transform(removeId=false) { } // Para cada objeto do resultado req.result.forEach((obj) => { - console.log(obj), + //console.log(obj), Object.keys(obj).forEach((key) => { // Se não há uma função especificada, retorna if(typeof ids[key] === 'undefined') return; @@ -392,5 +396,6 @@ module.exports = { totalDoc, educationDegreeEntity, revenue, - studentCost + studentCost, + ageRangePopSchool }; diff --git a/src/libs/routes_v1/api.js b/src/libs/routes_v1/api.js index 5331b389..133d5f18 100644 --- a/src/libs/routes_v1/api.js +++ b/src/libs/routes_v1/api.js @@ -174,10 +174,13 @@ const adjustedLiquidFrequency = require(`${libs}/routes_v1/adjustedLiquidFrequen const iliteracyRate = require(`${libs}/routes_v1/iliteracyRate`); const studentRevenue = require(`${libs}/routes_v1/studentRevenue`); + const studentRevenueParser = require(`${libs}/middlewares/studentRevenueParser`); const studentCost = require(`${libs}/routes_v1/studentCost`); +const populationOutOfSchool = require(`${libs}/routes_v1/populationOutOfSchool`); + api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API v1 is running' }); }); @@ -254,6 +257,7 @@ api.use('/adjusted_liquid_frequency', adjustedLiquidFrequency); api.use('/iliteracy_rate', iliteracyRate); api.use('/student_revenue', studentRevenueParser, studentRevenue); api.use('/student_cost', studentRevenueParser, studentCost); +api.use('/pop_out_school', populationOutOfSchool); //Publication api.use('/publication', publication); diff --git a/src/libs/routes_v1/populationOutOfSchool.js b/src/libs/routes_v1/populationOutOfSchool.js new file mode 100644 index 00000000..cac33a68 --- /dev/null +++ b/src/libs/routes_v1/populationOutOfSchool.js @@ -0,0 +1,532 @@ +/* +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 PopulationOutOfSchoolApp = 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(); + +const multiQuery = require(`${libs}/middlewares/multiQuery`); + +PopulationOutOfSchoolApp.use(cache('15 day')); + +PopulationOutOfSchoolApp.get('/years', (req, res, next) => { + req.sql.from('pnad_novo') + .field('DISTINCT pnad_novo.ano_ref', 'year') + .where('pnad_novo.ano_ref >= 2019') + next(); +}, query, response('years')); + +PopulationOutOfSchoolApp.get('/illiteracy', (req, res, next) => { + req.result = [] + + for (let i = 0; i < 2; i++) { + req.result.push({ + id: i, name: id2str.illiteracy(i) + }); + + } + req.result.push({id: 9, name: id2str.illiteracy(9)}); + next(); +}, response('illiteracy')); + +PopulationOutOfSchoolApp.get('/years_of_study', (req, res, next) => { + req.result = [] + + for (let i = 0; i < 17; i++) { + req.result.push({ + id: i, name: id2str.yearsOfStudy(i) + }); + } + + req.result.push({id: 99, name: id2str.yearsOfStudy(99)}); + next(); +}, response('years_of_study')); + +PopulationOutOfSchoolApp.get('/instruction_level', (req, res, next) => { + req.result = [] + + for (let i = 1; i < 8; i++) { + req.result.push({ + id: i, name: id2str.instructionLevel(i) + }); + } + req.result.push({id: 99, name: id2str.instructionLevel(99)}); + next(); +}, response('instruction_level')); + +PopulationOutOfSchoolApp.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')); + +PopulationOutOfSchoolApp.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')); + +PopulationOutOfSchoolApp.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')); + +PopulationOutOfSchoolApp.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')); + +PopulationOutOfSchoolApp.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')); + +PopulationOutOfSchoolApp.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')); + +PopulationOutOfSchoolApp.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')); + +PopulationOutOfSchoolApp.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')); + +PopulationOutOfSchoolApp.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')); + +PopulationOutOfSchoolApp.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')); + +PopulationOutOfSchoolApp.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')); + +PopulationOutOfSchoolApp.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')); + +PopulationOutOfSchoolApp.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')); + +PopulationOutOfSchoolApp.get('/age_range_pop_school', (req, res, next) => { + req.result = [] + for (let i = 1; i < 8; i++) { + req.result.push({ + id: i, name: id2str.ageRangePopSchool(i) + }); + } + + next(); +}, response('age_range_pop_school')); + + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'id', + table: 'pnad_novo', + 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: 'pnad_novo' + } +}).addValue({ + name: 'state_not', + table: 'estado', + tableField: ['nome', 'id'], + resultField: ['state_name', 'state_id'], + where: { + relation: '<>', + type: 'integer', + field: 'cod_uf', + table: 'pnad_novo' + }, + join: { + primary: 'id', + foreign: 'cod_uf', + foreignTable: 'pnad_novo' + } +}).addValue({ + name: 'bolsa_familia', + table: 'pnad_novo', + 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: 'pnad_novo', + tableField: 'cor_raca', + resultField: 'new_pnad_ethnic_group_id', + where: { + relation: '=', + type: 'integer', + field: 'cor_raca' + } +}).addValue({ + name: 'age_range_pop_school', + table: 'pnad_novo', + tableField: 'faixa_etaria_pop_out', + resultField: 'age_range_pop_school_id', + where: { + relation: '=', + type: 'integer', + field: 'faixa_etaria_pop_out' + } +}).addValue({ + name: 'income_range', + table: 'pnad_novo', + tableField: 'faixa_rendimento_aux', + resultField: 'income_range_id', + where: { + relation: '=', + type: 'integer', + field: 'faixa_rendimento_aux' + } +}).addValue({ + name: 'gender', + table: 'pnad_novo', + tableField: 'sexo', + resultField: 'gender_id', + where: { + relation: '=', + type: 'integer', + field: 'sexo' + } +}).addValue({ + name: 'cap_code', + table: 'pnad_novo', + tableField: 'cod_cap', + resultField: 'cap_code_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_cap' + } +}).addValue({ + name: 'region', + table: 'pnad_novo', + tableField: 'cod_regiao', + resultField: 'region_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_regiao' + } +}).addValue({ + name: 'metro_code', + table: 'pnad_novo', + tableField: 'cod_rm_ride', + resultField: 'metro_code_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_rm_ride' + } +}).addValue({ + name: 'min_year', + table: 'pnad_novo', + tableField: 'ano_ref', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + field: 'ano_ref' + } +}).addValue({ + name: 'max_year', + table: 'pnad_novo', + tableField: '', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + field: 'ano_ref' + } +}).addValue({ + name: 'location', + table: 'pnad_novo', + tableField: 'situacao_domicilio', + resultField: 'location_id', + where: { + relation: '=', + type: 'integer', + field: 'situacao_domicilio' + } +}); + +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('total'); + 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.total; + newObj.pop_total = objMatch.total; + newObj.total = Math.round((objMatch.total / result.total) * 100) + match.push(newObj); + } + } +) + + + /* console.log("tamanho: " + match.length); + console.log(match[10]) + for (let i = 7; i < match.length; i++) { + console.log("i: " , i) + match[6].denominator += match[i].denominator; + match[6].pop_total += match[i].pop_total; + } + + + console.log("chega aqui") + match[6].total = Math.round((match[6].pop_total / match[6].denominator) * 100) + console.log("match 6: " , match[6].total) + + + match.splice(7, 4) */ + + console.log(match) + + return match; +} + +PopulationOutOfSchoolApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + if ("age_range_pop_school" in req.filter || "age_range_pop_school" in req.dims) { + // As we will need to do two requests, they'll be stored in a list + req.querySet = [] + + // Create an object that will store the first request (the sum of all people that attend school) + let attends_school = req.sql.clone(); + attends_school.from('pnad_novo') + .field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total') + .field('pnad_novo.faixa_etaria_pop_out') + .field('pnad_novo.ano_ref', 'year') + .where('pnad_novo.ano_ref >= 2019') + .where('pnad_novo.frequenta_escola = 2') + .where('(pnad_novo.faixa_etaria_pop_out IN (1,2)) OR (pnad_novo.faixa_etaria_pop_out = 3 AND pnad_novo.nivel_de_instruc_mais_elevad_para_o_fundam_com_duracao_9_anos <= 2) OR \ + (pnad_novo.faixa_etaria_pop_out = 4 AND pnad_novo.nivel_de_instruc_mais_elevad_para_o_fundam_com_duracao_9_anos <= 3) OR \ + (pnad_novo.faixa_etaria_pop_out >= 5 AND pnad_novo.nivel_de_instruc_mais_elevad_para_o_fundam_com_duracao_9_anos <= 4)') + .group('pnad_novo.ano_ref') + .group('pnad_novo.faixa_etaria_pop_out') + .order('pnad_novo.ano_ref') + .order('pnad_novo.faixa_etaria_pop_out') + req.querySet.push(attends_school); + console.log(attends_school.toString()); + + + // Then, the second object is created and stores the sum of all people without filters + let full_population = req.sql.clone(); + full_population.from('pnad_novo') + .field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total') + .field('pnad_novo.faixa_etaria_pop_out') + .field('pnad_novo.ano_ref', 'year') + .where('pnad_novo.ano_ref >= 2019') + .group('pnad_novo.ano_ref') + .group('pnad_novo.faixa_etaria_pop_out') + .order('pnad_novo.ano_ref') + .order('pnad_novo.faixa_etaria_pop_out') + req.querySet.push(full_population); + } + + next(); +}, multiQuery, (req, res, next) => { + if ("age_range_pop_school" in req.filter || "age_range_pop_school" in req.dims) { + // The multiple requests are made. Then we need to calculate the percetange. So the function + // below is used + let newObj = matchQueries(req.result[0], req.result[1]); + req.result = newObj; + //console.log(attends_school.toString()); + } else { + res.status(400); + next({ + status: 400, + message: 'Wrong/No filter specified' + }); + } + next(); +}, id2str.transform(false), response('populationOutOfSchool')); + +module.exports = PopulationOutOfSchoolApp; diff --git a/src/libs/routes_v1/school.js b/src/libs/routes_v1/school.js index 54932c51..5207bb38 100644 --- a/src/libs/routes_v1/school.js +++ b/src/libs/routes_v1/school.js @@ -698,6 +698,8 @@ schoolApp.get('/count', cache('15 day'), rqfCount.parse(), (req, res, next) => { req.sql.where('' + arrangementQuery); } delete req.filter.arrangement + + console.log(req.sql.toString()) next(); }, rqfCount.build(), query, id2str.transform(), addMissing(rqfCount), response('school')); -- GitLab From bababae6eb77f49c174d7e320c3f5ab22a763e02 Mon Sep 17 00:00:00 2001 From: Fernando Gbur dos Santos <fgs21@inf.ufpr.br> Date: Tue, 8 Apr 2025 14:11:56 +0000 Subject: [PATCH 13/45] Edit school.js (console.log removed) --- src/libs/routes_v1/school.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/routes_v1/school.js b/src/libs/routes_v1/school.js index 5207bb38..5c5bfdeb 100644 --- a/src/libs/routes_v1/school.js +++ b/src/libs/routes_v1/school.js @@ -698,8 +698,7 @@ schoolApp.get('/count', cache('15 day'), rqfCount.parse(), (req, res, next) => { req.sql.where('' + arrangementQuery); } delete req.filter.arrangement - - console.log(req.sql.toString()) + next(); }, rqfCount.build(), query, id2str.transform(), addMissing(rqfCount), response('school')); -- GitLab From 994484177c7a18ad151639b60979167a7268a25b Mon Sep 17 00:00:00 2001 From: Lewis <lgtg20@inf.ufpr.br> Date: Tue, 8 Apr 2025 11:36:55 -0300 Subject: [PATCH 14/45] fix: update revenue calculation logic in studentRevenue route --- src/libs/routes_v1/studentRevenue.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/libs/routes_v1/studentRevenue.js b/src/libs/routes_v1/studentRevenue.js index 271566af..b549f896 100644 --- a/src/libs/routes_v1/studentRevenue.js +++ b/src/libs/routes_v1/studentRevenue.js @@ -123,10 +123,12 @@ studentRevenueApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { const jsonString = `{${req.query.filter.replace(/(\w+):/g, '"$1":')}}`; obj = JSON.parse(jsonString); if (obj.type) { - if (obj.type.includes("1") && !obj.type.includes("2")) + if (obj.type.includes("1") && !obj.type.includes("2")) { whereCondition = "receitas.cod_ibge >= 11 and receitas.cod_ibge <= 53" - else if (obj.type.includes("2") && !obj.type.includes("1")) + } + else if (obj.type.includes("2") && !obj.type.includes("1")) { whereCondition = "receitas.cod_ibge > 53" + } typeFilter = true; } @@ -134,10 +136,10 @@ studentRevenueApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { if (!typeFilter || (typeFilter && (!obj.state && !obj.city && !obj.region))) { req.sql.from('receitas') .field('receitas.ano', 'year') - .field('SUM(receuta_aluno_ano_publica)', '(total_receita_aluno_ano_publica)') - .field('SUM(receita_aluno_mes_publica)', 'total_receita_aluno_mes_publica') - .field('SUM(receita_aluno_ano_publica_mais_conveniada)', 'total_receita_aluno_ano_publica_mais_conveniada') - .field('SUM(receita_aluno_mes_publica_mais_conveniada)', 'total_receita_aluno_mes_publica_mais_conveniada') + .field(`SUM(receitas) / SUM(matriculas_publica)`, '(total_receita_aluno_ano_publica)') + .field(`SUM(receitas) / SUM(matriculas_publica) / 12`, 'total_receita_aluno_mes_publica') + .field(`SUM(receitas) / SUM(matriculas_publicas_mais_conveniada)`, 'total_receita_aluno_ano_publica_mais_conveniada') + .field(`SUM(receitas) / SUM(matriculas_publicas_mais_conveniada) / 12`, 'total_receita_aluno_mes_publica_mais_conveniada') .where(`${whereCondition}`) .group('receitas.ano') } -- GitLab From 580b5365dcf92ee8598a9c88dd38e41f5607cc28 Mon Sep 17 00:00:00 2001 From: MateusHerbele <mateusherbelemc@gmail.com> Date: Wed, 9 Apr 2025 11:08:20 -0300 Subject: [PATCH 15/45] indicador receita potencial finalizado --- src/libs/convert/potentialRevenue.js | 10 +--------- src/libs/routes_v1/potentialRevenue.js | 8 ++------ src/libs/routes_v1/studentRevenue.js | 2 +- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/libs/convert/potentialRevenue.js b/src/libs/convert/potentialRevenue.js index 18cfeb8c..ae7855bd 100644 --- a/src/libs/convert/potentialRevenue.js +++ b/src/libs/convert/potentialRevenue.js @@ -23,20 +23,12 @@ module.exports = function regionCode(id) { case 1: return "Ano"; case 2: - return "Nome Ente" + return "Nome Ente"; case 3: return 'Receitas'; case 4: return 'Matrículas Públicas'; case 5: return 'Matrículas Públicas Mais Conveniada'; - case 6: - return 'Receita Aluno Ano Pública' - case 7: - return 'Receita Aluno Mês Pública'; - case 8: - return 'Receita Aluno Ano Pública Mais Conveniada'; - case 9: - return 'Receita Aluno Mês Pública Mais Conveniada'; } }; diff --git a/src/libs/routes_v1/potentialRevenue.js b/src/libs/routes_v1/potentialRevenue.js index d52bf6bf..33557916 100644 --- a/src/libs/routes_v1/potentialRevenue.js +++ b/src/libs/routes_v1/potentialRevenue.js @@ -99,7 +99,7 @@ rqf.addField({ potentialRevenueApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { - if (req.query.dims && req.query.dims.includes('receitas')) { + if (req.query.dims && req.query.dims.includes('receita_potencial')) { let whereCondition = req.query.filter.includes("region") ? "" : "receitas.cod_ibge = 0"; let filterId; const filters = req.query.filter.split(","); @@ -117,12 +117,8 @@ potentialRevenueApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .field('receitas.receitas', 'total_receitas') .field('matriculas_publica', 'total_matriculas_publica') .field('matriculas_publicas_mais_conveniada', 'total_matriculas_publicas_mais_conveniada') - .field('receuta_aluno_ano_publica', 'total_receuta_aluno_ano_publica') - .field('receita_aluno_mes_publica', 'total_receita_aluno_mes_publica') - .field('receita_aluno_ano_publica_mais_conveniada', 'total_receita_aluno_ano_publica_mais_conveniada') - .field('receita_aluno_mes_publica_mais_conveniada', 'total_receita_aluno_mes_publica_mais_conveniada') .where(`${whereCondition}`) - .order('receitas.ano') + .order('receitas.ano'); } next(); diff --git a/src/libs/routes_v1/studentRevenue.js b/src/libs/routes_v1/studentRevenue.js index b595fb00..7b3e4c92 100644 --- a/src/libs/routes_v1/studentRevenue.js +++ b/src/libs/routes_v1/studentRevenue.js @@ -42,7 +42,7 @@ const cache = require('apicache').options({ debug: config.debug, statusCodes: {i let rqf = new ReqQueryFields(); -studentRevenueApp.use(cache('15 day')); +// studentRevenueApp.use(cache('15 day')); studentRevenueApp.get('/years', (req, res, next) => { req.sql.from('receitas') -- GitLab From 81e2d2b16c72f5b60f8b7e7ca81e8b1efffcfc3f Mon Sep 17 00:00:00 2001 From: MateusHerbele <mateusherbelemc@gmail.com> Date: Thu, 10 Apr 2025 11:36:39 -0300 Subject: [PATCH 16/45] [fix] convert/expenses.js --- src/libs/convert/expenses.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/libs/convert/expenses.js b/src/libs/convert/expenses.js index 2d8ff384..874cd0f4 100644 --- a/src/libs/convert/expenses.js +++ b/src/libs/convert/expenses.js @@ -21,13 +21,22 @@ along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. module.exports = function regionCode(id) { switch (id) { case 1: - return 'Rede pública (anual)' + return "Ano"; case 2: - return 'Rede pública (mensal)'; + return "Entidade"; case 3: - return 'Rede pública e conveniada (anual)'; + return 'Despesas'; case 4: - return 'Rede pública e conveniada (mensal)'; + return 'Matrículas Públicas'; + case 5: + return 'Matrículas Públicas Mais Conveniada'; + case 6: + return 'Despesas Aluno Ano Pública' + case 7: + return 'Despesas Aluno Mês Pública'; + case 8: + return 'Despesas Aluno Ano Pública Mais Conveniada'; + case 9: + return 'Despesas Aluno Mês Pública Mais Conveniada'; } }; - -- GitLab From 1f42013b66eeea7220e13d53add1cd750494d415 Mon Sep 17 00:00:00 2001 From: Lewis <lgtg20@inf.ufpr.br> Date: Mon, 14 Apr 2025 10:45:26 -0300 Subject: [PATCH 17/45] [feature] add region and state filters to adjustedLiquidFrequency query --- src/libs/routes_v1/adjustedLiquidFrequency.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/libs/routes_v1/adjustedLiquidFrequency.js b/src/libs/routes_v1/adjustedLiquidFrequency.js index 0be735c8..09ce8efb 100644 --- a/src/libs/routes_v1/adjustedLiquidFrequency.js +++ b/src/libs/routes_v1/adjustedLiquidFrequency.js @@ -344,6 +344,9 @@ adjustedLiquidFrequency.get('/', rqf.parse(), (req, res, next) => { ${dimensions.income_range ? "AND total_pop.income_range_id = pnad_novo.faixa_rendimento_aux" : ""} ${dimensions.cap_code ? "AND total_pop.cap_code_id = pnad_novo.cod_cap" : ""} ${dimensions.metro_code ? "AND pnad_novo.cod_rm_ride <> 99 AND total_pop.metro_code_id = pnad_novo.cod_rm_ride" : ""} + ${dimensions.region ? "AND total_pop.region_id = pnad_novo.cod_regiao" : ""} + ${dimensions.state ? "AND total_pop.state_id = pnad_novo.cod_uf" : ""} + ` // Subquery: total_apoio_freq @@ -393,6 +396,12 @@ adjustedLiquidFrequency.get('/', rqf.parse(), (req, res, next) => { if (dimensions.metro_code) mainQuery.field("total_apoio_freq.metro_code_id") + if (dimensions.region) + mainQuery.field("total_apoio_freq.region_id") + + if (dimensions.state) + mainQuery.field("total_apoio_freq.state_id") + req.sql = mainQuery; next(); -- GitLab From 25ea820ec951cd30a145b1b52ff89ddd48d771bb Mon Sep 17 00:00:00 2001 From: Lewis <lgtg20@inf.ufpr.br> Date: Mon, 14 Apr 2025 11:39:38 -0300 Subject: [PATCH 18/45] [fix] add ordering by year to student revenue query --- src/libs/routes_v1/studentRevenue.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/routes_v1/studentRevenue.js b/src/libs/routes_v1/studentRevenue.js index 488e0803..f5d5fda0 100644 --- a/src/libs/routes_v1/studentRevenue.js +++ b/src/libs/routes_v1/studentRevenue.js @@ -142,6 +142,7 @@ studentRevenueApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .field(`SUM(receitas) / SUM(matriculas_publicas_mais_conveniada) / 12`, 'total_receita_aluno_mes_publica_mais_conveniada') .where(`${whereCondition}`) .group('receitas.ano') + .order('receitas.ano') } } -- GitLab From b7bf4dc28a887e42f01d7d6ece294f6b9acfcb5a Mon Sep 17 00:00:00 2001 From: fgs21 <fgs21@inf.ufpr.br> Date: Tue, 22 Apr 2025 10:45:44 -0300 Subject: [PATCH 19/45] [hotfix] Rounding with 2 decimal numbers working --- src/libs/routes_v1/populationOutOfSchool.js | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/libs/routes_v1/populationOutOfSchool.js b/src/libs/routes_v1/populationOutOfSchool.js index cac33a68..99d991a5 100644 --- a/src/libs/routes_v1/populationOutOfSchool.js +++ b/src/libs/routes_v1/populationOutOfSchool.js @@ -445,29 +445,12 @@ function matchQueries(queryPartial, queryTotal) { if(objMatch) { newObj.denominator = result.total; newObj.pop_total = objMatch.total; - newObj.total = Math.round((objMatch.total / result.total) * 100) + newObj.total = Math.round((objMatch.total / result.total) * 10000) / 100; match.push(newObj); } } ) - - /* console.log("tamanho: " + match.length); - console.log(match[10]) - for (let i = 7; i < match.length; i++) { - console.log("i: " , i) - match[6].denominator += match[i].denominator; - match[6].pop_total += match[i].pop_total; - } - - - console.log("chega aqui") - match[6].total = Math.round((match[6].pop_total / match[6].denominator) * 100) - console.log("match 6: " , match[6].total) - - - match.splice(7, 4) */ - console.log(match) return match; -- GitLab From fa5e47ff966ab010dcae06889bca383849885410 Mon Sep 17 00:00:00 2001 From: fgs21 <fgs21@inf.ufpr.br> Date: Thu, 24 Apr 2025 10:57:20 -0300 Subject: [PATCH 20/45] [hotfix] Setting updated names to enrollment indicator --- src/libs/routes_v1/enrollment.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/routes_v1/enrollment.js b/src/libs/routes_v1/enrollment.js index 87259385..d7c8ef99 100644 --- a/src/libs/routes_v1/enrollment.js +++ b/src/libs/routes_v1/enrollment.js @@ -454,7 +454,7 @@ rqf.addField({ }, 'filter').addValueToField({ name: 'school', table: 'escola', - tableField: ['nome_escola', 'id'], + tableField: ['nome_escola_atualizado', 'id'], resultField: ['school_name', 'school_id'], where: { relation: '=', @@ -494,7 +494,7 @@ rqf.addField({ }, 'dims').addValueToField({ name: 'school', table: 'escola', - tableField: 'nome_escola', + tableField: 'nome_escola_atualizado', resultField: 'school_name', where: { relation: '=', -- GitLab From 446d05e0f30ef5942daf5859b252a885cf117e5f Mon Sep 17 00:00:00 2001 From: es23 <es23@inf.ufpr.br> Date: Tue, 29 Apr 2025 11:39:18 -0300 Subject: [PATCH 21/45] fix - nao e capital --- src/libs/routes_v1/api.js | 2 +- .../superiorEducationConclusionTax.js | 43 +++++++++++++------ 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/libs/routes_v1/api.js b/src/libs/routes_v1/api.js index 72fc3ddc..b5bcfda8 100644 --- a/src/libs/routes_v1/api.js +++ b/src/libs/routes_v1/api.js @@ -163,7 +163,7 @@ const aggregateClass = require(`${libs}/routes_v1/aggregateClass`); const instructionLevel = require(`${libs}/routes_v1/instructionLevel`); -const uniLocalOfferAggregate = require(`${libs}/routes_v1/uniLocalOfferAggregate`) +//const uniLocalOfferAggregate = require(`${libs}/routes_v1/uniLocalOfferAggregate`) const basicEducationConclusion = require(`${libs}/routes_v1/basicEducationConclusion`); diff --git a/src/libs/routes_v1/superiorEducationConclusionTax.js b/src/libs/routes_v1/superiorEducationConclusionTax.js index 1f84f7b0..a8198668 100644 --- a/src/libs/routes_v1/superiorEducationConclusionTax.js +++ b/src/libs/routes_v1/superiorEducationConclusionTax.js @@ -111,7 +111,7 @@ superiorEducationConclusionTaxApp.get('/region', (req, res, next) => { next(); }, response('region')); -superiorEducationConclusionTaxApp.get('/cap_code', (req, res, next) => { +superiorEducationConclusionTaxApp.get('/cap_code_pnad', (req, res, next) => { req.result = [] for (let i = 11; i < 54; i++) { if (id2str.capitalCode(i) !== 'Não informado') { @@ -120,10 +120,8 @@ superiorEducationConclusionTaxApp.get('/cap_code', (req, res, next) => { }); } } - req.result.push({id: 99, name: id2str.capitalCode(99)}); - next(); -}, response('cap_code')); +}, response('cap_code_pnad')); superiorEducationConclusionTaxApp.get('/metro_code', (req, res, next) => { req.result = [] @@ -134,7 +132,6 @@ superiorEducationConclusionTaxApp.get('/metro_code', (req, res, next) => { }); } } - req.result.push({id: 99, name: id2str.metroCode(99)}); next(); }, response('metro_code')); @@ -444,10 +441,10 @@ rqf.addField({ field: 'sexo' } }).addValue({ - name: 'cap_code', + name: 'cap_code_pnad', table: 'pnad_novo', tableField: 'cod_cap', - resultField: 'cap_code_id', + resultField: 'cap_code_pnad_id', where: { relation: '=', type: 'integer', @@ -575,9 +572,30 @@ function matchQueries(queryPartial, queryTotal) { return match; } +function whereCondition(req) { + let where = ""; + let filterId; + //const filters = req.query.filter.split(","); + const dims = req.query.dims; + if (dims && dims.includes("cap_code_pnad")){ + where += `pnad_novo.cod_cap <> 99`; + } + + console.log(where); + //dims.forEach((dim) => { + //if (dim.includes("cod_cap")) { + //filterId = dim.split(":")[1]; + //where += `pnad_novo.cod_cap != 99`; + //} + //}); + + return where; +} + superiorEducationConclusionTaxApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { req.querySet = []; - + let where = whereCondition(req); + // Subquery para total_pop_maior_25 com filtros dinâmicos let totalPopMaior25ComSuperiorCompleto = req.sql.clone(); totalPopMaior25ComSuperiorCompleto.from("pnad_novo") @@ -586,9 +604,10 @@ superiorEducationConclusionTaxApp.get('/', rqf.parse(), rqf.build(), (req, res, .where("idade_morador_31_03 >= 25") .where("nivel_de_instruc_mais_elevad_para_o_fundam_com_duracao_9_anos = 7") .where("ano_ref >= 2019") + .where(`${where}`) .group("ano_ref") .order("ano_ref"); - + // Subquery para total_pop_maior_25 com filtros dinâmicos let totalPopMaior25 = req.sql.clone(); @@ -597,14 +616,10 @@ superiorEducationConclusionTaxApp.get('/', rqf.parse(), rqf.build(), (req, res, .field("SUM(peso_domicilio_pessoas_com_cal)", "total") .where("idade_morador_31_03 >= 25") .where("ano_ref >= 2019") + .where(`${where}`) .group("ano_ref") .order("ano_ref"); - // if (req.query.dims && req.query.dims.includes("income_range")) { - // totalPopMaior19.where("faixa_rendimento_aux_tx is not null"); - // totalPopEdBasMaior19.where("faixa_rendimento_aux_tx is not null"); - // } - req.querySet.push(totalPopMaior25ComSuperiorCompleto); req.querySet.push(totalPopMaior25); -- GitLab From 40bbf1f7cc8477e093e941f7af9db6eec867e0fb Mon Sep 17 00:00:00 2001 From: es23 <es23@inf.ufpr.br> Date: Wed, 30 Apr 2025 10:05:15 -0300 Subject: [PATCH 22/45] fix faixa de renda familiar per capta --- src/libs/routes_v1/superiorEducationConclusionTax.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/libs/routes_v1/superiorEducationConclusionTax.js b/src/libs/routes_v1/superiorEducationConclusionTax.js index a8198668..0d682f12 100644 --- a/src/libs/routes_v1/superiorEducationConclusionTax.js +++ b/src/libs/routes_v1/superiorEducationConclusionTax.js @@ -157,6 +157,7 @@ superiorEducationConclusionTaxApp.get('/income_range', (req, res, next) => { }); } req.result.push({id: 10, name: id2str.incomeRange(10)}); + next(); }, response('income_range')); @@ -580,14 +581,9 @@ function whereCondition(req) { if (dims && dims.includes("cap_code_pnad")){ where += `pnad_novo.cod_cap <> 99`; } - - console.log(where); - //dims.forEach((dim) => { - //if (dim.includes("cod_cap")) { - //filterId = dim.split(":")[1]; - //where += `pnad_novo.cod_cap != 99`; - //} - //}); + if (dims && dims.includes("income_range")){ + where += `pnad_novo.faixa_rendimento_aux_tx is not null`; + } return where; } -- GitLab From 349c9c249a7beda59e35e1288a1dbfdc3ea39cf0 Mon Sep 17 00:00:00 2001 From: fgs21 <fgs21@inf.ufpr.br> Date: Wed, 30 Apr 2025 10:13:01 -0300 Subject: [PATCH 23/45] [REMOVE] Removing some trash files --- docker-compose.yml | 11 ----------- entrypoint.sh | 5 ----- gulpfile.template.js | 20 -------------------- script_req.sh | 10 ---------- 4 files changed, 46 deletions(-) delete mode 100644 docker-compose.yml delete mode 100644 entrypoint.sh delete mode 100644 gulpfile.template.js delete mode 100755 script_req.sh diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 85266ff9..00000000 --- a/docker-compose.yml +++ /dev/null @@ -1,11 +0,0 @@ -services: - simcaq-node: - container_name: simcaq-node - build: . - ports: - - '3000:3000' - develop: - watch: - - action: sync - path: . - target: /API diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100644 index 04db5192..00000000 --- a/entrypoint.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -echo "Starting simcaq-node" -gulp watch &> /dev/null & -cd build -NODE_ENV=production gulp run diff --git a/gulpfile.template.js b/gulpfile.template.js deleted file mode 100644 index 3de679df..00000000 --- a/gulpfile.template.js +++ /dev/null @@ -1,20 +0,0 @@ -const gulp = require('gulp'); - -const nodemon = require('gulp-nodemon'); - -gulp.task('run', () => { - // process.chdir('build'); - nodemon({ - script: 'server.js', - // tasks: ['watch'], - ignore: ["test/test.js", "gulpfile.babel.js"], - ext: 'js html json', - env: { 'NODE_ENV': process.env.NODE_ENV } - }); -}); - -gulp.task('default', () => { - console.log("Não execuatar apenas gulp, execute da forma:"); - console.log("\t\tgulp <task>"); -}); - diff --git a/script_req.sh b/script_req.sh deleted file mode 100755 index 125204b8..00000000 --- a/script_req.sh +++ /dev/null @@ -1,10 +0,0 @@ -curl -X 'POST' \ - 'http://10.254.221.20:3000/api/v1//auth/token' \ - -H 'accept: application/json' \ - -H 'Content-Type: application/json' \ - -d '{ - "email": "eduardomsouza@ufpr.br", - "password": "teste123", - "client_secret": "LDE", - "grant_type": "password" -}' \ No newline at end of file -- GitLab From 5327072deb1eddc1975ca4ac52034218134db9b8 Mon Sep 17 00:00:00 2001 From: es23 <es23@inf.ufpr.br> Date: Wed, 30 Apr 2025 10:37:51 -0300 Subject: [PATCH 24/45] fix faixa etaria --- src/libs/routes_v1/superiorEducationConclusionTax.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/routes_v1/superiorEducationConclusionTax.js b/src/libs/routes_v1/superiorEducationConclusionTax.js index 0d682f12..740d9a03 100644 --- a/src/libs/routes_v1/superiorEducationConclusionTax.js +++ b/src/libs/routes_v1/superiorEducationConclusionTax.js @@ -240,16 +240,17 @@ superiorEducationConclusionTaxApp.get('/state', (req, res, next) => { next(); }, response('state')); -superiorEducationConclusionTaxApp.get('/age_range', (req, res, next) => { +superiorEducationConclusionTaxApp.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) }); } + console.log(req.result); next(); -}, response('age_range')); +}, response('age_range_all')); superiorEducationConclusionTaxApp.get('/location', (req, res, next) => { req.result = [] -- GitLab From e8dce3bb2a250686ddd01a32c65267ef22c6180c Mon Sep 17 00:00:00 2001 From: es23 <es23@inf.ufpr.br> Date: Wed, 30 Apr 2025 10:52:04 -0300 Subject: [PATCH 25/45] fix name ageRangeAll --- src/libs/convert/ageRangeAll.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/convert/ageRangeAll.js b/src/libs/convert/ageRangeAll.js index 1ad1c54e..ebc2336a 100644 --- a/src/libs/convert/ageRangeAll.js +++ b/src/libs/convert/ageRangeAll.js @@ -18,7 +18,7 @@ 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) { +module.exports = function ageRangeAll(id) { switch (id) { case 1: return '0 a 3 anos'; -- GitLab From 730cd9147a44ca34af694680e8dbf3f7c876de38 Mon Sep 17 00:00:00 2001 From: es23 <es23@inf.ufpr.br> Date: Wed, 30 Apr 2025 11:07:26 -0300 Subject: [PATCH 26/45] fix filtro faixa etaria --- src/libs/routes_v1/superiorEducationConclusionTax.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libs/routes_v1/superiorEducationConclusionTax.js b/src/libs/routes_v1/superiorEducationConclusionTax.js index 740d9a03..d345b230 100644 --- a/src/libs/routes_v1/superiorEducationConclusionTax.js +++ b/src/libs/routes_v1/superiorEducationConclusionTax.js @@ -242,7 +242,7 @@ superiorEducationConclusionTaxApp.get('/state', (req, res, next) => { superiorEducationConclusionTaxApp.get('/age_range_all', (req, res, next) => { req.result = [] - for (let i = 1; i < 12; i++) { + for (let i = 7; i < 12; i++) { req.result.push({ id: i, name: id2str.ageRangeAll(i) }); @@ -585,6 +585,9 @@ function whereCondition(req) { if (dims && dims.includes("income_range")){ where += `pnad_novo.faixa_rendimento_aux_tx is not null`; } + if (dims && dims.includes("age_range_superior")){ + where += `pnad_novo.faixa_etaria > 6`; + } return where; } -- GitLab From 0e63ec5d0561fcfe87481e7baf69ddc1df256265 Mon Sep 17 00:00:00 2001 From: Lewis <lgtg20@inf.ufpr.br> Date: Tue, 6 May 2025 11:08:28 -0300 Subject: [PATCH 27/45] Fix student cost labels --- src/libs/middlewares/aggregateData.js | 2 +- src/libs/routes_v1/studentCost.js | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js index af02c0db..a46d7f77 100644 --- a/src/libs/middlewares/aggregateData.js +++ b/src/libs/middlewares/aggregateData.js @@ -39,7 +39,7 @@ const convert = { despesas_alunos: "expenses", receita_potencial: "potentialRevenue", receitas: "revenue", - despesas: "studentCost" + despesas: "revenue" } function aggregateData(req, res, next) { diff --git a/src/libs/routes_v1/studentCost.js b/src/libs/routes_v1/studentCost.js index 74aa91a2..5283e54d 100644 --- a/src/libs/routes_v1/studentCost.js +++ b/src/libs/routes_v1/studentCost.js @@ -133,17 +133,18 @@ studentCostApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { if (!typeFilter || (typeFilter && (!obj.state && !obj.city && !obj.region))) { req.sql.from('despesas') - .field('despesas.ano_censo', 'year') - .field('SUM(gasto_aluno_ano_publica)', 'total_gasto_aluno_ano_publica') - .field('SUM(gasto_aluno_mes_publica)', 'total_gasto_aluno_mes_publica') - .field('SUM(gasto_aluno_ano_publica_mais_conveniada)', 'total_gasto_aluno_ano_publica_mais_conveniada') - .field('SUM(gasto_aluno_mes_publica_mais_conveniada)', 'total_gasto_aluno_mes_publica_mais_conveniada') - .where(`${whereCondition}`) - .group('despesas.ano_censo') + .field('despesas.ano_censo', 'year') + .field(`SUM(despesas) / SUM(matriculas_publica)`, '(total_gasto_aluno_ano_publica)') + .field(`SUM(despesas) / SUM(matriculas_publica) / 12`, 'total_gasto_aluno_mes_publica') + .field(`SUM(despesas) / SUM(matriculas_publicas_mais_conveniada)`, 'total_gasto_aluno_ano_publica_mais_conveniada') + .field(`SUM(despesas) / SUM(matriculas_publicas_mais_conveniada) / 12`, 'total_gasto_aluno_mes_publica_mais_conveniada') + .where(`${whereCondition}`) + .group('despesas.ano_censo') + .order('despesas.ano_censo') } } next(); -}, query, aggregateData, id2str.transform(false), response('student_cost')); +}, query, aggregateData, response('student_cost')); module.exports = studentCostApp; -- GitLab From cbd1217f95fe99f432cf45aa946d766824175831 Mon Sep 17 00:00:00 2001 From: Lewis <lgtg20@inf.ufpr.br> Date: Fri, 9 May 2025 11:58:45 -0300 Subject: [PATCH 28/45] =?UTF-8?q?Update=20region=20and=20state=20name=20fo?= =?UTF-8?q?r=20'Exterior'=20to=20include=20'Curso=20=C3=A0=20dist=C3=A2nci?= =?UTF-8?q?a'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libs/convert/regionCode.js | 2 ++ src/libs/convert/stateName.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/convert/regionCode.js b/src/libs/convert/regionCode.js index fd215503..e2f2e729 100644 --- a/src/libs/convert/regionCode.js +++ b/src/libs/convert/regionCode.js @@ -30,5 +30,7 @@ module.exports = function regionCode(id) { return 'Sul' case 5: return 'Centro-Oeste'; + case 6: + return 'Exterior/Curso à distância'; } }; diff --git a/src/libs/convert/stateName.js b/src/libs/convert/stateName.js index 9254af00..0c37b0d4 100644 --- a/src/libs/convert/stateName.js +++ b/src/libs/convert/stateName.js @@ -75,7 +75,7 @@ module.exports = function stateName(id) { case 53: return 'Distrito Federal'; case 99: - return 'Exterior'; + return 'Exterior/Curso à distância'; default: return 'Não declarada'; } -- GitLab From 5e12a1a6881b7ba7a9633fc583a7a7bd337b634e Mon Sep 17 00:00:00 2001 From: fgs21 <fgs21@inf.ufpr.br> Date: Mon, 12 May 2025 10:31:26 -0300 Subject: [PATCH 29/45] [hotfix] capital filter working for superior education conclusion tax indicator AND gulpfile removed --- gulpfile.babel.js | 111 ------------------ .../superiorEducationConclusionTax.js | 10 +- 2 files changed, 5 insertions(+), 116 deletions(-) delete mode 100644 gulpfile.babel.js diff --git a/gulpfile.babel.js b/gulpfile.babel.js deleted file mode 100644 index 10a79259..00000000 --- a/gulpfile.babel.js +++ /dev/null @@ -1,111 +0,0 @@ -require('babel-core/register'); - -const gulp = require('gulp'); - -const babel = require('gulp-babel'); - -const eslint = require('gulp-eslint'); - -const mocha = require('gulp-mocha'); - -const istanbul = require('gulp-istanbul'); - -const nodemon = require('gulp-nodemon'); - -const Cache = require('gulp-file-cache'); - -const docco = require('gulp-docco'); - -const mkdirp = require('mkdirp'); - -const cache = new Cache(); - -function createLogDir() { - const logDirPath = 'build/logs'; - mkdirp(logDirPath, (err) => { - if(err) console.error(err); - }); -} - -gulp.task('lint', () => { - // run ESLint - gulp.src('src/**/*.js') - .pipe(eslint()) - .pipe(eslint.format()); -}) - -/** -* Compile source files -*/ -gulp.task('compile', ['lint'], () => { - - // compile source to ES5 - gulp.src('src/**/*.js') - .pipe(cache.filter()) // cache source files - .pipe(babel()) // compile only modified files - .pipe(cache.cache()) // cache compiled files - .pipe(gulp.dest('build')); // move compiled files to build directory -}); - -gulp.task('build', ['compile'], () => { - var filesToCopy = [ 'config.json', 'package.json', '.eslintignore', '.eslintrc.json' ]; - // copy configuration file to build directory - gulp.src(filesToCopy) - .pipe(gulp.dest('build')); - - createLogDir(); -}); - -gulp.task('docco', () => { - gulp.src('./src/**/*.js') - .pipe(docco()) - .pipe(gulp.dest('./docs')); -}); - -gulp.task('doc', ['docco']); - -gulp.task('pre-test', () => { - return gulp.src(['build/**/*.js', '!build/{test,test/**}']) - .pipe(istanbul()) - .pipe(istanbul.hookRequire()); -}); - -gulp.task('test', ['pre-test'], () => { - process.chdir('build'); - gulp.src(['test/**/*.js'], {read: false}) - .pipe(mocha({timeout: 60000})) - .pipe(istanbul.writeReports()) - .pipe(istanbul.enforceThresholds({ - thresholds: { - global: { - statements: 80, - branches: 70, - lines: 80, - functions: 80 - } - } - })) - .on('error', () => { - process.exit(1); - }) - .on('end', () => { - process.exit(); - }); -}); - -gulp.task('watch', () => { - console.log('Watching source directory for changes'); - return gulp.watch('src/**/*.js').on('change', () => { - console.log('Recompiling source'); - gulp.start('compile'); - console.log('Source recompilation done'); - }); -}); - -gulp.task('default', () => { - console.log("Não execuatar apenas gulp, execute da forma:"); - console.log("\t\tgulp <task>"); -}); - -gulp.task('default', ['run']); - diff --git a/src/libs/routes_v1/superiorEducationConclusionTax.js b/src/libs/routes_v1/superiorEducationConclusionTax.js index d345b230..3b038a92 100644 --- a/src/libs/routes_v1/superiorEducationConclusionTax.js +++ b/src/libs/routes_v1/superiorEducationConclusionTax.js @@ -111,7 +111,7 @@ superiorEducationConclusionTaxApp.get('/region', (req, res, next) => { next(); }, response('region')); -superiorEducationConclusionTaxApp.get('/cap_code_pnad', (req, res, next) => { +superiorEducationConclusionTaxApp.get('/cap_code', (req, res, next) => { req.result = [] for (let i = 11; i < 54; i++) { if (id2str.capitalCode(i) !== 'Não informado') { @@ -121,7 +121,7 @@ superiorEducationConclusionTaxApp.get('/cap_code_pnad', (req, res, next) => { } } next(); -}, response('cap_code_pnad')); +}, response('cap_code')); superiorEducationConclusionTaxApp.get('/metro_code', (req, res, next) => { req.result = [] @@ -443,10 +443,10 @@ rqf.addField({ field: 'sexo' } }).addValue({ - name: 'cap_code_pnad', + name: 'cap_code', table: 'pnad_novo', tableField: 'cod_cap', - resultField: 'cap_code_pnad_id', + resultField: 'cap_code_id', where: { relation: '=', type: 'integer', @@ -579,7 +579,7 @@ function whereCondition(req) { let filterId; //const filters = req.query.filter.split(","); const dims = req.query.dims; - if (dims && dims.includes("cap_code_pnad")){ + if (dims && dims.includes("cap_code")){ where += `pnad_novo.cod_cap <> 99`; } if (dims && dims.includes("income_range")){ -- GitLab From 81442a9de20567fa27cb3c6a68d9e413033ccdd1 Mon Sep 17 00:00:00 2001 From: fgs21 <fgs21@inf.ufpr.br> Date: Fri, 16 May 2025 11:56:46 -0300 Subject: [PATCH 30/45] [hotfix] university filter and dimension now working for 2023 in 'Numero de Cursos de 2020 a 2023' indicator --- 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 78ae89a7..fdc6bd88 100644 --- a/src/libs/routes_v1/courseAggregate.js +++ b/src/libs/routes_v1/courseAggregate.js @@ -316,7 +316,7 @@ rqf.addField({ field: 'cod_cine_area_detalhada' } }).addValue({ - name: 'uni_offer_aggregate', + name: 'university', table: 'ies_ens_superior', tableField: ['cod_ies', 'nome_ies'], resultField: ['university_id', 'university_name'], -- GitLab From ea1a0a37a6771feaca1cacb4845bc0c721e26ef5 Mon Sep 17 00:00:00 2001 From: tgcl21 <tgcl21@inf.ufpr.br> Date: Fri, 16 May 2025 15:48:00 -0300 Subject: [PATCH 31/45] Fixed the the wrong total errors --- src/libs/routes_v1/instructionLevel.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/routes_v1/instructionLevel.js b/src/libs/routes_v1/instructionLevel.js index d3cb7d0c..aa083380 100644 --- a/src/libs/routes_v1/instructionLevel.js +++ b/src/libs/routes_v1/instructionLevel.js @@ -291,7 +291,6 @@ NivelInstrucao.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .field('nivel_de_instrucao', 'nivel') .field('round(sum(peso_domicilio_pessoas_com_cal), 0)', 'total') .field('ano_ref', 'year') - .where('nivel_de_instrucao <> 99') .where('faixa_etaria <> 99') .group('pnad_novo.ano_ref') .group('pnad_novo.nivel_de_instrucao') -- GitLab From a1a27edd3b3949da3028505d140bb8a4eb18d0f4 Mon Sep 17 00:00:00 2001 From: es23 <es23@inf.ufpr.br> Date: Tue, 20 May 2025 10:22:51 -0300 Subject: [PATCH 32/45] fix income range null field --- src/libs/routes_v1/studentsReceivingAidTax.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/libs/routes_v1/studentsReceivingAidTax.js b/src/libs/routes_v1/studentsReceivingAidTax.js index c4509cf8..b515e376 100644 --- a/src/libs/routes_v1/studentsReceivingAidTax.js +++ b/src/libs/routes_v1/studentsReceivingAidTax.js @@ -578,8 +578,21 @@ function matchQueries(queryPartial, queryTotal) { return match; } +function whereCondition(req) { + let where = ""; + + const dims = req.query.dims; + if (dims && dims.includes("income_range")){ + where += `pnad_novo.faixa_rendimento_aux_tx is not null`; + } + + + return where; +} + studentsReceivingAidTaxApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { req.querySet = []; + let where = whereCondition(req); // Subquery para total_pop_maior_25 com filtros dinâmicos let totalEstudantesQueRecebemAuxilio = req.sql.clone(); @@ -587,6 +600,7 @@ studentsReceivingAidTaxApp.get('/', rqf.parse(), rqf.build(), (req, res, next) = .field("ano_ref", "year") .field("SUM(peso_domicilio_pessoas_com_cal)", "total") .where("recebeu_rendimentos_de_programa_bolsa_familia = 1") + .where(`${where}`) .where("frequenta_escola = 1") .where("ano_ref >= 2019") .group("ano_ref") @@ -598,7 +612,9 @@ studentsReceivingAidTaxApp.get('/', rqf.parse(), rqf.build(), (req, res, next) = totalEstudantes.from("pnad_novo") .field("ano_ref", "year") .field("SUM(peso_domicilio_pessoas_com_cal)", "total") + .where(`${where}`) .where("frequenta_escola = 1") + .where("ano_ref >= 2019") .group("ano_ref") .order("ano_ref"); -- GitLab From bf5128ae2994eb8d01a2522762349e499f7fcec3 Mon Sep 17 00:00:00 2001 From: fgs21 <fgs21@inf.ufpr.br> Date: Tue, 20 May 2025 11:50:13 -0300 Subject: [PATCH 33/45] [hotfix] Solving aggregate enrollment city dimension problem --- src/libs/middlewares/aggregateData.js | 2 +- src/libs/routes_v1/enrollmentAggregate.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js index a46d7f77..8dbf01d7 100644 --- a/src/libs/middlewares/aggregateData.js +++ b/src/libs/middlewares/aggregateData.js @@ -72,7 +72,7 @@ function aggregateData(req, res, next) { 'receita_potencial', 'despesas' ]; - const baseFields = ["school"] + const baseFields = ["school", "city"] let id; const fields = req.query.dims.split(','); let currentAggregateField; diff --git a/src/libs/routes_v1/enrollmentAggregate.js b/src/libs/routes_v1/enrollmentAggregate.js index a561f137..db09b08d 100644 --- a/src/libs/routes_v1/enrollmentAggregate.js +++ b/src/libs/routes_v1/enrollmentAggregate.js @@ -400,7 +400,8 @@ rqf.addField({ where: { relation: '=', type: 'integer', - field: 'id' + field: 'municipio_id', + table: 'escola' }, join: { primary: 'id', -- GitLab From f7240405b47b5de5f633ce5a92ae14623366ca39 Mon Sep 17 00:00:00 2001 From: es23 <es23@inf.ufpr.br> Date: Wed, 21 May 2025 10:24:44 -0300 Subject: [PATCH 34/45] fix age range filter --- src/libs/convert/ageRangeAll.js | 2 +- src/libs/routes_v1/studentsReceivingAidTax.js | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libs/convert/ageRangeAll.js b/src/libs/convert/ageRangeAll.js index 1ad1c54e..ebc2336a 100644 --- a/src/libs/convert/ageRangeAll.js +++ b/src/libs/convert/ageRangeAll.js @@ -18,7 +18,7 @@ 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) { +module.exports = function ageRangeAll(id) { switch (id) { case 1: return '0 a 3 anos'; diff --git a/src/libs/routes_v1/studentsReceivingAidTax.js b/src/libs/routes_v1/studentsReceivingAidTax.js index b515e376..16547bfd 100644 --- a/src/libs/routes_v1/studentsReceivingAidTax.js +++ b/src/libs/routes_v1/studentsReceivingAidTax.js @@ -242,7 +242,7 @@ studentsReceivingAidTaxApp.get('/state', (req, res, next) => { next(); }, response('state')); -studentsReceivingAidTaxApp.get('/age_range', (req, res, next) => { +studentsReceivingAidTaxApp.get('/age_range_all', (req, res, next) => { req.result = [] for (let i = 1; i < 12; i++) { req.result.push({ @@ -251,7 +251,7 @@ studentsReceivingAidTaxApp.get('/age_range', (req, res, next) => { } next(); -}, response('age_range')); +}, response('age_range_all')); studentsReceivingAidTaxApp.get('/location', (req, res, next) => { req.result = [] @@ -618,7 +618,6 @@ studentsReceivingAidTaxApp.get('/', rqf.parse(), rqf.build(), (req, res, next) = .group("ano_ref") .order("ano_ref"); - req.querySet.push(totalEstudantesQueRecebemAuxilio); req.querySet.push(totalEstudantes); -- GitLab From 877de5b65ab37df70734f25153d6b64a1c38c263 Mon Sep 17 00:00:00 2001 From: Joao Pedro <jpv.ramalho2013@gmail.com> Date: Thu, 22 May 2025 09:24:54 -0300 Subject: [PATCH 35/45] [fix] arredondando para duas casas decimais --- src/libs/routes_v1/expenses.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/routes_v1/expenses.js b/src/libs/routes_v1/expenses.js index 36248659..624609e8 100644 --- a/src/libs/routes_v1/expenses.js +++ b/src/libs/routes_v1/expenses.js @@ -126,13 +126,13 @@ ExpensesApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .field('despesas.ano_censo', 'year') .field('despesas.ano_censo', 'total_ano') .field('despesas.nome_ente', 'total_nome_ente') - .field('despesas.despesas', 'total_despesas') + .field('round(despesas.despesas,2)', 'total_despesas') .field('matriculas_publica', 'total_matriculas_publica') .field('matriculas_publicas_mais_conveniada', 'total_matriculas_publicas_mais_conveniada') - .field('gasto_aluno_ano_publica', 'total_gasto_aluno_ano_publica') - .field('gasto_aluno_mes_publica', 'total_gasto_aluno_mes_publica') - .field('gasto_aluno_ano_publica_mais_conveniada', 'total_gasto_aluno_ano_publica_mais_conveniada') - .field('gasto_aluno_mes_publica_mais_conveniada', 'total_gasto_aluno_mes_publica_mais_conveniada') + .field('round(gasto_aluno_ano_publica,2)', 'total_gasto_aluno_ano_publica') + .field('round(gasto_aluno_mes_publica,2)', 'total_gasto_aluno_mes_publica') + .field('round(gasto_aluno_ano_publica_mais_conveniada,2)', 'total_gasto_aluno_ano_publica_mais_conveniada') + .field('round(gasto_aluno_mes_publica_mais_conveniada,2)', 'total_gasto_aluno_mes_publica_mais_conveniada') .where(`${whereCondition}`) .order('despesas.ano_censo') } -- GitLab From 965d4d1c30135cb9ed9cb189b7062ae398065f23 Mon Sep 17 00:00:00 2001 From: Fernando Gbur dos Santos <fgs21@inf.ufpr.br> Date: Thu, 22 May 2025 13:14:03 +0000 Subject: [PATCH 36/45] Development --- src/libs/routes_v1/expenses.js | 10 ++++----- src/libs/routes_v1/instructionLevel.js | 1 - src/libs/routes_v1/studentsReceivingAidTax.js | 21 ++++++++++++++++--- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/libs/routes_v1/expenses.js b/src/libs/routes_v1/expenses.js index 36248659..624609e8 100644 --- a/src/libs/routes_v1/expenses.js +++ b/src/libs/routes_v1/expenses.js @@ -126,13 +126,13 @@ ExpensesApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .field('despesas.ano_censo', 'year') .field('despesas.ano_censo', 'total_ano') .field('despesas.nome_ente', 'total_nome_ente') - .field('despesas.despesas', 'total_despesas') + .field('round(despesas.despesas,2)', 'total_despesas') .field('matriculas_publica', 'total_matriculas_publica') .field('matriculas_publicas_mais_conveniada', 'total_matriculas_publicas_mais_conveniada') - .field('gasto_aluno_ano_publica', 'total_gasto_aluno_ano_publica') - .field('gasto_aluno_mes_publica', 'total_gasto_aluno_mes_publica') - .field('gasto_aluno_ano_publica_mais_conveniada', 'total_gasto_aluno_ano_publica_mais_conveniada') - .field('gasto_aluno_mes_publica_mais_conveniada', 'total_gasto_aluno_mes_publica_mais_conveniada') + .field('round(gasto_aluno_ano_publica,2)', 'total_gasto_aluno_ano_publica') + .field('round(gasto_aluno_mes_publica,2)', 'total_gasto_aluno_mes_publica') + .field('round(gasto_aluno_ano_publica_mais_conveniada,2)', 'total_gasto_aluno_ano_publica_mais_conveniada') + .field('round(gasto_aluno_mes_publica_mais_conveniada,2)', 'total_gasto_aluno_mes_publica_mais_conveniada') .where(`${whereCondition}`) .order('despesas.ano_censo') } diff --git a/src/libs/routes_v1/instructionLevel.js b/src/libs/routes_v1/instructionLevel.js index d3cb7d0c..aa083380 100644 --- a/src/libs/routes_v1/instructionLevel.js +++ b/src/libs/routes_v1/instructionLevel.js @@ -291,7 +291,6 @@ NivelInstrucao.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .field('nivel_de_instrucao', 'nivel') .field('round(sum(peso_domicilio_pessoas_com_cal), 0)', 'total') .field('ano_ref', 'year') - .where('nivel_de_instrucao <> 99') .where('faixa_etaria <> 99') .group('pnad_novo.ano_ref') .group('pnad_novo.nivel_de_instrucao') diff --git a/src/libs/routes_v1/studentsReceivingAidTax.js b/src/libs/routes_v1/studentsReceivingAidTax.js index c4509cf8..16547bfd 100644 --- a/src/libs/routes_v1/studentsReceivingAidTax.js +++ b/src/libs/routes_v1/studentsReceivingAidTax.js @@ -242,7 +242,7 @@ studentsReceivingAidTaxApp.get('/state', (req, res, next) => { next(); }, response('state')); -studentsReceivingAidTaxApp.get('/age_range', (req, res, next) => { +studentsReceivingAidTaxApp.get('/age_range_all', (req, res, next) => { req.result = [] for (let i = 1; i < 12; i++) { req.result.push({ @@ -251,7 +251,7 @@ studentsReceivingAidTaxApp.get('/age_range', (req, res, next) => { } next(); -}, response('age_range')); +}, response('age_range_all')); studentsReceivingAidTaxApp.get('/location', (req, res, next) => { req.result = [] @@ -578,8 +578,21 @@ function matchQueries(queryPartial, queryTotal) { return match; } +function whereCondition(req) { + let where = ""; + + const dims = req.query.dims; + if (dims && dims.includes("income_range")){ + where += `pnad_novo.faixa_rendimento_aux_tx is not null`; + } + + + return where; +} + studentsReceivingAidTaxApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { req.querySet = []; + let where = whereCondition(req); // Subquery para total_pop_maior_25 com filtros dinâmicos let totalEstudantesQueRecebemAuxilio = req.sql.clone(); @@ -587,6 +600,7 @@ studentsReceivingAidTaxApp.get('/', rqf.parse(), rqf.build(), (req, res, next) = .field("ano_ref", "year") .field("SUM(peso_domicilio_pessoas_com_cal)", "total") .where("recebeu_rendimentos_de_programa_bolsa_familia = 1") + .where(`${where}`) .where("frequenta_escola = 1") .where("ano_ref >= 2019") .group("ano_ref") @@ -598,11 +612,12 @@ studentsReceivingAidTaxApp.get('/', rqf.parse(), rqf.build(), (req, res, next) = totalEstudantes.from("pnad_novo") .field("ano_ref", "year") .field("SUM(peso_domicilio_pessoas_com_cal)", "total") + .where(`${where}`) .where("frequenta_escola = 1") + .where("ano_ref >= 2019") .group("ano_ref") .order("ano_ref"); - req.querySet.push(totalEstudantesQueRecebemAuxilio); req.querySet.push(totalEstudantes); -- GitLab From c31b81cc1dbe1695f5424cd973ca423d8fea855d Mon Sep 17 00:00:00 2001 From: Joao Pedro <jpv.ramalho2013@gmail.com> Date: Wed, 28 May 2025 09:32:16 -0300 Subject: [PATCH 37/45] [fix] retirou as colunas desnecessarias da tabela --- src/libs/middlewares/aggregateData.js | 2 ++ src/libs/routes_v1/expenses.js | 44 +++++++++++---------------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js index 8dbf01d7..0aab0341 100644 --- a/src/libs/middlewares/aggregateData.js +++ b/src/libs/middlewares/aggregateData.js @@ -78,6 +78,7 @@ function aggregateData(req, res, next) { let currentAggregateField; let currentNonAggregateField; + console.log("data pre aggregate" ,req.result) // Verifica se o filtro passado está presente nos filtros agregados fields.forEach(field => {if (aggregateFields.includes(field)) currentAggregateField = field; else currentNonAggregateField = field}); if (currentAggregateField) { @@ -109,6 +110,7 @@ function aggregateData(req, res, next) { req.result = newResult; } } + console.log("data pos aggregate" ,req.result) next(); } diff --git a/src/libs/routes_v1/expenses.js b/src/libs/routes_v1/expenses.js index 624609e8..40f41166 100644 --- a/src/libs/routes_v1/expenses.js +++ b/src/libs/routes_v1/expenses.js @@ -111,33 +111,25 @@ rqf.addField({ ExpensesApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { - if (req.query.dims && req.query.dims.includes('despesas')) { - let whereCondition = req.query.filter.includes("region") ? "" : "despesas.cod_ibge = 0"; - let filterId; - const filters = req.query.filter.split(","); - filters.forEach((filter) => { - if (filter.includes("state") || filter.includes("city")) { - filterId = Number(filter.split(":")[1].replace(/"/g, "")); - whereCondition = `despesas.cod_ibge = ${filterId}` - } - }) - - req.sql.from('despesas') - .field('despesas.ano_censo', 'year') - .field('despesas.ano_censo', 'total_ano') - .field('despesas.nome_ente', 'total_nome_ente') - .field('round(despesas.despesas,2)', 'total_despesas') - .field('matriculas_publica', 'total_matriculas_publica') - .field('matriculas_publicas_mais_conveniada', 'total_matriculas_publicas_mais_conveniada') - .field('round(gasto_aluno_ano_publica,2)', 'total_gasto_aluno_ano_publica') - .field('round(gasto_aluno_mes_publica,2)', 'total_gasto_aluno_mes_publica') - .field('round(gasto_aluno_ano_publica_mais_conveniada,2)', 'total_gasto_aluno_ano_publica_mais_conveniada') - .field('round(gasto_aluno_mes_publica_mais_conveniada,2)', 'total_gasto_aluno_mes_publica_mais_conveniada') - .where(`${whereCondition}`) - .order('despesas.ano_censo') - } + let whereCondition = req.query.filter.includes("region") ? "" : "despesas.cod_ibge = 0"; + let filterId; + const filters = req.query.filter.split(","); + filters.forEach((filter) => { + if (filter.includes("state") || filter.includes("city")) { + filterId = Number(filter.split(":")[1].replace(/"/g, "")); + whereCondition = `despesas.cod_ibge = ${filterId}` + } + }) + req.sql.from('despesas') + .field('despesas.ano_censo', 'year') + .field('despesas.ano_censo', 'total_ano') + .field('despesas.nome_ente', 'total_nome_ente') + .field('round(despesas.despesas,2)', 'total') + .where(`${whereCondition}`) + .order('despesas.ano_censo') + next(); -}, query, aggregateData, id2str.transform(false), response('expenses')); +}, query, id2str.transform(false), response('expenses')); module.exports = ExpensesApp; \ No newline at end of file -- GitLab From 537bdef25e53cdf2bf3e8996c204db5d46b23465 Mon Sep 17 00:00:00 2001 From: Joao Pedro <jpv.ramalho2013@gmail.com> Date: Wed, 28 May 2025 11:19:38 -0300 Subject: [PATCH 38/45] [fix] filtros por rede --- src/libs/routes_v1/expenses.js | 43 +++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/src/libs/routes_v1/expenses.js b/src/libs/routes_v1/expenses.js index 40f41166..0e578f2e 100644 --- a/src/libs/routes_v1/expenses.js +++ b/src/libs/routes_v1/expenses.js @@ -51,6 +51,14 @@ ExpensesApp.get('/years', (req, res, next) => { next(); }, query, response('years')) +ExpensesApp.get('/type', (req, res, next) => { + req.result = [] + + req.result.push({ id: 1, name: "Rede Estadual" }); + req.result.push({ id: 2, name: "Rede Municipal" }); + next(); +}, response('type')); + // rqf.addValue({ // name: 'location', // table: 'despesas', @@ -111,6 +119,8 @@ rqf.addField({ ExpensesApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + let obj = {} + let typeFilter = false; let whereCondition = req.query.filter.includes("region") ? "" : "despesas.cod_ibge = 0"; let filterId; const filters = req.query.filter.split(","); @@ -121,14 +131,31 @@ ExpensesApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { } }) - req.sql.from('despesas') - .field('despesas.ano_censo', 'year') - .field('despesas.ano_censo', 'total_ano') - .field('despesas.nome_ente', 'total_nome_ente') - .field('round(despesas.despesas,2)', 'total') - .where(`${whereCondition}`) - .order('despesas.ano_censo') - + if (req.query.filter) { + const jsonString = `{${req.query.filter.replace(/(\w+):/g, '"$1":')}}`; + obj = JSON.parse(jsonString); + if (obj.type) { + if (obj.type.includes("1") && !obj.type.includes("2")) { + whereCondition = "despesas.cod_ibge >= 11 and despesas.cod_ibge <= 53" + } + else if (obj.type.includes("2") && !obj.type.includes("1")) { + whereCondition = "despesas.cod_ibge > 53" + } + + typeFilter = true; + } + } + + if (!typeFilter || (typeFilter && (!obj.state && !obj.city && !obj.region))) { + req.sql.from('despesas') + .field('despesas.ano_censo', 'year') + .field('despesas.ano_censo', 'total_ano') + .field('despesas.nome_ente', 'total_nome_ente') + .field('round(despesas.despesas,2)', 'total') + .where(`${whereCondition}`) + .order('despesas.ano_censo') + } + next(); }, query, id2str.transform(false), response('expenses')); -- GitLab From 125b8a4d593e97682419824b1b6e5bd0f06ba85f Mon Sep 17 00:00:00 2001 From: Fernando Gbur dos Santos <fgs21@inf.ufpr.br> Date: Wed, 28 May 2025 14:43:56 +0000 Subject: [PATCH 39/45] Edit aggregateData.js --- src/libs/middlewares/aggregateData.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js index 0aab0341..8dbf01d7 100644 --- a/src/libs/middlewares/aggregateData.js +++ b/src/libs/middlewares/aggregateData.js @@ -78,7 +78,6 @@ function aggregateData(req, res, next) { let currentAggregateField; let currentNonAggregateField; - console.log("data pre aggregate" ,req.result) // Verifica se o filtro passado está presente nos filtros agregados fields.forEach(field => {if (aggregateFields.includes(field)) currentAggregateField = field; else currentNonAggregateField = field}); if (currentAggregateField) { @@ -110,7 +109,6 @@ function aggregateData(req, res, next) { req.result = newResult; } } - console.log("data pos aggregate" ,req.result) next(); } -- GitLab From b0bee54b7ca0abddf8df127e8d551f0cb328e609 Mon Sep 17 00:00:00 2001 From: Joao Pedro <jpv.ramalho2013@gmail.com> Date: Fri, 30 May 2025 10:42:57 -0300 Subject: [PATCH 40/45] [fix] somar registros para filtro de rede --- src/libs/routes_v1/expenses.js | 76 ++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/src/libs/routes_v1/expenses.js b/src/libs/routes_v1/expenses.js index 0e578f2e..a761b108 100644 --- a/src/libs/routes_v1/expenses.js +++ b/src/libs/routes_v1/expenses.js @@ -117,46 +117,58 @@ rqf.addField({ }) -ExpensesApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { - - let obj = {} +ExpensesApp.get( + '/', + rqf.parse(), + rqf.build(), + (req, res, next) => { + let obj = {}; let typeFilter = false; - let whereCondition = req.query.filter.includes("region") ? "" : "despesas.cod_ibge = 0"; + // condição inicial padrão (sem filtro de região, coloca cod_ibge = 0 só para não quebrar a query) + let whereCondition = req.query.filter.includes('region') + ? '' + : 'despesas.cod_ibge = 0'; let filterId; - const filters = req.query.filter.split(","); + const filters = req.query.filter.split(','); + + // Se houver filtro de estado/cidade, ajusta o cod_ibge filters.forEach((filter) => { - if (filter.includes("state") || filter.includes("city")) { - filterId = Number(filter.split(":")[1].replace(/"/g, "")); - whereCondition = `despesas.cod_ibge = ${filterId}` - } - }) + if (filter.includes('state') || filter.includes('city')) { + filterId = Number(filter.split(':')[1].replace(/"/g, '')); + whereCondition = `despesas.cod_ibge = ${filterId}`; + } + }); + // Interpreta o JSON de filtros; se tiver “type”, ajusta o where para agregar por tipo if (req.query.filter) { - const jsonString = `{${req.query.filter.replace(/(\w+):/g, '"$1":')}}`; - obj = JSON.parse(jsonString); - if (obj.type) { - if (obj.type.includes("1") && !obj.type.includes("2")) { - whereCondition = "despesas.cod_ibge >= 11 and despesas.cod_ibge <= 53" - } - else if (obj.type.includes("2") && !obj.type.includes("1")) { - whereCondition = "despesas.cod_ibge > 53" - } - - typeFilter = true; + const jsonString = `{${req.query.filter.replace(/(\w+):/g, '"$1":')}}`; + obj = JSON.parse(jsonString); + + if (obj.type) { + // Se vier só “1” (por exemplo, Unidades Federativas) + if (obj.type.includes('1') && !obj.type.includes('2')) { + whereCondition = 'despesas.cod_ibge >= 11 AND despesas.cod_ibge <= 53'; } + // Se vier só “2” (Municípios) + else if (obj.type.includes('2') && !obj.type.includes('1')) { + whereCondition = 'despesas.cod_ibge > 53'; + } + typeFilter = true; + } } - if (!typeFilter || (typeFilter && (!obj.state && !obj.city && !obj.region))) { - req.sql.from('despesas') - .field('despesas.ano_censo', 'year') - .field('despesas.ano_censo', 'total_ano') - .field('despesas.nome_ente', 'total_nome_ente') - .field('round(despesas.despesas,2)', 'total') - .where(`${whereCondition}`) - .order('despesas.ano_censo') - } + req.sql + .from('despesas') + .field('despesas.ano_censo', 'year') + .field('SUM(ROUND(despesas.despesas, 2))', 'total') + .where(whereCondition) + .group('despesas.ano_censo') + .order('despesas.ano_censo'); next(); -}, query, id2str.transform(false), response('expenses')); - + }, + query, + id2str.transform(false), + response('expenses') +); module.exports = ExpensesApp; \ No newline at end of file -- GitLab From 31f48959cb94fdfa1a28f3ce0a637651ffb29a2c Mon Sep 17 00:00:00 2001 From: Fernando Gbur dos Santos <fgs21@inf.ufpr.br> Date: Mon, 2 Jun 2025 13:21:57 +0000 Subject: [PATCH 41/45] Development --- src/libs/routes_v1/expenses.js | 76 ++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/src/libs/routes_v1/expenses.js b/src/libs/routes_v1/expenses.js index 0e578f2e..a761b108 100644 --- a/src/libs/routes_v1/expenses.js +++ b/src/libs/routes_v1/expenses.js @@ -117,46 +117,58 @@ rqf.addField({ }) -ExpensesApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { - - let obj = {} +ExpensesApp.get( + '/', + rqf.parse(), + rqf.build(), + (req, res, next) => { + let obj = {}; let typeFilter = false; - let whereCondition = req.query.filter.includes("region") ? "" : "despesas.cod_ibge = 0"; + // condição inicial padrão (sem filtro de região, coloca cod_ibge = 0 só para não quebrar a query) + let whereCondition = req.query.filter.includes('region') + ? '' + : 'despesas.cod_ibge = 0'; let filterId; - const filters = req.query.filter.split(","); + const filters = req.query.filter.split(','); + + // Se houver filtro de estado/cidade, ajusta o cod_ibge filters.forEach((filter) => { - if (filter.includes("state") || filter.includes("city")) { - filterId = Number(filter.split(":")[1].replace(/"/g, "")); - whereCondition = `despesas.cod_ibge = ${filterId}` - } - }) + if (filter.includes('state') || filter.includes('city')) { + filterId = Number(filter.split(':')[1].replace(/"/g, '')); + whereCondition = `despesas.cod_ibge = ${filterId}`; + } + }); + // Interpreta o JSON de filtros; se tiver “type”, ajusta o where para agregar por tipo if (req.query.filter) { - const jsonString = `{${req.query.filter.replace(/(\w+):/g, '"$1":')}}`; - obj = JSON.parse(jsonString); - if (obj.type) { - if (obj.type.includes("1") && !obj.type.includes("2")) { - whereCondition = "despesas.cod_ibge >= 11 and despesas.cod_ibge <= 53" - } - else if (obj.type.includes("2") && !obj.type.includes("1")) { - whereCondition = "despesas.cod_ibge > 53" - } - - typeFilter = true; + const jsonString = `{${req.query.filter.replace(/(\w+):/g, '"$1":')}}`; + obj = JSON.parse(jsonString); + + if (obj.type) { + // Se vier só “1” (por exemplo, Unidades Federativas) + if (obj.type.includes('1') && !obj.type.includes('2')) { + whereCondition = 'despesas.cod_ibge >= 11 AND despesas.cod_ibge <= 53'; } + // Se vier só “2” (Municípios) + else if (obj.type.includes('2') && !obj.type.includes('1')) { + whereCondition = 'despesas.cod_ibge > 53'; + } + typeFilter = true; + } } - if (!typeFilter || (typeFilter && (!obj.state && !obj.city && !obj.region))) { - req.sql.from('despesas') - .field('despesas.ano_censo', 'year') - .field('despesas.ano_censo', 'total_ano') - .field('despesas.nome_ente', 'total_nome_ente') - .field('round(despesas.despesas,2)', 'total') - .where(`${whereCondition}`) - .order('despesas.ano_censo') - } + req.sql + .from('despesas') + .field('despesas.ano_censo', 'year') + .field('SUM(ROUND(despesas.despesas, 2))', 'total') + .where(whereCondition) + .group('despesas.ano_censo') + .order('despesas.ano_censo'); next(); -}, query, id2str.transform(false), response('expenses')); - + }, + query, + id2str.transform(false), + response('expenses') +); module.exports = ExpensesApp; \ No newline at end of file -- GitLab From 3d4965b9cedfb224685f3c4fd6369ca17853542c Mon Sep 17 00:00:00 2001 From: fgs21 <fgs21@inf.ufpr.br> Date: Tue, 3 Jun 2025 11:38:54 -0300 Subject: [PATCH 42/45] =?UTF-8?q?[hotfix]=20'Exterior'=20Category=20remove?= =?UTF-8?q?d=20from=20'Taxa=20de=20Conclus=C3=A3o=20da=20Educa=C3=A7=C3=A3?= =?UTF-8?q?o=20Superior'=20indicator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libs/routes_v1/superiorEducationConclusionTax.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/routes_v1/superiorEducationConclusionTax.js b/src/libs/routes_v1/superiorEducationConclusionTax.js index 3b038a92..5a21db62 100644 --- a/src/libs/routes_v1/superiorEducationConclusionTax.js +++ b/src/libs/routes_v1/superiorEducationConclusionTax.js @@ -102,7 +102,7 @@ superiorEducationConclusionTaxApp.get('/new_pnad_adm_dependency', (req, res, nex superiorEducationConclusionTaxApp.get('/region', (req, res, next) => { req.result = [] - for (let i = 1; i < 6; i++) { + for (let i = 1; i < 5; i++) { req.result.push({ id: i, name: id2str.regionCode(i) }); @@ -247,7 +247,6 @@ superiorEducationConclusionTaxApp.get('/age_range_all', (req, res, next) => { id: i, name: id2str.ageRangeAll(i) }); } - console.log(req.result); next(); }, response('age_range_all')); -- GitLab From 7fffedd295d6ab31dee1c7578455a13727e66eb8 Mon Sep 17 00:00:00 2001 From: fgs21 <fgs21@inf.ufpr.br> Date: Mon, 9 Jun 2025 10:41:25 -0300 Subject: [PATCH 43/45] [hotfix] matriculas 2021 2023 indicador city filter working --- src/libs/routes_v1/enrollmentAggregate.js | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/libs/routes_v1/enrollmentAggregate.js b/src/libs/routes_v1/enrollmentAggregate.js index db09b08d..31c421e1 100644 --- a/src/libs/routes_v1/enrollmentAggregate.js +++ b/src/libs/routes_v1/enrollmentAggregate.js @@ -392,7 +392,7 @@ rqf.addField({ foreign: 'estado_id', foreignTable: 'escola' } -}, 'filter').addValueToField({ +}, 'filter').addValue({ name: 'city', table: 'municipio', tableField: ['nome', 'id'], @@ -408,22 +408,7 @@ rqf.addField({ 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({ +}).addValueToField({ name: 'school', table: 'escola', tableField: ['nome_escola', 'id'], -- GitLab From 320f7eafc9872cfeac5478dfd01ecd109becec2a Mon Sep 17 00:00:00 2001 From: fgs21 <fgs21@inf.ufpr.br> Date: Thu, 12 Jun 2025 11:07:51 -0300 Subject: [PATCH 44/45] [hotfix] Removing some console.log() and fixing 'population out of school' results to 1 decimal place --- src/libs/routes_v1/courseAggregate.js | 1 - src/libs/routes_v1/enrollmentAggregate.js | 1 + src/libs/routes_v1/populationOutOfSchool.js | 6 +----- src/libs/routes_v1/rateSchool.js | 3 --- 4 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/libs/routes_v1/courseAggregate.js b/src/libs/routes_v1/courseAggregate.js index fdc6bd88..cf9a52f2 100644 --- a/src/libs/routes_v1/courseAggregate.js +++ b/src/libs/routes_v1/courseAggregate.js @@ -405,7 +405,6 @@ CourseAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .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()) next(); }, query, id2str.transform(false), response('course_aggregate')); diff --git a/src/libs/routes_v1/enrollmentAggregate.js b/src/libs/routes_v1/enrollmentAggregate.js index db09b08d..408b952b 100644 --- a/src/libs/routes_v1/enrollmentAggregate.js +++ b/src/libs/routes_v1/enrollmentAggregate.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 enrollmentAggregateApp = express.Router(); diff --git a/src/libs/routes_v1/populationOutOfSchool.js b/src/libs/routes_v1/populationOutOfSchool.js index 99d991a5..d5686c23 100644 --- a/src/libs/routes_v1/populationOutOfSchool.js +++ b/src/libs/routes_v1/populationOutOfSchool.js @@ -445,14 +445,12 @@ function matchQueries(queryPartial, queryTotal) { if(objMatch) { newObj.denominator = result.total; newObj.pop_total = objMatch.total; - newObj.total = Math.round((objMatch.total / result.total) * 10000) / 100; + newObj.total = parseFloat(((objMatch.total / result.total) * 100).toFixed(1)); match.push(newObj); } } ) - console.log(match) - return match; } @@ -477,7 +475,6 @@ PopulationOutOfSchoolApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => .order('pnad_novo.ano_ref') .order('pnad_novo.faixa_etaria_pop_out') req.querySet.push(attends_school); - console.log(attends_school.toString()); // Then, the second object is created and stores the sum of all people without filters @@ -501,7 +498,6 @@ PopulationOutOfSchoolApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => // below is used let newObj = matchQueries(req.result[0], req.result[1]); req.result = newObj; - //console.log(attends_school.toString()); } else { res.status(400); next({ diff --git a/src/libs/routes_v1/rateSchool.js b/src/libs/routes_v1/rateSchool.js index a6a91b7b..37e0b283 100644 --- a/src/libs/routes_v1/rateSchool.js +++ b/src/libs/routes_v1/rateSchool.js @@ -257,8 +257,6 @@ function matchQueries(queryTotal, queryPartial) { keys.forEach((key) => { newObj[key] = result[key]; }); - // console.log('NEW OBJ'); - // console.log(newObj); let index = keys.indexOf('total'); if(index > -1) keys.splice(index, 1); let objMatch = null; @@ -280,7 +278,6 @@ function matchQueries(queryTotal, queryPartial) { } if(objMatch) { - // console.log(objMatch); newObj.denominator = result.total; newObj.partial = objMatch.total; newObj.total = (objMatch.total / result.total) * 100; -- GitLab From 6bcd66dfb40ed0979ac30aa06174f0e33c8b8ba7 Mon Sep 17 00:00:00 2001 From: fgs21 <fgs21@inf.ufpr.br> Date: Fri, 13 Jun 2025 11:45:30 -0300 Subject: [PATCH 45/45] =?UTF-8?q?[hotfix]=20Fixing=20'N=C3=A3o=20=C3=A9=20?= =?UTF-8?q?Capital'=20value=20in=20'Percentual=20de=20Estudantes=20que=20R?= =?UTF-8?q?ecebem=20Bolsa=20Fam=C3=ADlia'=20indicator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libs/routes_v1/studentsReceivingAidTax.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/routes_v1/studentsReceivingAidTax.js b/src/libs/routes_v1/studentsReceivingAidTax.js index 16547bfd..2910f434 100644 --- a/src/libs/routes_v1/studentsReceivingAidTax.js +++ b/src/libs/routes_v1/studentsReceivingAidTax.js @@ -120,8 +120,6 @@ studentsReceivingAidTaxApp.get('/cap_code', (req, res, next) => { }); } } - req.result.push({id: 99, name: id2str.capitalCode(99)}); - next(); }, response('cap_code')); @@ -586,6 +584,9 @@ function whereCondition(req) { where += `pnad_novo.faixa_rendimento_aux_tx is not null`; } + if (dims && dims.includes("cap_code")){ + where += `pnad_novo.cod_cap <> 99`; + } return where; } -- GitLab