diff --git a/src/libs/convert/revenue.js b/src/libs/convert/revenue.js new file mode 100644 index 0000000000000000000000000000000000000000..c4f5865a56c323eaf4bcba464fd9d3a7984d10d3 --- /dev/null +++ b/src/libs/convert/revenue.js @@ -0,0 +1,38 @@ +/* +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 'Receitas'; + case 2: + return 'MatrÃculas Públicas'; + case 3: + return 'MatrÃculas Públicas Mais Conveniada'; + case 4: + return 'Receita Aluno Ano Pública' + case 5: + return 'Receita Aluno Mês Pública'; + case 6: + return 'Receita Aluno Ano Pública Mais Conveniada'; + case 7: + return 'Receita Aluno Mês Pública Mais Conveniada'; + } +}; diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js index eed373ddbbfd98c4a30fc4615823bb5d91a01fc4..adf21fbab4b2c87ee0497ecb839f2b9abc67b414 100644 --- a/src/libs/middlewares/aggregateData.js +++ b/src/libs/middlewares/aggregateData.js @@ -35,7 +35,8 @@ const convert = { contract_type_entity: 'contractType', total_doc: "totalDoc", education_degree_entity: "educationDegreeEntity", - government_agreement: "governmentAgreement" + government_agreement: "governmentAgreement", + receitas: "revenue" } function aggregateData(req, res, next) { @@ -62,7 +63,8 @@ function aggregateData(req, res, next) { 'age_range_entity', 'post_graduation_entity', 'contract_type_entity', - 'education_degree_entity' + 'education_degree_entity', + 'receitas' ] let id; const fields = req.query.dims.split(','); @@ -78,6 +80,7 @@ function aggregateData(req, res, next) { for (const property in r) { // Dados agregados são identificados com a substring 'total_' em sua chave if (property.includes('total_')) { + console.log(property); let data = { total: r[property], year: r.year, diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index d6c763c9e3d281b3763c8be632d1b4dca5a0e78f..60ff424f8c0599499d6a7e3cf559a4ab1a595049 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 revenue = require(`${libs}/convert/revenue`); 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, + receitas_id: revenue }; function transform(removeId=false) { @@ -386,5 +388,6 @@ module.exports = { postGraduationEntity, specialEducationEntity, totalDoc, - educationDegreeEntity + educationDegreeEntity, + revenue }; diff --git a/src/libs/routes_v1/studentRevenue.js b/src/libs/routes_v1/studentRevenue.js index ecc798443051acf7c112c3403a3576d193c39c39..93ae6997fd6d4b2878ac79b5ee581ee5ca3f8abb 100644 --- a/src/libs/routes_v1/studentRevenue.js +++ b/src/libs/routes_v1/studentRevenue.js @@ -32,6 +32,8 @@ const response = require(`${libs}/middlewares/response`); const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); +const aggregateData = require(`${libs}/middlewares/aggregateData`); + const id2str = require(`${libs}/middlewares/id2str`); const config = require(`${libs}/config`); @@ -94,39 +96,15 @@ studentRevenueApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { req.sql.from('receitas') .field('receitas.ano', 'year') .field('receitas.receitas', 'total_receitas') - } - if (req.query.dims && req.query.dims.includes('matriculas_publicas')) { - req.sql.from('receitas') - .field('receitas.ano', 'year') - .field('matriculas_publica', 'matriculas_publica_total') - } - if (req.query.dims && req.query.dims.includes('matriculas_publicas_mais_conveniada')) { - req.sql.from('receitas') - .field('receitas.ano', 'year') - .field('matriculas_publicas_mais_conveniada', 'matriculas_publicas_mais_conveniada_total') - } - if (req.query.dims && req.query.dims.includes('receita_aluno_ano_publica')) { - req.sql.from('receitas') - .field('receitas.ano', 'year') - .field('receuta_aluno_ano_publica', 'receita_aluno_ano_publica_total') - } - if (req.query.dims && req.query.dims.includes('receita_aluno_mes_publica')) { - req.sql.from('receitas') - .field('receitas.ano', 'year') - .field('receita_aluno_mes_publica', 'receita_aluno_mes_publica_total') - } - if (req.query.dims && req.query.dims.includes('receita_aluno_ano_publica_mais_conveniada')) { - req.sql.from('receitas') - .field('receitas.ano', 'year') - .field('receita_aluno_ano_publica_mais_conveniada', 'receita_aluno_ano_publica_mais_conveniada_total') - } - if (req.query.dims && req.query.dims.includes('receita_aluno_mes_publica_mais_conveniada')) { - req.sql.from('receitas') - .field('receitas.ano', 'year') - .field('receita_aluno_mes_publica_mais_conveniada', 'receita_aluno_mes_publica_mais_conveniada_total') + .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') } next(); -}, query, id2str.transform(false), response('student_revenue')); +}, query, aggregateData, id2str.transform(false), response('student_revenue')); module.exports = studentRevenueApp; diff --git a/src/libs/routes_v1/yearsOfStudy.js b/src/libs/routes_v1/yearsOfStudy.js index 0a84f206e9fedd82cb24286b5adfaf2ae198b6d6..a87d833ada08033abb2c7925d7f0c0b8bf33e636 100644 --- a/src/libs/routes_v1/yearsOfStudy.js +++ b/src/libs/routes_v1/yearsOfStudy.js @@ -538,7 +538,7 @@ PnadNovoApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { req.sql.from('pnad_novo') .field('pnad_novo.ano_ref', 'year') - .field('media.media_anos_estudo', 'mean') + .field('media.media_anos_estudo', 'average') .field('SQRT(SUM(POWER(pnad_novo.anos_de_estudo - media.media_anos_estudo, 2) * pnad_novo.peso_domicilio_pessoas_com_cal) / SUM(pnad_novo.peso_domicilio_pessoas_com_cal))', 'std_dev') .join(mean, 'media', joinQuery) .where('pnad_novo.ano_ref >= 2019 AND pnad_novo.faixa_etaria >= 6 AND pnad_novo.anos_de_estudo <> 99')