Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • simcaq/simcaq-node
  • SMPPIR/SMPPIR-Node
2 results
Select Git revision
Show changes
Commits on Source (83)
Showing
with 780 additions and 57 deletions
......@@ -28,3 +28,9 @@ package-lock.json
Dockerfile
DockerfileAntigo
src/libs/db/postgres.js
docker-compose.yml
entrypoint.sh
gulpfile*
gulpfile.template.js
gulpfile.babel.js
services:
simcaq-node:
container_name: simcaq-node
build: .
ports:
- '3000:3000'
develop:
watch:
- action: sync
path: .
target: /API
#!/bin/bash
echo "Starting simcaq-node"
gulp watch &> /dev/null &
cd build
NODE_ENV=production gulp run
......@@ -106,3 +106,6 @@ gulp.task('default', () => {
console.log("Não execuatar apenas gulp, execute da forma:");
console.log("\t\tgulp <task>");
});
gulp.task('default', ['run']);
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>");
});
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
/*
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';
}
};
/*
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';
}
};
/*
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 "Entidade";
case 3:
return 'Despesas';
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';
}
};
/*
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';
}
};
/*
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 'Rede pública (anual)'
case 2:
return 'Rede pública (mensal)';
case 3:
return 'Rede pública e conveniada (anual)';
case 4:
return 'Rede pública e conveniada (mensal)';
}
};
/*
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';
}
};
......@@ -35,7 +35,11 @@ const convert = {
contract_type_entity: 'contractType',
total_doc: "totalDoc",
education_degree_entity: "educationDegreeEntity",
government_agreement: "governmentAgreement"
government_agreement: "governmentAgreement",
despesas_alunos: "expenses",
receita_potencial: "potentialRevenue",
receitas: "revenue",
despesas: "studentCost"
}
function aggregateData(req, res, next) {
......@@ -62,8 +66,13 @@ function aggregateData(req, res, next) {
'age_range_entity',
'post_graduation_entity',
'contract_type_entity',
'education_degree_entity'
]
'education_degree_entity',
'despesas_alunos',
'receitas',
'receita_potencial',
'despesas'
];
const baseFields = ["school"]
let id;
const fields = req.query.dims.split(',');
let currentAggregateField;
......@@ -87,7 +96,9 @@ function aggregateData(req, res, next) {
if (currentNonAggregateField) {
data[`${currentNonAggregateField}_id`] = r[`${currentNonAggregateField}_id`];
data[`${currentNonAggregateField}_name`] = id2str[convert[currentNonAggregateField]](r[`${currentNonAggregateField}_id`]);
data[`${currentNonAggregateField}_name`] = baseFields.includes(currentNonAggregateField)
? r[`${currentNonAggregateField}_name`]
: id2str[convert[currentNonAggregateField]](r[`${currentNonAggregateField}_id`]);
}
newResult.push(data)
......
/*
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) {
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();
};
......@@ -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`);
......@@ -126,6 +128,12 @@ 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 potentialRevenue = require(`${libs}/convert/potentialRevenue.js`)
const revenue = require(`${libs}/convert/revenue`);
const studentCost = require(`${libs}/convert/studentCost`);
const ageRangeOutSchool = require(`${libs}/convert/ageRangePopSchool`);
const ageRange19to64 = require(`${libs}/convert/ageRange19to64`);
const ids = {
gender_id: gender,
......@@ -244,7 +252,13 @@ const ids = {
post_graduation_entity: postGraduationEntity,
special_education_entity: specialEducationEntity,
total_doc: totalDoc,
education_degree_entity: educationDegreeEntity
education_degree_entity: educationDegreeEntity,
despesas_id: expenses,
receita_potencial_id: potentialRevenue,
receitas_id: revenue,
student_cost: studentCost,
age_range_pop_school_id: ageRangePopSchool,
age_range_19_to_64_id: ageRange19to64
};
function transform(removeId=false) {
......@@ -254,7 +268,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;
......@@ -386,5 +400,11 @@ module.exports = {
postGraduationEntity,
specialEducationEntity,
totalDoc,
educationDegreeEntity
educationDegreeEntity,
expenses,
potentialRevenue,
revenue,
studentCost,
ageRangePopSchool,
ageRange19to64
};
/*
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();
};
/*
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 studentRevenueParser(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();
};
\ No newline at end of file
......@@ -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;
......
/*
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 adjustedLiquidFrequency = express.Router();
const libs = `${process.cwd()}/libs`;
const squel = require('squel');
const query = require(`${libs}/middlewares/query`).query;
const multiQuery = require(`${libs}/middlewares/multiQuery`);
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();
adjustedLiquidFrequency.use(cache('15 day'));
adjustedLiquidFrequency.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'));
adjustedLiquidFrequency.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: 10, name: id2str.incomeRange(10)});
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++) {
req.result.push({
id: i, name: id2str.gender(i)
});
}
next();
}, response('gender'));
adjustedLiquidFrequency.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'));
adjustedLiquidFrequency.get('/age_range_all', (req, res, next) => {
req.result = []
for (let i = 1; i <= 6; i++) {
req.result.push({
id: i, name: id2str.ageRangeAll(i)
});
}
next()
}, response('age_range_all'));
adjustedLiquidFrequency.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'));
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: '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',
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: 'income_range',
table: 'pnad_novo',
tableField: 'faixa_rendimento_aux',
resultField: 'income_range_id',
where: {
relation: '=',
type: 'integer',
field: 'faixa_rendimento_aux'
}
}).addValue({
name: 'age_range_all',
table: 'pnad_novo',
tableField: 'faixa_etaria',
resultField: 'age_range_all_id',
where: {
relation: '=',
type: 'integer',
field: 'faixa_etaria'
}
}).addValue({
name: 'gender',
table: 'pnad_novo',
tableField: 'sexo',
resultField: 'gender_id',
where: {
relation: '=',
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',
tableField: 'cod_regiao',
resultField: 'region_id',
where: {
relation: '=',
type: 'integer',
field: 'cod_regiao'
}
}).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'
}
}).addField({
name: 'search',
field: false,
where: true
}).addValueToField({
name: 'name',
table: 'pnad_novo',
tableField: 'nome',
where: {
relation: 'LIKE',
type: 'string',
field: 'nome'
}
}, 'search').addValue({
name: 'mesoregion',
table: 'pnad_novo',
tableField: 'mesorregiao_id',
where: {
relation: '=',
type: 'integer',
field: 'mesorregiao_id'
}
}).addValue({
name: 'microregion',
table: 'pnad_novo',
tableField: 'microrregiao_id',
where: {
relation: '=',
type: 'integer',
field: 'microrregiao_id'
}
});
adjustedLiquidFrequency.get('/', rqf.parse(), (req, res, next) => {
const dimensions = req.dims || {}; // Obter dimensões solicitadas pela requisição
if (!dimensions.age_range_all) {
req.result = { error: "age_range_all should be selected" };
next();
}
// Subquery: total_pop
let totalPop = squel.select()
.field("ano_ref")
.field("faixa_etaria")
.field("SUM(peso_domicilio_pessoas_com_cal)", "total")
.from("pnad_novo")
.where("faixa_etaria <= 6")
.group("ano_ref")
.group("faixa_etaria");
// Aplicar filtros dinâmicos à subquery total_pop
totalPop = rqf.buildQuery(req, totalPop);
const joinQuery = `
total_pop.ano_ref = pnad_novo.ano_ref AND
total_pop.faixa_etaria = pnad_novo.apoio_frequencia_ajustada
${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" : ""}
${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
let totalApoioFreq = squel.select()
.field("pnad_novo.ano_ref", "ano_ref")
.field("pnad_novo.apoio_frequencia_ajustada", "apoio_frequencia_ajustada")
.field("total_pop.total", "total")
.field("SUM(pnad_novo.peso_domicilio_pessoas_com_cal)", "total_freq")
.from("pnad_novo")
.join(
totalPop,
"total_pop",
joinQuery
)
.group("pnad_novo.ano_ref")
.group("pnad_novo.apoio_frequencia_ajustada")
.group("total_pop.total");
// Aplicar filtros dinâmicos à subquery total_apoio_freq
totalApoioFreq = rqf.buildQuery(req, totalApoioFreq);
// Query Principal
let mainQuery = squel.select()
.from(totalApoioFreq, "total_apoio_freq")
.field("total_apoio_freq.ano_ref", "year")
.field("total_apoio_freq.apoio_frequencia_ajustada", "age_range_all_id")
.field("ROUND((total_apoio_freq.total_freq / total_apoio_freq.total) * 100, 1)", "total")
.where("total_apoio_freq.ano_ref >= 2019")
.order("total_apoio_freq.ano_ref")
.order("total_apoio_freq.apoio_frequencia_ajustada");
if (dimensions.gender)
mainQuery.field("total_apoio_freq.gender_id")
if (dimensions.bolsa_familia)
mainQuery.field("total_apoio_freq.bolsa_familia_id")
if (dimensions.new_pnad_ethnic_group)
mainQuery.field("total_apoio_freq.new_pnad_ethnic_group_id")
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")
if (dimensions.region)
mainQuery.field("total_apoio_freq.region_id")
if (dimensions.state)
mainQuery.field("total_apoio_freq.state_id")
req.sql = mainQuery;
next();
}, query, id2str.transform(false), response('adjusted_liquid_frequency'));
module.exports = adjustedLiquidFrequency;
......@@ -155,7 +155,19 @@ const federativeEntity = require(`${libs}/routes_v1/federativeEntity`);
const email = require(`${libs}/routes_v1/email`);
const uniLocalOfferAggregate = require(`${libs}/routes_v1/uniLocalOfferAggregate`)
const uniLocalOfferAggregate = require(`${libs}/routes_v1/uniLocalOfferAggregate`);
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`)
const superiorEducationConclusionTax = require(`${libs}/routes_v1/superiorEducationConclusionTax`)
......@@ -163,12 +175,20 @@ const aggregateClass = require(`${libs}/routes_v1/aggregateClass`);
const instructionLevel = require(`${libs}/routes_v1/instructionLevel`);
const uniLocalOfferAggregate = require(`${libs}/routes_v1/uniLocalOfferAggregate`)
const basicEducationConclusion = require(`${libs}/routes_v1/basicEducationConclusion`);
const adjustedLiquidFrequency = require(`${libs}/routes_v1/adjustedLiquidFrequency`);
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' });
});
......@@ -237,9 +257,17 @@ api.use('/employeesAggregate', employeesAggregate);
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)
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);
api.use('/pop_out_school', populationOutOfSchool);
//Publication
api.use('/publication', publication);
......