Skip to content
Snippets Groups Projects
Commit f41ff9cc authored by lgtg20's avatar lgtg20
Browse files

Merge branch 'issue-968' into 'development'

feat: add studentCost route

See merge request !446
parents 09a36811 271e7d8c
No related branches found
No related tags found
3 merge requests!449Homologa,!448Development,!446feat: add studentCost route
/*
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 studentCost(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 'Gasto Aluno Ano Pública'
case 7:
return 'Gasto Aluno Mês Pública';
case 8:
return 'Gasto Aluno Ano Pública Mais Conveniada';
case 9:
return 'Gasto Aluno Mês Pública Mais Conveniada';
}
};
......@@ -36,7 +36,8 @@ const convert = {
total_doc: "totalDoc",
education_degree_entity: "educationDegreeEntity",
government_agreement: "governmentAgreement",
receitas: "revenue"
receitas: "revenue",
despesas: "studentCost"
}
function aggregateData(req, res, next) {
......@@ -64,10 +65,12 @@ function aggregateData(req, res, next) {
'post_graduation_entity',
'contract_type_entity',
'education_degree_entity',
'receitas'
'receitas',
'despesas'
]
let id;
const fields = req.query.dims.split(',');
console.log(fields);
let currentAggregateField;
let currentNonAggregateField;
......
......@@ -127,6 +127,7 @@ 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 studentCost = require(`${libs}/convert/studentCost`);
const ids = {
gender_id: gender,
......@@ -246,7 +247,8 @@ const ids = {
special_education_entity: specialEducationEntity,
total_doc: totalDoc,
education_degree_entity: educationDegreeEntity,
receitas_id: revenue
receitas_id: revenue,
student_cost: studentCost
};
function transform(removeId=false) {
......@@ -389,5 +391,6 @@ module.exports = {
specialEducationEntity,
totalDoc,
educationDegreeEntity,
revenue
revenue,
studentCost
};
......@@ -4,7 +4,6 @@ Devido à limitações na tabela de dados, quando ambos campos estão ativos o f
"região" funciona incorretamente.
*/
module.exports = function studentRevenueParser(req, res, next) {
console.log(req.query);
if (req.query && req.query.filter) {
const jsonString = `{${req.query.filter.replace(/(\w+):/g, '"$1":')}}`;
......
......@@ -176,6 +176,8 @@ 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`);
api.get('/', (req, res) => {
res.json({ msg: 'SimCAQ API v1 is running' });
});
......@@ -251,6 +253,7 @@ api.use('/basic_education_conclusion', basicEducationConclusion);
api.use('/adjusted_liquid_frequency', adjustedLiquidFrequency);
api.use('/iliteracy_rate', iliteracyRate);
api.use('/student_revenue', studentRevenueParser, studentRevenue);
api.use('/student_cost', studentRevenueParser, studentCost);
//Publication
api.use('/publication', publication);
......
/*
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 studentCostApp = 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 aggregateData = require(`${libs}/middlewares/aggregateData`);
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();
studentCostApp.use(cache('15 day'));
studentCostApp.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.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'
}
})
studentCostApp.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('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')
}
next();
}, query, aggregateData, id2str.transform(false), response('student_cost'));
module.exports = studentCostApp;
......@@ -121,6 +121,7 @@ studentRevenueApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
.field('receita_aluno_mes_publica_mais_conveniada', 'total_receita_aluno_mes_publica_mais_conveniada')
.where(`${whereCondition}`)
.order('receitas.cod_ibge')
.order('receitas.ano')
}
next();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment