Skip to content
Snippets Groups Projects
Commit 34edc4e0 authored by Herbele's avatar Herbele :penguin:
Browse files

Merge branch 'receita-potencial' into 'development'

Receita potencial

See merge request !464
parents 6aec2731 580b5365
Branches
No related tags found
4 merge requests!501[hotfix] capital filter working for superior education conclusion tax...,!499[hotfix] capital filter working for superior education conclusion tax...,!466Development,!464Receita potencial
/*
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';
}
};
......@@ -37,6 +37,7 @@ const convert = {
education_degree_entity: "educationDegreeEntity",
government_agreement: "governmentAgreement",
despesas_alunos: "expenses",
receita_potencial: "potentialRevenue",
receitas: "revenue",
despesas: "studentCost"
}
......@@ -68,6 +69,7 @@ function aggregateData(req, res, next) {
'education_degree_entity',
'despesas_alunos',
'receitas',
'receita_potencial',
'despesas'
];
const baseFields = ["school"]
......
......@@ -129,6 +129,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 ageRangeOutSchool = require(`${libs}/convert/ageRangePopSchool`);
......@@ -253,6 +254,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_pop_school_id: ageRangePopSchool,
......@@ -400,6 +402,7 @@ module.exports = {
totalDoc,
educationDegreeEntity,
expenses,
potentialRevenue,
revenue,
studentCost,
ageRangePopSchool,
......
/*
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();
};
......@@ -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`)
......@@ -254,6 +258,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)
......
/*
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('receita_potencial')) {
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')
.where(`${whereCondition}`)
.order('receitas.ano');
}
next();
}, query, aggregateData, id2str.transform(false), response('potentialRevenue'));
module.exports = potentialRevenueApp;
\ No newline at end of file
......@@ -42,7 +42,7 @@ const cache = require('apicache').options({ debug: config.debug, statusCodes: {
let rqf = new ReqQueryFields();
studentRevenueApp.use(cache('15 day'));
// studentRevenueApp.use(cache('15 day'));
studentRevenueApp.get('/years', (req, res, next) => {
req.sql.from('receitas')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment