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
  • #974-receita-potencial
  • aggregate_enrollment
  • attendance_rate
  • courseAggregate
  • db-conn
  • development
  • docentes-ies-ente-federativo
  • enrollment_rate
  • es23-superior-enrollment
  • homologa
  • hotfix-enrollment-aggregate
  • instruction_level_fixes
  • instruction_number
  • issue_935
  • issue_953
  • issue_958
  • issues_indicadores_agregados
  • master
  • new-indicators
  • receita-potencial
  • teachers-ies
  • years-of-study-mean
  • v0.1.0
  • v1.0.0
  • v1.0.1
  • v1.0.2
  • v1.0.3
  • v1.1.0
  • v1.1.1
  • v1.14
  • v1.14.0
  • v1.14.1
  • v1.14.2
  • v1.15.1
  • v1.16.0
  • v1.2.0
  • v1.2.1
  • v1.2.2
  • v1.2.3
  • v1.3.0
  • v1.3.1
  • v1.3.2
  • v1.3.3
  • v1.4.0
  • v1.4.1
  • v1.4.2
  • v1.5.0
  • v1.6.0
  • v1.6.1
  • v1.7.0
  • v1.8.0
  • v1.8.1
  • v1.8.2
  • v1.8.3
  • v1.9.0
55 results

Target

Select target project
  • simcaq/simcaq-node
  • SMPPIR/SMPPIR-Node
2 results
Select Git revision
  • #974-receita-potencial
  • aggregate_enrollment
  • attendance_rate
  • courseAggregate
  • db-conn
  • development
  • docentes-ies-ente-federativo
  • enrollment_rate
  • es23-superior-enrollment
  • homologa
  • hotfix-enrollment-aggregate
  • instruction_level_fixes
  • instruction_number
  • issue_935
  • issue_953
  • issue_958
  • issues_indicadores_agregados
  • master
  • new-indicators
  • receita-potencial
  • teachers-ies
  • years-of-study-mean
  • v0.1.0
  • v1.0.0
  • v1.0.1
  • v1.0.2
  • v1.0.3
  • v1.1.0
  • v1.1.1
  • v1.14
  • v1.14.0
  • v1.14.1
  • v1.14.2
  • v1.15.1
  • v1.16.0
  • v1.2.0
  • v1.2.1
  • v1.2.2
  • v1.2.3
  • v1.3.0
  • v1.3.1
  • v1.3.2
  • v1.3.3
  • v1.4.0
  • v1.4.1
  • v1.4.2
  • v1.5.0
  • v1.6.0
  • v1.6.1
  • v1.7.0
  • v1.8.0
  • v1.8.1
  • v1.8.2
  • v1.8.3
  • v1.9.0
55 results
Show changes
Commits on Source (48)
Showing
with 1048 additions and 24 deletions
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
......@@ -43,12 +43,12 @@ gulp.task('compile', ['lint'], () => {
gulp.src('src/**/*.js')
.pipe(cache.filter()) // cache source files
.pipe(babel()) // compile only modified files
// .pipe(cache.cache()) // cache compiled files
.pipe(cache.cache()) // cache compiled files
.pipe(gulp.dest('build')); // move compiled files to build directory
});
gulp.task('build', ['compile'], () => {
var filesToCopy = [ 'config.json', 'package.json' ];
var filesToCopy = [ 'config.json', 'package.json', '.eslintignore', '.eslintrc.json' ];
// copy configuration file to build directory
gulp.src(filesToCopy)
.pipe(gulp.dest('build'));
......@@ -93,24 +93,16 @@ gulp.task('test', ['pre-test'], () => {
});
});
gulp.task('watch', ['compile'], () => {
gulp.task('watch', () => {
console.log('Watching source directory for changes');
gulp.watch('src/**/*.js').on('change', () => {
return gulp.watch('src/**/*.js').on('change', () => {
console.log('Recompiling source');
gulp.start('compile');
console.log('Source recompilation done');
});
});
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>");
});
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>");
});
/*
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 ageRangeEntity(id) {
switch (id) {
case 1:
return 'Até 24 anos';
case 2:
return '25 a 29 anos';
case 3:
return '30 a 39 anos';
case 4:
return '40 a 49 anos';
case 5:
return '50 a 54 anos';
case 6:
return '55 a 59 anos';
case 7:
return '60 anos ou mais';
default:
return 'Não declarada';
}
};
......@@ -30,5 +30,7 @@ module.exports = function location(id) {
return 'Área remanescente de quilombos';
case 8:
return 'Área onde se localizam povos e comunidades tradicionais';
default:
return 'Não definido';
}
};
/*
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 educationDegreeEntity(id) {
switch (id) {
case 1:
return 'Ensino Fundamental';
case 2:
return 'Ensino Médio';
case 3:
return 'Graduação Com Licenciatura';
case 4:
return 'Graduação Sem Licenciatura';
}
};
......@@ -24,11 +24,11 @@ module.exports = function educationLevelBasic(id) {
return 'Creche';
case 2:
return 'Pré-Escola';
case 4:
case 3:
return 'Ensino Fundamental - anos iniciais';
case 5:
case 4:
return 'Ensino Fundamental - anos finais';
case 6:
case 5:
return 'Ensino Médio';
default:
return 'Não classificada';
......
......@@ -40,6 +40,8 @@ module.exports = function educationLevelMod(id) {
return 'EJA - EF e EM Integrado - tecnico';
case 10:
return 'Educacao Profissional - concomitante e subsequente';
case 11:
return 'suporte_total'
default:
return 'Não classificada';
}
......
/*
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 educationLevelShort(id) {
switch (id) {
case 1:
return 'Creche';
case 2:
return 'Pré-Escola';
case 3:
return 'Ensino Fundamental - anos iniciais';
case 4:
return 'Ensino Fundamental - anos finais';
case 5:
return 'Ensino Médio Propedêutico';
case 6:
return 'Ensino Médio Normal Magistério';
case 7:
return 'Ensino Médio Integrado';
case 8:
return 'Educação Profissional Técnica - Associado ao Nível Médio';
case 9:
return 'Educação Profissional Técnica - Concomitante';
case 10:
return 'Educação Profissional Técnica - Subsequente';
case 11:
return 'Educação Profissional - Misto';
case 12:
return 'Educação Profissional FIC Concomitante';
case 13:
return 'Educacao Profissional FIC Integrado EJA';
case 14:
return 'EJA Ensino Fundamental';
case 15:
return 'EJA Ensino Médio';
default:
return 'Não classificada';
}
};
/*
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 educationLevelShort(id) {
switch (id) {
case 1:
return 'Educação Infantil';
case 2:
return 'Ensino Fundamental';
case 3:
return 'Ensino Médio';
case 4:
return 'Educação Profissional';
case 5:
return 'Educação Profissional Técnica de Nível Médio';
case 6:
return 'Educação Profissional FIC';
case 7:
return 'EJA';
default:
return 'Não classificada';
}
};
......@@ -36,5 +36,7 @@ module.exports = function incomeRange(id) {
return 'Mais de 5 salários mínimos';
case 9:
return 'Não informado ou ignorado';
case 10:
return "Ignorado"
}
};
/*
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 ageRange(id) {
switch (id) {
case 1:
return 'Pós-Graduação Especialização';
case 2:
return 'Pós-Graduação Mestrado';
case 3:
return 'Pós-Graduação Doutorado';
default:
return '';
}
};
/*
Copyright (C) 2022 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 specialEducation(id) {
switch (id) {
case 1:
return 'Classe Comum';
case 2:
return 'Classe Exclusiva';
default:
return 'Não definido';
}
};
/*
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 totalDoc(id) {
return '';
};
......@@ -22,7 +22,20 @@ const convert = {
modality_integral_time: 'educationLevelBasic',
special_education: 'specialEducation',
special_education_doc: 'specialEducationDoc',
education_level_mod_doc: 'educationLevelModDoc'
special_education_entity: 'specialEducationEntity',
education_level_mod_doc: 'educationLevelModDoc',
education_level_mod_entity_seg: 'educationLevelModEntitySeg',
education_level_mod_entity_agg: 'educationLevelModEntityAgg',
adm_dependency_entity_agg: 'newPnadAdmDependency',
adm_dependency_entity: 'admDependency',
location_entity: 'location',
gender_entity: 'gender',
age_range_entity: 'ageRangeEntity',
post_graduation_entity: 'postGraduationEntity',
contract_type_entity: 'contractType',
total_doc: "totalDoc",
education_degree_entity: "educationDegreeEntity",
government_agreement: "governmentAgreement"
}
function aggregateData(req, res, next) {
......@@ -38,7 +51,18 @@ function aggregateData(req, res, next) {
'period_agg',
'modality_integral_time',
'special_education',
'special_education_doc'
'special_education_doc',
'special_education_entity',
'education_level_mod_entity_seg',
'education_level_mod_entity_agg',
'adm_dependency_entity_agg',
'adm_dependency_entity',
'location_entity',
'gender_entity',
'age_range_entity',
'post_graduation_entity',
'contract_type_entity',
'education_degree_entity'
]
let id;
const fields = req.query.dims.split(',');
......
......@@ -118,8 +118,14 @@ const incomeRange = require(`${libs}/convert/incomeRange`);
const ageRangeAggregate = require(`${libs}/convert/ageRangeAggregate`);
const specialEducation = require(`${libs}/convert/specialEducation`);
const specialEducationDoc = require(`${libs}/convert/specialEducationDoc`);
const specialEducationEntity = require(`${libs}/convert/specialEducationEntity`);
const educationLevelModDoc = require(`${libs}/convert/educationLevelModDoc`);
const educationLevelModEntitySeg = require(`${libs}/convert/educationLevelModEntitySeg`);
const educationLevelModEntityAgg = require(`${libs}/convert/educationLevelModEntityAgg`);
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 ids = {
gender_id: gender,
......@@ -231,7 +237,14 @@ const ids = {
income_range_id: incomeRange,
special_education: specialEducation,
special_education_doc: specialEducationDoc,
education_level_mod_doc: educationLevelModDoc
education_level_mod_doc: educationLevelModDoc,
education_level_mod_entity_seg: educationLevelModEntitySeg,
education_level_mod_entity_agg: educationLevelModEntityAgg,
age_range_entity: ageRangeEntity,
post_graduation_entity: postGraduationEntity,
special_education_entity: specialEducationEntity,
total_doc: totalDoc,
education_degree_entity: educationDegreeEntity
};
function transform(removeId=false) {
......@@ -241,6 +254,7 @@ function transform(removeId=false) {
}
// Para cada objeto do resultado
req.result.forEach((obj) => {
console.log(obj),
Object.keys(obj).forEach((key) => {
// Se não há uma função especificada, retorna
if(typeof ids[key] === 'undefined') return;
......@@ -365,5 +379,12 @@ module.exports = {
incomeRange,
specialEducation,
specialEducationDoc,
educationLevelModDoc
educationLevelModDoc,
educationLevelModEntitySeg,
educationLevelModEntityAgg,
ageRangeEntity,
postGraduationEntity,
specialEducationEntity,
totalDoc,
educationDegreeEntity
};
/*
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/>.
*/
const express = require('express');
const aggregateClassApp = 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 config = require(`${libs}/config`);
const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware;
let rqf = new ReqQueryFields();
aggregateClassApp.use(cache('15 day'));
aggregateClassApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
req.sql.from('turmas_agregadas2022')
.field('id');
next();
}, query, response('aggregateClass'));
module.exports = aggregateClassApp;
......@@ -149,8 +149,23 @@ const enrollmentAggregate = require(`${libs}/routes_v1/enrollmentAggregate`);
const employeesAggregate = require(`${libs}/routes_v1/employeesAggregate`);
const courseAggregate = require(`${libs}/routes_v1/courseAggregate`);
const federativeEntity = require(`${libs}/routes_v1/federativeEntity`);
const email = require(`${libs}/routes_v1/email`);
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 iliteracyRate = require(`${libs}/routes_v1/iliteracyRate`);
api.get('/', (req, res) => {
res.json({ msg: 'SimCAQ API v1 is running' });
});
......@@ -211,10 +226,16 @@ api.use('/universityLocalOffer', universityLocalOffer);
api.use('/message', message);
api.use('/course_students', courseStudents);
api.use('/new_pnad', newPnad);
api.use('/aggregate_class', aggregateClass);
api.use('/instruction_level', instructionLevel)
api.use('/rate_school_new', rateSchoolNew)
api.use('/enrollmentAggregate', enrollmentAggregate);
api.use('/employeesAggregate', employeesAggregate);
api.use('/course_aggregate', courseAggregate);
api.use('/federativeEntity', federativeEntity);
api.use('/uni_offer_aggregate', uniLocalOfferAggregate);
api.use('/basic_education_conclusion', basicEducationConclusion);
api.use('/iliteracy_rate', iliteracyRate);
//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 basicEducationConclusion = 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();
basicEducationConclusion.use(cache('15 day'));
basicEducationConclusion.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'));
basicEducationConclusion.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'));
basicEducationConclusion.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'));
basicEducationConclusion.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'));
basicEducationConclusion.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'));
basicEducationConclusion.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'));
basicEducationConclusion.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'));
basicEducationConclusion.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'));
basicEducationConclusion.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'));
basicEducationConclusion.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'));
basicEducationConclusion.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'));
basicEducationConclusion.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'));
basicEducationConclusion.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'));
basicEducationConclusion.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'));
basicEducationConclusion.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'));
basicEducationConclusion.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'));
basicEducationConclusion.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'));
basicEducationConclusion.get('/age_range_all', (req, res, next) => {
req.result = []
for (let i = 1; i < 12; i++) {
req.result.push({
id: i, name: id2str.ageRangeAll(i)
});
}
next();
}, response('age_range_all'));
basicEducationConclusion.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_tx',
resultField: 'income_range_id',
where: {
relation: '=',
type: 'integer',
field: 'faixa_rendimento_aux_tx'
}
}).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;
match.push(newObj);
}
});
return match;
}
basicEducationConclusion.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
req.querySet = [];
// Subquery para total_pop_maior_19 com filtros dinâmicos
let totalPopMaior19 = req.sql.clone();
totalPopMaior19.from("pnad_novo")
.field("ano_ref", "year")
.field("SUM(peso_domicilio_pessoas_com_cal)", "total")
.where("idade_morador_31_03 >= 19")
.where("ano_ref >= 2019")
.group("ano_ref")
.order("ano_ref");
// Subquery para total_pop_ed_bas_maior_19 com filtros dinâmicos
let totalPopEdBasMaior19 = req.sql.clone();
totalPopEdBasMaior19.from("pnad_novo")
.field("ano_ref", "year")
.field("SUM(peso_domicilio_pessoas_com_cal)", "total")
.where("idade_morador_31_03 >= 19")
.where("nivel_de_instruc_mais_elevad_para_o_fundam_com_duracao_9_anos IN (5, 6, 7)")
.where("ano_ref >= 2019")
.group("ano_ref")
.order("ano_ref");
if (req.query.dims && req.query.dims.includes("income_range")) {
totalPopMaior19.where("faixa_rendimento_aux_tx is not null");
totalPopEdBasMaior19.where("faixa_rendimento_aux_tx is not null");
}
req.querySet.push(totalPopEdBasMaior19);
req.querySet.push(totalPopMaior19);
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('basic_education_conclusion'));
module.exports = basicEducationConclusion;