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
Loading items

Target

Select target project
  • simcaq/simcaq-node
  • SMPPIR/SMPPIR-Node
2 results
Select Git revision
Loading items
Show changes
......@@ -144,6 +144,7 @@ cityApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
.field('municipio.latitude', 'latitude')
.field('municipio.mesorregiao_id', 'mesoregion_id')
.field('municipio.microrregiao_id', 'microregion_id');
console.log(req.sql.toString());
next();
}, query, response('city'));
......
/*
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 CourseAggregateApp = 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();
CourseAggregateApp.use(cache('15 day'));
CourseAggregateApp.get('/years', (req, res, next) => {
req.sql.from('curso_superior_agregado')
.field('DISTINCT curso_superior_agregado.ano_censo', 'year')
next();
}, query, response('years'));
CourseAggregateApp.get('/upper_adm_dependency', (req, res, next) => {
req.result = [];
for(let i = 1; i <= 7; ++i) {
req.result.push({
id: i,
name: id2str.upperAdmDependency(i)
});
};
next();
}, response('upper_adm_dependency'));
CourseAggregateApp.get('/academic_organization', (req, res, next) => {
req.result = [];
for(let i = 1; i <= 5; ++i) {
req.result.push({
id: i,
name: id2str.academicOrganization(i)
});
};
next();
}, response('academic_organization'));
CourseAggregateApp.get('/academic_level', (req, res, next) => {
req.result = [];
for(let i = 1; i <= 4; ++i) {
req.result.push({
id: i,
name: id2str.academicLevel(i)
});
};
next();
}, response('academic_level'));
CourseAggregateApp.get('/upper_education_mod', (req, res, next) => {
req.result = [];
for(let i = 1; i <= 2; ++i) {
req.result.push({
id: i,
name: id2str.upperEducationMod(i)
});
};
next();
}, response('upper_education_mod'));
CourseAggregateApp.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'));
CourseAggregateApp.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'));
CourseAggregateApp.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'));
CourseAggregateApp.get('/is_free', (req, res, next) => {
req.result = [
{id: null, name: 'Não Classificado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('is_free'));
CourseAggregateApp.get('/cine_geral', (req, res, next) => {
req.result = [];
for(let i = 1; i <= 10; ++i) {
req.result.push({
id: i,
name: id2str.cineGeral(i)
});
};
next();
}, response('cine_geral'));
CourseAggregateApp.get('/cine_specific', (req, res, next) => {
req.result = [];
const defaultCase = null;
for(let i = 1; i <= 104; ++i) {
let obj = {
id: i,
name: id2str.cineSpecific(i)
};
if (obj.name !== id2str.cineSpecific(defaultCase)){
req.result.push(obj);
}
};
req.result.push({
id: defaultCase,
name: id2str.cineSpecific(defaultCase)
});
next();
}, response('cine_specific'));
CourseAggregateApp.get('/cine_detailed', (req, res, next) => {
req.result = [];
const defaultCase = null;
for(let i = 11; i <= 1041; ++i) {
let obj = {
id: i,
name: id2str.cineDetailed(i)
};
if (obj.name !== id2str.cineDetailed(defaultCase)){
req.result.push(obj);
}
};
req.result.push({
id: defaultCase,
name: id2str.cineDetailed(defaultCase)
});
next();
}, response('cine_detailed'));
CourseAggregateApp.get('/university', (req, res, next) => {
req.sql.from('curso_superior_agregado')
.field('DISTINCT curso_superior_agregado.cod_ies', 'cod')
.field('ies_ens_superior.nome_ies', 'nome')
.join('ies_ens_superior', null, 'curso_superior_agregado.cod_ies = ies_ens_superior.cod_ies and curso_superior_agregado.ano_censo = ies_ens_superior.ano_censo')
next();
}, query, response('university'));
CourseAggregateApp.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'));
rqf.addField({
name: 'filter',
field: false,
where: true
}).addField({
name: 'dims',
field: true,
where: false
}).addValue({
name: 'upper_adm_dependency',
table: 'curso_superior_agregado',
tableField: 'tp_categ_adm',
resultField: 'upper_adm_dependency_id',
where: {
relation: '=',
type: 'integer',
field: 'tp_categ_adm'
}
}).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: 'curso_superior_agregado'
}
}).addValue({
name: 'academic_organization',
table: 'curso_superior_agregado',
tableField: 'tp_org_acad',
resultField: 'academic_organization_id',
where: {
relation: '=',
type: 'integer',
field: 'tp_org_acad'
}
}).addValue({
name: 'academic_level',
table: 'curso_superior_agregado',
tableField: 'tp_grau_acad',
resultField: 'academic_level_id',
where: {
relation: '=',
type: 'integer',
field: 'tp_grau_acad'
}
}).addValue({
name: 'upper_education_mod',
table: 'curso_superior_agregado',
tableField: 'tp_modal_ens',
resultField: 'upper_education_mod_id',
where: {
relation: '=',
type: 'integer',
field: 'tp_modal_ens'
}
}).addValue({
name: 'is_free',
table: 'curso_superior_agregado',
tableField: 'in_gratuito',
resultField: 'is_free_id',
where: {
relation: '=',
type: 'boolean',
field: 'in_gratuito'
}
}).addValue({
name: 'cine_geral',
table: 'curso_superior_agregado',
tableField: 'cod_cine_area_geral',
resultField: 'cine_geral_id',
where: {
relation: '=',
type: 'integer',
field: 'cod_cine_area_geral'
}
}).addValue({
name: 'cine_specific',
table: 'curso_superior_agregado',
tableField: 'cod_cine_area_esp',
resultField: 'cine_specific_id',
where: {
relation: '=',
type: 'integer',
field: 'cod_cine_area_esp'
}
}).addValue({
name: 'cine_detailed',
table: 'curso_superior_agregado',
tableField: 'cod_cine_area_detalhada',
resultField: 'cine_detailed_id',
where: {
relation: '=',
type: 'integer',
field: 'cod_cine_area_detalhada'
}
}).addValue({
name: 'uni_offer_aggregate',
table: 'ies_ens_superior',
tableField: ['cod_ies', 'nome_ies'],
resultField: ['university_id', 'university_name'],
where: {
relation: '=',
type: 'integer',
field: 'cod_ies'
},
join: {
primary: ['cod_ies', 'ano_censo'],
foreign: ['cod_ies', 'ano_censo'],
foreignTable: 'curso_superior_agregado'
}
}).addValue({
name: 'cap_code',
table: 'curso_superior_agregado',
tableField: 'cod_cap',
resultField: 'cap_code_id',
where: {
relation: '=',
type: 'integer',
field: 'cod_cap'
}
}).addValue({
name: 'region',
table: 'curso_superior_agregado',
tableField: 'cod_reg',
resultField: 'region_id',
where: {
relation: '=',
type: 'integer',
field: 'cod_reg'
}
}).addValue({
name: 'metro_code',
table: 'curso_superior_agregado',
tableField: 'cod_rm_ride',
resultField: 'metro_code_id',
where: {
relation: '=',
type: 'integer',
field: 'cod_rm_ride'
}
}).addValue({
name: 'min_year',
table: 'curso_superior_agregado',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '>=',
type: 'integer',
field: 'ano_censo'
}
}).addValue({
name: 'max_year',
table: 'curso_superior_agregado',
tableField: '',
resultField: 'year',
where: {
relation: '<=',
type: 'integer',
field: 'ano_censo'
}
}).addValue({
name: 'city',
table: 'municipio',
tableField: ['id', 'nome'],
resultField: ['city_id', 'city_name'],
where: {
relation: '=',
type: 'integer',
field: 'id',
table: 'municipio'
},
join: {
primary: 'id',
foreign: 'cod_mun',
foreignTable: 'curso_superior_agregado'
}
});
CourseAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
req.sql.from('curso_superior_agregado')
.field('count(distinct(cod_curso))', 'total')
.field('curso_superior_agregado.ano_censo', 'year')
.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'));
module.exports = CourseAggregateApp;
......@@ -70,7 +70,7 @@ enrollmentAggregateApp.get('/adm_dependency', (req, res, next) => {
enrollmentAggregateApp.get('/adm_dependency_detailed', (req, res, next) => {
req.result = []
for (let i = 1; i <= 9; i++) {
for (let i = 1; i <= 8; i++) {
req.result.push({
id: i, name: id2str.admDependencyPriv(i)
});
......@@ -78,6 +78,18 @@ enrollmentAggregateApp.get('/adm_dependency_detailed', (req, res, next) => {
next();
}, response('adm_dependency_detailed'));
enrollmentAggregateApp.get('/government_agreement', (req, res, next) => {
req.result = []
for(let i = 1; i <= 6; ++i) {
req.result.push({
id: i,
name: id2str.governmentAgreement(i)
});
};
next();
}, response('government_agreement'));
enrollmentAggregateApp.get('/education_level_mod_agg', (req, res, next) => {
req.result = []
......@@ -114,7 +126,7 @@ enrollmentAggregateApp.get('/location', (req, res, next) => {
enrollmentAggregateApp.get('/diff_location', (req, res, next) => {
req.result = []
for (let i = 0; i <= 4; i++) {
for (let i = 0; i < 4; i++) {
req.result.push({
id: i, name: id2str.diffLocation(i)
});
......@@ -483,7 +495,17 @@ rqf.addField({
where: {
relation: '=',
type: 'integer',
field: 'localizacao_diferenciada_par'
field: 'localizacao_diferenciada_par',
}
}).addValue({
name: 'government_agreement',
table: 'escola',
tableField: 'dependencia_convenio_publico',
resultField: 'government_agreement_id',
where: {
relation: '=',
type: 'integer',
field: 'dependencia_convenio_publico'
}
});
......@@ -499,7 +521,8 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
.field('SUM(escola.qt_mat_bas_fem)', 'total_fem')
.field('escola.ano_censo', 'year')
.group('escola.ano_censo')
.order('escola.ano_censo');
.order('escola.ano_censo')
.where('escola.localizacao_diferenciada_par is not null');
}
else if (req.query.dims && req.query.dims.includes('age_range')) {
req.sql.from('escola')
......@@ -511,7 +534,8 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
.field('SUM(escola.qt_mat_bas_18_mais)', 'total_18_mais')
.field('escola.ano_censo', 'year')
.group('escola.ano_censo')
.order('escola.ano_censo');
.order('escola.ano_censo')
.where('escola.localizacao_diferenciada_par is not null')
}
else if (req.query.dims && req.query.dims.includes('ethnic_group')) {
req.sql.from('escola')
......@@ -523,7 +547,8 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
.field('SUM(escola.qt_mat_bas_indigena)', 'total_indigena')
.field('escola.ano_censo', 'year')
.group('escola.ano_censo')
.order('escola.ano_censo');
.order('escola.ano_censo')
.where('escola.localizacao_diferenciada_par is not null')
}
else if (req.query.dims && req.query.dims.includes('education_level_mod_agg')) {
req.sql.from('escola')
......@@ -537,9 +562,12 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
.field('SUM(escola.qt_mat_eja_med_agg)', 'total_eja_med')
.field('SUM(escola.qt_mat_eja_fund_fic + escola.qt_mat_eja_med_fic + escola.qt_mat_eja_med_tec)', 'total_tec')
.field('SUM(escola.qt_mat_prof_agg)', 'total_prof')
.field('SUM(escola.qt_mat_bas)', 'total_total')
.field('escola.ano_censo', 'year')
.group('escola.ano_censo')
.order('escola.ano_censo');
.order('escola.ano_censo')
.where('escola.localizacao_diferenciada_par is not null');
}
else if (req.query.dims && req.query.dims.includes('integral_time_agg')) {
req.sql.from('turma,escola')
......@@ -549,7 +577,7 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
.field('escola.ano_censo', 'year')
.group('escola.ano_censo')
.order('escola.ano_censo')
.where('turma.tipo_atendimento_id <= 2 and turma.escola_id = escola.id and turma.ano_censo = escola.ano_censo');
.where('turma.tipo_atendimento_id <= 2 and turma.escola_id = escola.id and turma.ano_censo = escola.ano_censo and escola.localizacao_diferenciada_par is not null');
}
else if (req.query.dims && req.query.dims.includes('period_agg')) {
req.sql.from('turma,escola')
......@@ -561,7 +589,7 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
.field('escola.ano_censo', 'year')
.group('escola.ano_censo')
.order('escola.ano_censo')
.where('turma.tipo_atendimento_id <= 2 and turma.escola_id = escola.id and turma.ano_censo = escola.ano_censo');
.where('turma.tipo_atendimento_id <= 2 and turma.escola_id = escola.id and turma.ano_censo = escola.ano_censo and escola.localizacao_diferenciada_par is not null');
}
else if (req.query.dims && req.query.dims.includes('modality_integral_time')) {
req.sql.from('escola')
......@@ -573,6 +601,7 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
.field('escola.ano_censo', 'year')
.group('escola.ano_censo')
.order('escola.ano_censo')
.where('escola.localizacao_diferenciada_par is not null');
}
else if (req.query.dims && req.query.dims.includes('special_education')) {
req.sql.from('escola')
......@@ -581,13 +610,15 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
.field('escola.ano_censo', 'year')
.group('escola.ano_censo')
.order('escola.ano_censo')
.where('escola.localizacao_diferenciada_par is not null');
}
else {
req.sql.from('escola')
.field('SUM(escola.qt_mat_bas)', 'total')
.field('escola.ano_censo', 'year')
.group('escola.ano_censo')
.order('escola.ano_censo');
.order('escola.ano_censo')
.where('escola.localizacao_diferenciada_par is not null');
}
next();
}, query, aggregateData, id2str.transform(false), response('enrollment_aggregate'));
......
This diff is collapsed.
/*
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 iliteracyRate = 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();
iliteracyRate.use(cache('15 day'));
iliteracyRate.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'));
iliteracyRate.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'));
iliteracyRate.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'));
iliteracyRate.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'));
iliteracyRate.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'));
iliteracyRate.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'));
iliteracyRate.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'));
iliteracyRate.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'));
iliteracyRate.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'));
iliteracyRate.get('/income_range', (req, res, next) => {
req.result = []
for (let i = 1; i < 10; i++) {
req.result.push({
id: i, name: id2str.incomeRange(i)
});
}
next();
}, response('income_range'));
iliteracyRate.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'));
iliteracyRate.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'));
iliteracyRate.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'));
iliteracyRate.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'));
iliteracyRate.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'));
iliteracyRate.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'));
iliteracyRate.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'));
iliteracyRate.get('/age_range_all', (req, res, next) => {
req.result = []
for (let i = 5; i < 12; i++) {
req.result.push({
id: i, name: id2str.ageRangeAll(i)
});
}
next();
}, response('age_range_all'));
iliteracyRate.get('/location', (req, res, next) => {
req.result = []
for (let i = 1; i <= 2; i++) {
req.result.push({
id: i, name: id2str.location(i)
});
}
next();
}, response('location'));
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: 'years_of_study',
table: 'pnad_novo',
tableField: 'anos_de_estudo',
resultField: 'years_of_study_id',
where: {
relation: '=',
type: 'integer',
field: 'anos_de_estudo'
}
}).addValue({
name: 'instruction_level',
table: 'pnad_novo',
tableField: 'nivel_de_instrucao',
resultField: 'instruction_level_id',
where: {
relation: '=',
type: 'integer',
field: 'nivel_de_instrucao'
}
}).addValue({
name: 'new_pnad_adm_dependency',
table: 'pnad_novo',
tableField: 'dependencia_adm',
resultField: 'new_pnad_adm_dependency_id',
where: {
relation: '=',
type: 'integer',
field: 'dependencia_adm'
}
}).addValue({
name: 'attends_school',
table: 'pnad_novo',
tableField: 'frequenta_escola',
resultField: 'attends_school_id',
where: {
relation: '=',
type: 'integer',
field: 'frequenta_escola'
}
}).addValue({
name: 'modality',
table: 'pnad_novo',
tableField: 'modalidade',
resultField: 'modality_id',
where: {
relation: '=',
type: 'integer',
field: 'modalidade'
}
}).addValue({
name: 'attended_modality',
table: 'pnad_novo',
tableField: 'nivel_etapa_modalidade_freq',
resultField: 'attended_modality_id',
where: {
relation: '=',
type: 'integer',
field: 'nivel_etapa_modalidade_freq'
}
}).addValue({
name: 'illiteracy',
table: 'pnad_novo',
tableField: 'analfabetismo',
resultField: 'illiteracy_id',
where: {
relation: '=',
type: 'integer',
field: 'analfabetismo'
}
}).addValue({
name: 'modality_shift',
table: 'pnad_novo',
tableField: 'turno_nivel_etapa',
resultField: 'modality_shift_id',
where: {
relation: '=',
type: 'integer',
field: 'turno_nivel_etapa'
}
}).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_all',
table: 'pnad_novo',
tableField: 'faixa_etaria',
resultField: 'age_range_all_id',
where: {
relation: '=',
type: 'integer',
field: 'faixa_etaria'
}
}).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: 'location',
table: 'pnad_novo',
tableField: 'situacao_domicilio',
resultField: 'location_id',
where: {
relation: '=',
type: 'integer',
field: 'situacao_domicilio'
}
}).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'
}
});
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.partial = objMatch.total;
newObj.total = (objMatch.total / result.total) * 100;
newObj.total = newObj.total.toFixed(1);
match.push(newObj);
}
});
return match;
}
iliteracyRate.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
req.querySet = [];
// Subquery para total_pop_maior_19 com filtros dinâmicos
let totalAnalfabetismo = req.sql.clone();
totalAnalfabetismo.from("pnad_novo")
.field("ano_ref", "year")
.field("SUM(peso_domicilio_pessoas_com_cal)", "total")
.where("analfabetismo = 1")
.where("ano_ref >= 2019")
.group("ano_ref")
.order("ano_ref");
// Subquery para total_pop_ed_bas_maior_19 com filtros dinâmicos
let totalPop = req.sql.clone();
totalPop.from("pnad_novo")
.field("ano_ref", "year")
.field("SUM(peso_domicilio_pessoas_com_cal)", "total")
.where("analfabetismo = 0 or analfabetismo = 1")
.where("ano_ref >= 2019")
.group("ano_ref")
.order("ano_ref");
req.querySet.push(totalAnalfabetismo);
req.querySet.push(totalPop);
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;
next();
}, id2str.transform(false), response('iliteracy_rate'));
module.exports = iliteracyRate;
/*
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 NivelInstrucao = 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();
NivelInstrucao.use(cache('15 day'));
NivelInstrucao.get('/years', (req, res, next) => {
req.sql.from('pnad_novo')
.field('DISTINCT pnad_novo.ano_ref', 'year')
next();
}, query, response('years'));
NivelInstrucao.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'));
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: 'location',
table: 'pnad_novo',
tableField: 'tipo_de_area',
resultField: 'location_id',
where: {
relation: '=',
type: 'integer',
field: 'id'
}
}).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: 'cap_code',
table: 'pnad_novo',
tableField: 'cod_cap',
resultField: 'cap_code_id',
where: {
relation: '=',
type: 'integer',
field: 'cod_cap'
}
}).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_all',
table: 'pnad_novo',
tableField: 'faixa_etaria',
resultField: 'age_range_all_id',
where: {
relation: '=',
type: 'integer',
field: 'faixa_etaria'
}
}).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: '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: 'gender',
table: 'pnad_novo',
tableField: 'sexo',
resultField: 'gender_id',
where: {
relation: '=',
type: 'integer',
field: 'sexo'
}
}).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: 'instruction_level',
table: 'pnad_novo',
tableField: 'nivel_de_instrucao',
resultField: 'instruction_level_id',
where: {
relation: '=',
type: 'integer',
field: 'cod_uf'
}
}).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: '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'
}
})
NivelInstrucao.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
if ("instruction_level" in req.filter || "instruction_level" in req.dims) {
// The multiple requests are made. Then we need to calculate the percetange. So the function
// below is used
req.sql.from('pnad_novo')
.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')
console.log(req.sql.toString())
}
else {
res.status(400);
next({
status: 400,
message: 'Wrong/No filter specified'
});
}
next();
}, query, id2str.transform(false), response('pnad_novo'));
module.exports = NivelInstrucao;
......@@ -308,20 +308,49 @@ rqf.addField({
}
});
// The queries are matched and the total is calculated
function matchQueries(attendsSchoolObj, populationObj) {
let match = [];
for (let i = 0; i < attendsSchoolObj.length; i++) {
let newObj = attendsSchoolObj[i];
newObj.total = (attendsSchoolObj[i].total / populationObj[i].total) * 100;
/*
The queries are matched and the total is calculated.
This function is necessary to match the results of the
2 queries with the right pair. In some queries, the result
doesn't exist in one of the 2, so, we need to run this algorithm
to match them right.
*/
newObj.age_range_id = newObj.faixa_etaria;
delete newObj.faixa_etaria;
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.partial = objMatch.total;
newObj.total = (objMatch.total / result.total) * 100;
match.push(newObj);
}
});
return match;
}
......
/*
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 uniLocalOfferAggregateApp = express.Router();
const libs = `${process.cwd()}/libs`;
const query = require(`${libs}/middlewares/query`).query;
const response = require(`${libs}/middlewares/response`);
const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
const config = require(`${libs}/config`);
const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware;
let rqf = new ReqQueryFields();
uniLocalOfferAggregateApp.use(cache('15 day'));
rqf.addField({
name: 'filter',
field: false,
where: true
}).addField({
name: 'dims',
field: true,
where: false
}).addValue({
name: 'min_year',
table: 'curso_superior_agregado',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '>=',
type: 'integer',
field: 'ano_censo'
}
}).addValue({
name: 'max_year',
table: 'curso_superior_agregado',
tableField: '',
resultField: 'year',
where: {
relation: '<=',
type: 'integer',
field: 'ano_censo'
}
}).addValue({
name: 'region',
table: 'curso_superior_agregado',
tableField: 'cod_reg',
resultField: 'region_id',
where: {
relation: '=',
type: 'integer',
field: 'cod_reg'
}
}).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: 'curso_superior_agregado'
}
}).addValue({
name: 'city',
table: 'municipio',
tableField: ['id', 'nome'],
resultField: ['city_id', 'city_name'],
where: {
relation: '=',
type: 'integer',
field: 'id',
table: 'municipio'
},
join: {
primary: 'id',
foreign: 'cod_mun',
foreignTable: 'curso_superior_agregado'
}
});
uniLocalOfferAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
req.sql.from('curso_superior_agregado')
.field('DISTINCT curso_superior_agregado.cod_ies', 'id')
.field('ies_ens_superior.nome_ies', 'name')
.field('curso_superior_agregado.cod_mun', 'city_id')
.field('curso_superior_agregado.cod_uf', 'state_id')
.field('curso_superior_agregado.cod_reg', 'region_id')
.join('ies_ens_superior', null, 'curso_superior_agregado.cod_ies = ies_ens_superior.cod_ies and curso_superior_agregado.ano_censo = ies_ens_superior.ano_censo')
.order('curso_superior_agregado.cod_ies')
next();
}, query, response('uni_offer_aggregate'));
module.exports = uniLocalOfferAggregateApp;
\ No newline at end of file
......@@ -84,7 +84,7 @@ rqf.addField({
},
join: {
primary: 'nome',
foreign: 'nome_regiao_ies',
foreign: 'nome_regiao',
foreignTable: 'localoferta_ens_superior'
}
......