diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..85266ff985a71c7c1d0a0933785b77be4d3d3c3d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +services: + simcaq-node: + container_name: simcaq-node + build: . + ports: + - '3000:3000' + develop: + watch: + - action: sync + path: . + target: /API diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000000000000000000000000000000000000..04db51922c7afe6455aa25ef452e79ead0cd5751 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/bash +echo "Starting simcaq-node" +gulp watch &> /dev/null & +cd build +NODE_ENV=production gulp run diff --git a/gulpfile.babel.js b/gulpfile.babel.js index c661d5af261b6a5a8baf5232592d01ef7cb48b28..1d0724e16a18a88b11333f3564a763ebe1452d83 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -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']); diff --git a/gulpfile.template.js b/gulpfile.template.js new file mode 100644 index 0000000000000000000000000000000000000000..3de679df0c18e307b692cb22a3cb6446c052fcaf --- /dev/null +++ b/gulpfile.template.js @@ -0,0 +1,20 @@ +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>"); +}); + diff --git a/src/libs/convert/ageRangeIES.js b/src/libs/convert/ageRangeIES.js new file mode 100644 index 0000000000000000000000000000000000000000..4a88182998b7af0f07713984f161dd3a6fb8125a --- /dev/null +++ b/src/libs/convert/ageRangeIES.js @@ -0,0 +1,38 @@ +/* +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 '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'; + default: + return 'Não declarada'; + } +}; diff --git a/src/libs/convert/fullAgeRangeIES.js b/src/libs/convert/fullAgeRangeIES.js new file mode 100644 index 0000000000000000000000000000000000000000..558c513c97bf8e0262e25eb13ccedb7be603c355 --- /dev/null +++ b/src/libs/convert/fullAgeRangeIES.js @@ -0,0 +1,40 @@ +/* +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 ageRangeIES(id) { + switch (id) { + case 1: + return 'até 29 anos'; + case 2: + return 'de 30 a 34 anos'; + case 3: + return 'de 35 a 39 anos'; + case 4: + return 'de 40 a 44 anos'; + case 5: + return 'de 45 a 49 anos'; + case 6: + return 'de 50 a 54 anos'; + case 7: + return 'de 55 a 59 anos'; + case 8: + return 'de 60 anos ou mais'; + } +}; diff --git a/src/libs/convert/teacherDeficiency.js b/src/libs/convert/teacherDeficiency.js new file mode 100644 index 0000000000000000000000000000000000000000..dd911d2170b8e7a500a841a9147e85d4e08edf5f --- /dev/null +++ b/src/libs/convert/teacherDeficiency.js @@ -0,0 +1,26 @@ +/* +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 teacherDeficiency(id) { + switch (id) { + case 0: + return 'Total'; + } +}; diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js index eed373ddbbfd98c4a30fc4615823bb5d91a01fc4..48c4ab52091cc0e18a63dfd6c297f2109f3a97f6 100644 --- a/src/libs/middlewares/aggregateData.js +++ b/src/libs/middlewares/aggregateData.js @@ -14,6 +14,7 @@ const convert = { region: 'regionCode', state: 'stateName', age_range: 'ageRangeAggregate', + age_range_ies: 'ageRangeIES', gender: 'gender', ethnic_group: 'ethnicGroup', education_level_mod_agg: 'educationLevelModAgg', @@ -35,7 +36,10 @@ const convert = { contract_type_entity: 'contractType', total_doc: "totalDoc", education_degree_entity: "educationDegreeEntity", - government_agreement: "governmentAgreement" + government_agreement: "governmentAgreement", + work_regime: "workRegime", + teacher_schooling: "teacherSchooling", + teacher_deficiency: "teacherDeficiency", } function aggregateData(req, res, next) { @@ -43,7 +47,8 @@ function aggregateData(req, res, next) { const newResult = [] const aggregateFields = [ 'gender', - 'age_range', + 'age_range', + 'age_range_ies', 'ethnic_group', 'education_level_mod_agg', 'education_level_mod_doc', @@ -62,19 +67,23 @@ function aggregateData(req, res, next) { 'age_range_entity', 'post_graduation_entity', 'contract_type_entity', - 'education_degree_entity' + 'education_degree_entity', + 'work_regime', + 'teacher_schooling', + 'teacher_deficiency', ] let id; const fields = req.query.dims.split(','); let currentAggregateField; let currentNonAggregateField; - + // Verifica se o filtro passado está presente nos filtros agregados fields.forEach(field => {if (aggregateFields.includes(field)) currentAggregateField = field; else currentNonAggregateField = field}); if (currentAggregateField) { req.result.forEach((r) => { // Alguns filtros começam com o id = 0 outros id = 1 - id = ['ethnic_group', 'integral_time_agg'].includes(currentAggregateField) ? 0 : 1; + id = ['ethnic_group', 'integral_time_agg', 'teacher_deficiency'].includes(currentAggregateField) ? 0 : 1; + for (const property in r) { // Dados agregados são identificados com a substring 'total_' em sua chave if (property.includes('total_')) { @@ -84,9 +93,13 @@ function aggregateData(req, res, next) { [`${currentAggregateField}_id`]: id, [`${currentAggregateField}_name`]: id2str[convert[currentAggregateField]](id) } - - if (currentNonAggregateField) { + + if(currentNonAggregateField == 'university'){ data[`${currentNonAggregateField}_id`] = r[`${currentNonAggregateField}_id`]; + data[`${currentNonAggregateField}_name`] = r[`${currentNonAggregateField}_name`]; + } + else if (currentNonAggregateField) { + data[`${currentNonAggregateField}_id`] = data[`${currentNonAggregateField}_id`]; data[`${currentNonAggregateField}_name`] = id2str[convert[currentNonAggregateField]](r[`${currentNonAggregateField}_id`]); } diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index f366d90a30c8d5c57955856040c78d610b3392b3..5f98e53208dbe5d2eb9957a033872baf797f754c 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -42,6 +42,7 @@ const stateName = require(`${libs}/convert/stateName`); const contractType = require(`${libs}/convert/contractType`); const ethnicGroupPnad = require(`${libs}/convert/ethnicGroupPnad`); const ageRange = require(`${libs}/convert/ageRange`); +const ageRangeIES = require(`${libs}/convert/fullAgeRangeIES`); const ageRangeAll = require(`${libs}/convert/ageRangeAll`); const ageStudentCode = require(`${libs}/convert/ageStudentCode`); const fullAgeRange = require(`${libs}/convert/fullAgeRange`); @@ -126,6 +127,7 @@ 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 teacherDeficiency = require(`${libs}/convert/teacherDeficiency`); const ids = { gender_id: gender, @@ -161,6 +163,7 @@ const ids = { contract_type_id: contractType, ethnic_group_pnad_id: ethnicGroupPnad, age_range_id: ageRange, + age_range_ies_id: ageRangeIES, age_range_all_id: ageRangeAll, age_range_aggregate_id: ageRangeAggregate, full_age_range_id: fullAgeRange, @@ -244,14 +247,17 @@ const ids = { post_graduation_entity: postGraduationEntity, special_education_entity: specialEducationEntity, total_doc: totalDoc, - education_degree_entity: educationDegreeEntity + education_degree_entity: educationDegreeEntity, + teacher_deficiency: teacherDeficiency }; function transform(removeId=false) { return (req, res, next) => { + if(req.result.length <= 0) { return next(); } + // Para cada objeto do resultado req.result.forEach((obj) => { Object.keys(obj).forEach((key) => { @@ -309,6 +315,7 @@ module.exports = { contractType, ethnicGroupPnad, ageRange, + ageRangeIES, ageRangeAggregate, ageRangeAll, ageStudentCode, @@ -385,5 +392,6 @@ module.exports = { postGraduationEntity, specialEducationEntity, totalDoc, - educationDegreeEntity + educationDegreeEntity, + teacherDeficiency }; diff --git a/src/libs/routes_v1/api.js b/src/libs/routes_v1/api.js index bffc8b5d0ff428652d958d41d521ad1992007b85..efbbc4fd0115ae20d931c52ecc53faa4e8c19eb3 100644 --- a/src/libs/routes_v1/api.js +++ b/src/libs/routes_v1/api.js @@ -157,6 +157,8 @@ const email = require(`${libs}/routes_v1/email`); const uniLocalOfferAggregate = require(`${libs}/routes_v1/uniLocalOfferAggregate`) +const iesTeachers = require(`${libs}/routes_v1/iesTeachers`); + api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API v1 is running' }); }); @@ -223,7 +225,7 @@ api.use('/employeesAggregate', employeesAggregate); api.use('/course_aggregate', courseAggregate); api.use('/federativeEntity', federativeEntity); api.use('/uni_offer_aggregate', uniLocalOfferAggregate); - +api.use('/teacher_ies', iesTeachers); //Publication api.use('/publication', publication); diff --git a/src/libs/routes_v1/courseCount.js b/src/libs/routes_v1/courseCount.js index 404ed2eb09b56efe5b6bd1caaa643ca1e225d3a8..1df41166dcaa94a3e273fb65ceb848d8355ac254 100644 --- a/src/libs/routes_v1/courseCount.js +++ b/src/libs/routes_v1/courseCount.js @@ -801,6 +801,7 @@ courseCountApp.get('/', rqf.parse(), (req, res, next) => { .where('curso_ens_superior.cod_nivel_academico = 1'); } next(); + }, rqf.build(), query, (req, res, next) =>{ if ('course' in req.dims){ var total_course = req.result.reduce((total, cur) => {return total += cur.total}, 0) @@ -808,6 +809,7 @@ courseCountApp.get('/', rqf.parse(), (req, res, next) => { course.percentage = Number((( course.total / total_course ) * 100).toFixed(2)) } } + console.log(req.result) next(); }, id2str.transform(), addMissing(rqf), response('course_count')); diff --git a/src/libs/routes_v1/fulltimeEnrollment.js b/src/libs/routes_v1/fulltimeEnrollment.js new file mode 100644 index 0000000000000000000000000000000000000000..fdc1266eeba8c5c4cb6671963f5269a3d8dd473a --- /dev/null +++ b/src/libs/routes_v1/fulltimeEnrollment.js @@ -0,0 +1,704 @@ +const express = require('express'); + +const fulltimeEnrollmentApp = express.Router(); + +const libs = `${process.cwd()}/libs`; + +const log = require(`${libs}/log`)(module); + +const squel = require('squel'); + +const query = require(`${libs}/middlewares/query`).query; + +const response = require(`${libs}/middlewares/response`); + +const id2str = require(`${libs}/middlewares/id2str`); + +const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); + +const request = require(`request`); + +const config = require(`${libs}/config`); + +const passport = require('passport'); + +const addMissing = require(`${libs}/middlewares/addMissing`); + +const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware; + +let rqf = new ReqQueryFields(); +let rqfCount = new ReqQueryFields(); + +// Return location +fulltimeEnrollmentApp.get('/year_range', cache('15 day'), (req, res, next) => { + req.sql.from('escola') + .field('MIN(escola.ano_censo)', 'start_year') + .field('MAX(escola.ano_censo)', 'end_year'); + next(); +}, query, response('range')); + +fulltimeEnrollmentApp.get('/years', cache('15 day'), (req, res, next) => { + req.sql.from('escola'). + field('DISTINCT escola.ano_censo', 'year'); + next(); +}, query, response('years')); + +fulltimeEnrollmentApp.get('/source', (req, res, next) => { + req.sql.from('fonte') + .field('fonte', 'source') + .where('tabela = \'escola\''); + next(); +}, query, response('source')); + +fulltimeEnrollmentApp.get('/location', cache('15 day'), (req, res, next) => { + req.result = [ + {id: 1, name: 'Urbana'}, + {id: 2, name: 'Rural'} + ]; + next(); +}, response('location')); + +fulltimeEnrollmentApp.get('/diff_location', cache('15 day'), (req, res, next) => { + req.result = [ + {id: 0, name: "Não está em localidade diferenciada"}, + {id: 1, name: "Área de assentamento"}, + {id: 2, name: "Terra indígena"}, + {id: 3, name: "Terra remanescente de quilombos"}, + {id: 8, name: "Área onde se localizam povos e comunidades tradicionais"} + ]; + next(); +}, response('diff_location')); + +fulltimeEnrollmentApp.get('/adm_dependency', (req, res, next) => { + req.result = []; + + for(let i = 1; i <= 4; ++i) { + req.result.push({ + id: i, + name: id2str.admDependency(i) + }); + }; + next(); +}, response('adm_dependency')); + +fulltimeEnrollmentApp.get('/adm_dependency_detailed', cache('15 day'), (req, res, next) => { + req.result = []; + for(let i = 1; i <= 8; i++) { + req.result.push({ + id: i, + name: id2str.admDependencyPriv(i) + }); + }; + next(); +}, response('adm_dependency_detailed')); + +fulltimeEnrollmentApp.get('/government_agreement', cache('15 day'), (req, res, next) => { + req.result = [{ + id: "null", + name: id2str.governmentAgreement("null") + }]; + for(let i = 1; i <= 6; ++i) { + req.result.push({ + id: i, + name: id2str.governmentAgreement(i) + }); + }; + next(); +}, response('government_agreement')); + +fulltimeEnrollmentApp.get('/agreement', cache('15 day'), (req, res, next) => { + req.result = [ + {id: 1, name: 'Municipal'}, + {id: 2, name: 'Estadual'}, + {id: 3, name: 'Estadual e Municipal'} + ]; + next(); +}, response('agreement')); + +fulltimeEnrollmentApp.get('/education_day_care_child', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('education_day_care_child')); + +fulltimeEnrollmentApp.get('/education_preschool_child', cache('15 day'), (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('education_preschool_child')); + +fulltimeEnrollmentApp.get('/education_begin_elementary_school', cache('15 day'), (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('education_begin_elementary_school')); + +fulltimeEnrollmentApp.get('/education_end_elementary_school', cache('15 day'), (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('education_end_elementary_school')); + +fulltimeEnrollmentApp.get('/education_middle_school', cache('15 day'), (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('education_middle_school')); + +fulltimeEnrollmentApp.get('/education_professional', cache('15 day'), (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('education_professional')); + +fulltimeEnrollmentApp.get('/education_eja', cache('15 day'), (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('education_eja')); + + +fulltimeEnrollmentApp.get('/arrangement', cache('15 day'), (req, res, next) => { + req.result = [ + {id: 0, name: 'Creche'}, + {id: 1, name: 'Pré Escola'}, + {id: 2, name: 'Ensino Fundamental - AI'}, + {id: 3, name: 'Ensino Fundamental - AF'}, + {id: 4, name: 'Ed. Infantil Unificada/Multietapa/Multissérie/Correção fluxo'}, + {id: 5, name: 'Ensino Médio'}, + {id: 6, name: 'Ensino EJA'}, + {id: 7, name: 'Educação Profissional'}, + {id: 8, name: 'Educação Especial Exclusiva'} + ]; + next(); +}, response('arrangement')); + +fulltimeEnrollmentApp.get('/integral_time', cache('15 day'), (req, res, next) => { + req.result = []; + for(let i = 0; i <= 2; ++i) { + req.result.push({ + id: i, + name: id2str.integralTime(i) + }); + } + next(); +}, response('integral_time')); + + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addValue({ + name: 'id', + table: 'escola', + tableField: 'id', + where: { + relation: '=', + type: 'integer', + field: 'id' + } +}).addValue({ + name: 'city', + table: 'municipio', + tableField: ['nome', 'id'], + resultField: ['city_name', 'city_id'], + where: { + relation: '=', + type: 'integer', + field: 'municipio_id', + table: 'escola' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'escola' + } +}).addValue({ + name: 'state', + table: 'estado', + tableField: ['nome', 'id'], + resultField: ['state_name', 'state_id'], + where: { + relation: '=', + type: 'integer', + field: 'estado_id', + table: 'escola' + }, + join: { + primary: 'id', + foreign: 'estado_id', + foreignTable: 'escola' + } +}).addValue({ + name: 'year', + table: 'escola', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '=', + type: 'integer', + field: 'ano_censo', + table: 'escola' + } +}).addValue({ + name: 'min_year', + table: 'escola', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'max_year', + table: 'escola', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'adm_dependency', + table: 'escola', + tableField: 'dependencia_adm_id', + resultField: 'adm_dependency', + where: { + relation: '=', + type: 'integer', + field: 'dependencia_adm_id' + } +}).addField({ + name: 'search', + field: true, + where: true +}).addValueToField({ + name: 'city_name', + table: 'municipio', + tableField: 'nome', + resultField: 'city_name', + dontGroup: true, + where: { + relation: 'LIKE', + type: 'string', + field: 'nome' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'escola' + } +}, 'search') +.addValueToField({ + name: 'state_name', + table: 'estado', + tableField: 'nome', + resultField: 'state_name', + dontGroup: true, + where: { + relation: 'LIKE', + type: 'string', + field: 'sigla' + }, + join: { + primary: 'id', + foreign: 'estado_id', + foreignTable: 'escola' + } +}, 'search').addValue({ + name: 'diff_location', + table: 'escola', + tableField: 'localizacao_diferenciada_par', + resultField: 'diff_location_id', + where: { + relation: '=', + type: 'integer', + field: 'localizacao_diferenciada_par' + } +}).addValue({ + name: 'adm_dependency', + table: 'escola', + tableField: 'dependencia_adm_id', + resultField: 'adm_dependency', + where: { + relation: '=', + type: 'integer', + field: 'dependencia_adm_id' + } +}); + +rqfCount.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'id', + table: 'escola', + tableField: 'id', + where: { + relation: '=', + type: 'integer', + field: 'id' + } +}).addValueToField({ + name: 'city', + table: 'municipio', + tableField: ['nome', 'id'], + resultField: ['city_name', 'city_id'], + where: { + relation: '=', + type: 'integer', + field: 'municipio_id', + table: 'escola' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'escola' + } +}, 'dims').addValueToField({ + name: 'city', + table: 'municipio', + tableField: 'nome', + resultField: 'city_name', + where: { + relation: '=', + type: 'integer', + field: 'municipio_id', + table: 'escola' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'escola' + } +}, 'filter').addValue({ + name: 'state', + table: 'estado', + tableField: ['nome', 'id'], + resultField: ['state_name', 'state_id'], + where: { + relation: '=', + type: 'integer', + field: 'estado_id', + table: 'escola' + }, + join: { + primary: 'id', + foreign: 'estado_id', + foreignTable: 'escola' + } +}).addValue({ + name: 'mesoregion', + table: 'municipio', + tableField: ['nome_mesorregiao', 'mesorregiao_id'], + resultField: ['mesoregion_name', 'mesoregion_id'], + where: { + relation: '=', + type: 'integer', + field: 'mesorregiao_id', + table: 'municipio' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'escola' + } +}).addValue({ + name: 'microregion', + table: 'municipio', + tableField: ['nome_microrregiao', 'microrregiao_id'], + resultField: ['microregion_name', 'microregion_id'], + where: { + relation: '=', + type: 'integer', + field: 'microrregiao_id', + table: 'municipio' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'escola' + } +}).addValue({ + name: 'region', + table: 'regiao', + tableField: ['nome', 'id'], + resultField: ['region_name', 'region_id'], + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'regiao_id', + foreignTable: 'escola' + } +}).addValue({ + name: 'year', + table: 'escola', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '=', + type: 'integer', + field: 'ano_censo', + table: 'escola' + } +}).addValue({ + name: 'location', + table: 'escola', + tableField: 'localizacao_id', + resultField: 'location_id', + where: { + relation: '=', + type: 'integer', + field: 'localizacao_id' + } +}).addValue({ + name: 'diff_location', + table: 'escola', + tableField: 'localizacao_diferenciada_par', + resultField: 'diff_location_id', + where: { + relation: '=', + type: 'integer', + field: 'localizacao_diferenciada_par' + } +}).addValue({ + name: 'rural_location', + table: 'escola', + tableField: 'localidade_area_rural', + resultField: 'rural_location_id', + where: { + relation: '=', + type: 'integer', + field: 'localidade_area_rural' + } +}).addValue({ + name: 'arrangement', + table: 'escola', + tableField: 'arranjo', + resultField: 'arrangement_id', + where: { + relation: '=', + type: 'integer', + field: 'arranjo' + } +}).addValue({ + name: 'adm_dependency', + table: 'escola', + tableField: 'dependencia_adm_id', + resultField: 'adm_dependency_id', + where: { + relation: '=', + type: 'integer', + field: 'dependencia_adm_id' + } +}).addValue({ + name: 'adm_dependency_detailed', + table: 'escola', + tableField: 'dependencia_adm_priv', + resultField: 'adm_dependency_detailed_id', + where: { + relation: '=', + type: 'integer', + field: 'dependencia_adm_priv' + } +}).addValue({ + name: 'government_agreement', + table: 'escola', + tableField: 'dependencia_convenio_publico', + resultField: 'government_agreement_id', + where: { + relation: '=', + type: 'integer', + field: 'dependencia_convenio_publico' + } +}).addValue({ + name: 'integral_time', + table: 'escola', + tableField: 'tempo_integral', + resultField: 'integral_time_id', + where: { + relation: '=', + type: 'boolean', + field: 'tempo_integral' + } +}).addValue({ + name: 'agreement', + table: 'escola', + tableField: 'tipo_convenio_pp', + resultField: 'agreement_id', + where: { + relation: '=', + type: 'integer', + field: 'tipo_convenio_pp' + } +}).addValue({ + name: 'education_day_care_child', + table: 'escola', + tableField: 'reg_infantil_creche_t1', + resultField: 'education_day_care_child_id', + where: { + relation: '=', + type: 'boolean', + field: 'reg_infantil_creche_t1' + } +}).addValue({ + name: 'education_preschool_child', + table: 'escola', + tableField: 'reg_infantil_preescola_t1', + resultField: 'education_preschool_child_id', + where: { + relation: '=', + type: 'boolean', + field: 'reg_infantil_preescola_t1' + } +}).addValue({ + name: 'education_begin_elementary_school', + table: 'escola', + tableField: 'reg_fund_ai_t1', + resultField: 'education_begin_elementary_school_id', + where: { + relation: '=', + type: 'boolean', + field: 'reg_fund_ai_t1' + } +}).addValue({ + name: 'education_end_elementary_school', + table: 'escola', + tableField: 'reg_fund_af_t1', + resultField: 'education_end_elementary_school_id', + where: { + relation: '=', + type: 'boolean', + field: 'reg_fund_af_t1' + } +}).addValue({ + name: 'education_middle_school', + table: 'escola', + tableField: 'reg_medio_medio_t1', + resultField: 'education_middle_school_id', + where: { + relation: '=', + type: 'boolean', + field: 'reg_medio_medio_t1' + } +}).addValue({ + name: 'education_professional', + table: 'escola', + tableField: 'educacao_profissional', + resultField: 'education_professional_id', + where: { + relation: '=', + type: 'boolean', + field: 'educacao_profissional' + } +}).addValue({ + name: 'education_eja', + table: 'escola', + tableField: 'ensino_eja', + resultField: 'education_eja_id', + where: { + relation: '=', + type: 'boolean', + field: 'ensino_eja' + } +}).addValue({ + name: 'min_year', + table: 'escola', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'max_year', + table: 'escola', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'school_building', + table: 'escola', + tableField: 'local_func_predio_escolar', + resultField: 'school_building', + where: { + relation: '=', + type: 'boolean', + field: 'local_func_predio_escolar' + } +}); +fulltimeEnrollmentApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + + req.sql.from('escola') + .field('escola.id') + .field('escola.ano_censo', 'year') + .field('escola.nome_escola', 'name') + .field('escola.estado_id', 'state_id') + .field('escola.municipio_id', 'city_id'); + next(); +}, query, response('school')); + +fulltimeEnrollmentApp.get('/count', cache('15 day'), rqfCount.parse(), (req, res, next) => { + let arrang = ["arranjo_creche", "arranjo_pre", "arranjo_fundamental_ai", "arranjo_fundamental_af", "arranjo_multietapa", "arranjo_ensino_medio", "ensino_eja", "educacao_profissional", "ensino_especial"]; + + req.sql.from('escola') + .field('COUNT(escola.id)', 'total') + .field("'Brasil'", 'name') + .field('escola.ano_censo', 'year') + .group('escola.ano_censo') + .order('escola.ano_censo') + .where('escola.situacao_funcionamento_pareada = 1 AND (escola.ensino_regular = 1 OR escola.ensino_eja=1 or escola.educacao_profissional=1)') + + //Transforma a query em OR se tiver o filtro do arranjo + if (req.filter.arrangement) { + let arrangementQuery = ""; + for (let i = 0; i < req.filter.arrangement.length - 1; i++) { + arrangementQuery += 'escola.' + arrang[req.filter.arrangement[i]] + ' = 1 OR '; + } + // o ultimo elemento precisa ser sem o OR + arrangementQuery += 'escola.' + arrang[req.filter.arrangement[req.filter.arrangement.length - 1]] + ' = 1'; + req.sql.where('' + arrangementQuery); + } + delete req.filter.arrangement + next(); +}, rqfCount.build(), query, id2str.transform(), addMissing(rqfCount), response('school')); + +module.exports = fulltimeEnrollmentApp; diff --git a/src/libs/routes_v1/iesTeachers.js b/src/libs/routes_v1/iesTeachers.js new file mode 100644 index 0000000000000000000000000000000000000000..d212d6aa9511dce702efb5cab55d11ee9cbbcef9 --- /dev/null +++ b/src/libs/routes_v1/iesTeachers.js @@ -0,0 +1,722 @@ +/* +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 iesTeachers = express.Router(); + +const libs = `${process.cwd()}/libs`; + +const squel = require('squel'); + +const query = require(`${libs}/middlewares/query`).query; + +const response = require(`${libs}/middlewares/response`); + +const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); + +const aggregateData = require(`${libs}/middlewares/aggregateData`); + +const id2str = require(`${libs}/middlewares/id2str`); + +const config = require(`${libs}/config`); + +const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware; + +let rqf = new ReqQueryFields(); + +iesTeachers.use(cache('15 day')); + +iesTeachers.get('/years', (req, res, next) => { + req.sql.from('docente_ies_agregado') + .field('DISTINCT docente_ies_agregado.ano_censo', 'year') + next(); +}, query, response('years')); + +iesTeachers.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')); + +iesTeachers.get('/ethnic_group', (req, res, next) => { + req.result = []; + for (let i = 1; i <= 6; ++i) { + req.result.push({ + id: i, + name: id2str.ethnicGroup(i) + }); + } + next(); +}, response('ethnic_group')); + +iesTeachers.get('/teacher_deficiency', (req, res, next) => { + req.result = []; + for (let i = 0; i <= 0; ++i) { + req.result.push({ + id: i, + name: id2str.teacherDeficiency(i) + }); + } + next(); +}, response('teacher_deficiency')); + +iesTeachers.get('/teacher_schooling', (req, res, next) => { + req.result = []; + for (let i = 1; i <= 5; ++i) { + req.result.push({ + id: i, + name: id2str.teacherSchooling(i) + }); + } + next(); +}, response('teacher_schooling')); + +iesTeachers.get('/work_regime', (req, res, next) => { + req.result = []; + for (let i = 1; i <= 5; ++i) { + req.result.push({ + id: i, + name: id2str.workRegime(i) + }); + } + next(); +}, response('work_regime')); + +iesTeachers.get('/age_range_ies', (req, res, next) => { + req.result = []; + for (let i = 1; i <= 8; ++i) { + req.result.push({ + id: i, + name: id2str.ageRangeIES(i) + }); + } + next(); +}, response('age_range_ies')); + +iesTeachers.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')); + +iesTeachers.get('/gender', (req, res, next) => { + req.result = []; + for (let i = 1; i <= 2; ++i) { + req.result.push({ + id: i, + name: id2str.gender(i) + }); + } + next(); +}, response('gender')); + + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'id', + table: 'docente_ies_agregado', + 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: 'docente_ies_agregado' + } +}).addValue({ + name: 'university', + table: 'docente_ies_agregado', + tableField: ['cod_ies', 'nome_ies'], + resultField: ['university_id', 'university_name'], + where: { + relation: '=', + type: 'integer', + field: 'cod_ies' + } +}).addValue({ + name: 'min_year', + table: 'docente_ies_agregado', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'max_year', + table: 'docente_ies_agregado', + tableField: '', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'qtd_doc_ex_fem', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_fem', + resultField: 'qtd_doc_ex_fem', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_fem' + } +}).addValue({ + name: 'qtd_doc_ex_masc', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_masc', + resultField: 'qtd_doc_ex_masc', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_masc' + } +}).addValue({ + name: 'qtd_doc_ex_branca', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_branca', + resultField: 'qtd_doc_ex_branca', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_branca' + } +}).addValue({ + name: 'qtd_doc_ex_preta', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_preta', + resultField: 'qtd_doc_ex_preta', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_preta' + } +}).addValue({ + name: 'qtd_doc_ex_parda', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_parda', + resultField: 'qtd_doc_ex_parda', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_parda' + } +}).addValue({ + name: 'qtd_doc_ex_amarela', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_amarela', + resultField: 'qtd_doc_ex_amarela', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_amarela' + } +}).addValue({ + name: 'qtd_doc_ex_indigena', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_indigena', + resultField: 'qtd_doc_ex_indigena', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_indigena' + } +}).addValue({ + name: 'teacher_deficiency', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_com_deficiencia', + resultField: 'teacher_deficiency_total', + where: { + relation: '=', + type: 'integer', + field: 'cod_ies' + } +}).addValue({ + name: 'qtd_doc_ex_0_29', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_0_29', + resultField: 'qtd_doc_ex_0_29', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_0_29' + } +}).addValue({ + name: 'qtd_doc_ex_30_34', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_30_34', + resultField: 'qtd_doc_ex_30_34', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_30_34' + } +}).addValue({ + name: 'qtd_doc_ex_35_39', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_35_39', + resultField: 'qtd_doc_ex_35_39', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_35_39' + } +}).addValue({ + name: 'qtd_doc_ex_40_44', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_40_44', + resultField: 'qtd_doc_ex_40_44', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_40_44' + } +}).addValue({ + name: 'qtd_doc_ex_45_49', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_45_49', + resultField: 'qtd_doc_ex_45_49', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_45_49' + } +}).addValue({ + name: 'qtd_doc_ex_50_54', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_50_54', + resultField: 'qtd_doc_ex_50_54', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_50_54' + } +}).addValue({ + name: 'qtd_doc_ex_55_59', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_55_59', + resultField: 'qtd_doc_ex_55_59', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_55_59' + } +}).addValue({ + name: 'qtd_doc_ex_60_mais', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_60_mais', + resultField: 'qtd_doc_ex_60_mais', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_60_mais' + } +}).addValue({ + name: 'qtd_tec_total', + table: 'docente_ies_agregado', + tableField: 'qtd_tec_total', + resultField: 'qtd_tec_total', + where: { + relation: '=', + type: 'integer', + field: 'qtd_tec_total' + } +}).addValue({ + name: 'qtd_tec_fundamental_incomp_fem', + table: 'docente_ies_agregado', + tableField: 'qtd_tec_fundamental_incomp_fem', + resultField: 'qtd_tec_fundamental_incomp_fem', + where: { + relation: '=', + type: 'integer', + field: 'qtd_tec_fundamental_incomp_fem' + } +}).addValue({ + name: 'qtd_tec_fundamental_incomp_masc', + table: 'docente_ies_agregado', + tableField: 'qtd_tec_fundamental_incomp_masc', + resultField: 'qtd_tec_fundamental_incomp_masc', + where: { + relation: '=', + type: 'integer', + field: 'qtd_tec_fundamental_incomp_masc' + } +}).addValue({ + name: 'qtd_tec_fundamental_comp_fem', + table: 'docente_ies_agregado', + tableField: 'qtd_tec_fundamental_comp_fem', + resultField: 'qtd_tec_fundamental_comp_fem', + where: { + relation: '=', + type: 'integer', + field: 'qtd_tec_fundamental_comp_fem' + } +}).addValue({ + name: 'qtd_tec_fundamental_comp_masc', + table: 'docente_ies_agregado', + tableField: 'qtd_tec_fundamental_comp_masc', + resultField: 'qtd_tec_fundamental_comp_masc', + where: { + relation: '=', + type: 'integer', + field: 'qtd_tec_fundamental_comp_masc' + } +}).addValue({ + name: 'qtd_tec_medio_fem', + table: 'docente_ies_agregado', + tableField: 'qtd_tec_medio_fem', + resultField: 'qtd_tec_medio_fem', + where: { + relation: '=', + type: 'integer', + field: 'qtd_tec_medio_fem' + } +}).addValue({ + name: 'qtd_tec_medio_masc', + table: 'docente_ies_agregado', + tableField: 'qtd_tec_medio_masc', + resultField: 'qtd_tec_medio_masc', + where: { + relation: '=', + type: 'integer', + field: 'qtd_tec_medio_masc' + } +}).addValue({ + name: 'qtd_tec_superior_fem', + table: 'docente_ies_agregado', + tableField: 'qtd_tec_superior_fem', + resultField: 'qtd_tec_superior_fem', + where: { + relation: '=', + type: 'integer', + field: 'qtd_tec_superior_fem' + } +}).addValue({ + name: 'qtd_tec_superior_masc', + table: 'docente_ies_agregado', + tableField: 'qtd_tec_superior_masc', + resultField: 'qtd_tec_superior_masc', + where: { + relation: '=', + type: 'integer', + field: 'qtd_tec_superior_masc' + } +}).addValue({ + name: 'qtd_tec_esp_fem', + table: 'docente_ies_agregado', + tableField: 'qtd_tec_esp_fem', + resultField: 'qtd_tec_esp_fem', + where: { + relation: '=', + type: 'integer', + field: 'qtd_tec_esp_fem' + } +}).addValue({ + name: 'qtd_tec_esp_masc', + table: 'docente_ies_agregado', + tableField: 'qtd_tec_esp_masc', + resultField: 'qtd_tec_esp_masc', + where: { + relation: '=', + type: 'integer', + field: 'qtd_tec_esp_masc' + } +}).addValue({ + name: 'qtd_tec_mestrado_fem', + table: 'docente_ies_agregado', + tableField: 'qtd_tec_mestrado_fem', + resultField: 'qtd_tec_mestrado_fem', + where: { + relation: '=', + type: 'integer', + field: 'qtd_tec_mestrado_fem' + } +}).addValue({ + name: 'qtd_tec_mestrado_masc', + table: 'docente_ies_agregado', + tableField: 'qtd_tec_mestrado_masc', + resultField: 'qtd_tec_mestrado_masc', + where: { + relation: '=', + type: 'integer', + field: 'qtd_tec_mestrado_masc' + } +}).addValue({ + name: 'qtd_tec_doutorado_fem', + table: 'docente_ies_agregado', + tableField: 'qtd_tec_doutorado_fem', + resultField: 'qtd_tec_doutorado_fem', + where: { + relation: '=', + type: 'integer', + field: 'qtd_tec_doutorado_fem' + } +}).addValue({ + name: 'qtd_tec_doutorado_masc', + table: 'docente_ies_agregado', + tableField: 'qtd_tec_doutorado_masc', + resultField: 'qtd_tec_doutorado_masc', + where: { + relation: '=', + type: 'integer', + field: 'qtd_tec_doutorado_mascc' + } +}).addValue({ + name: 'qtd_doc_ex_bra', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_bra', + resultField: 'qtd_doc_ex_bra', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_bra' + } +}).addValue({ + name: 'qtd_doc_ex_est', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_est', + resultField: 'qtd_doc_ex_est', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_est' + } +}).addValue({ + name: 'academic_organization', + table: 'docente_ies_agregado', + tableField: 'tipo_org_acad', + resultField: 'academic_organization_id', + where: { + relation: '=', + type: 'integer', + table: 'docente_ies_agregado', + field: 'tipo_org_acad' + } +}).addValue({ + name: 'qtd_doc_ex_int', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_int', + resultField: 'qtd_doc_ex_int', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_int' + } +}).addValue({ + name: 'qtd_doc_ex_de', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_de', + resultField: 'qtd_doc_ex_de', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_de' + } +}).addValue({ + name: 'qtd_doc_ex_int_sem_de', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_int_sem_de', + resultField: 'qtd_doc_ex_int_sem_de', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_int_sem_de' + } +}).addValue({ + name: 'qtd_doc_ex_parc', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_parc', + resultField: 'qtd_doc_ex_parc', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_parc' + } +}).addValue({ + name: 'qtd_doc_ex_hor', + table: 'docente_ies_agregado', + tableField: 'qtd_doc_ex_hor', + resultField: 'qtd_doc_ex_hor', + where: { + relation: '=', + type: 'integer', + field: 'qtd_doc_ex_hor' + } +}); + +iesTeachers.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + if ("university" in req.dims) { + if (req.query.dims && req.query.dims.includes('teacher_deficiency')) { + req.sql.from('docente_ies_agregado') + .field('SUM(docente_ies_agregado.qtd_doc_ex_com_deficiencia)', 'total_deficiency') + .field('docente_ies_agregado.ano_censo', 'year') + .field('docente_ies_agregado.cod_ies', 'university_id') + .field('docente_ies_agregado.nome_ies', 'university_name') + .group('docente_ies_agregado.cod_ies') + .group('docente_ies_agregado.nome_ies') + .group('docente_ies_agregado.ano_censo') + .order('docente_ies_agregado.ano_censo') + } else if (req.query.dims && req.query.dims.includes('gender')) + { + req.sql.from('docente_ies_agregado') + .field('SUM(docente_ies_agregado.qtd_doc_ex_masc)', 'total_masc') + .field('SUM(docente_ies_agregado.qtd_doc_ex_fem)', 'total_fem') + .field('docente_ies_agregado.ano_censo', 'year') + .field('docente_ies_agregado.cod_ies', 'university_id') + .field('docente_ies_agregado.nome_ies', 'university_name') + .group('docente_ies_agregado.ano_censo') + .group('docente_ies_agregado.cod_ies') + .group('docente_ies_agregado.nome_ies') + .order('docente_ies_agregado.ano_censo') + } else if(req.query.dims && req.query.dims.includes('age_range_ies')) + { + req.sql.from('docente_ies_agregado') + .field('SUM(docente_ies_agregado.qtd_doc_ex_0_29)', 'total_0_29') + .field('SUM(docente_ies_agregado.qtd_doc_ex_30_34)', 'total_30_34') + .field('SUM(docente_ies_agregado.qtd_doc_ex_35_39)', 'total_35_39') + .field('SUM(docente_ies_agregado.qtd_doc_ex_40_44)', 'total_40_44') + .field('SUM(docente_ies_agregado.qtd_doc_ex_45_49)', 'total_45_49') + .field('SUM(docente_ies_agregado.qtd_doc_ex_50_54)', 'total_50_54') + .field('SUM(docente_ies_agregado.qtd_doc_ex_55_59)', 'total_55_59') + .field('SUM(docente_ies_agregado.qtd_doc_ex_60_mais)', 'qtd_doc_ex_60_mais') + .field('docente_ies_agregado.ano_censo', 'year') + .field('docente_ies_agregado.cod_ies', 'university_id') + .field('docente_ies_agregado.nome_ies', 'university_name') + .group('docente_ies_agregado.ano_censo') + .group('docente_ies_agregado.cod_ies') + .group('docente_ies_agregado.nome_ies') + .order('docente_ies_agregado.ano_censo') + } else if(req.query.dims && req.query.dims.includes('ethnic_group')){ + req.sql.from('docente_ies_agregado') + .field('SUM(docente_ies_agregado.qtd_doc_ex_cor_nd)', 'total_nd') + .field('SUM(docente_ies_agregado.qtd_doc_ex_branca)', 'total_branca') + .field('SUM(docente_ies_agregado.qtd_doc_ex_preta)', 'total_preta') + .field('SUM(docente_ies_agregado.qtd_doc_ex_parda)', 'total_parda') + .field('SUM(docente_ies_agregado.qtd_doc_ex_amarela)', 'total_amarela') + .field('SUM(docente_ies_agregado.qtd_doc_ex_indigena)', 'total_indigena') + .field('docente_ies_agregado.ano_censo', 'year') + .field('docente_ies_agregado.cod_ies', 'university_id') + .field('docente_ies_agregado.nome_ies', 'university_name') + .group('docente_ies_agregado.ano_censo') + .group('docente_ies_agregado.cod_ies') + .group('docente_ies_agregado.nome_ies') + .order('docente_ies_agregado.ano_censo') + console.log(req.sql.toString()) + console.log(req.result) + }else if(req.query.dims && req.query.dims.includes('teacher_schooling')){ + req.sql.from('docente_ies_agregado') + .field('SUM(docente_ies_agregado.qtd_doc_ex_sem_grad)', 'total_sem_grad') + .field('SUM(docente_ies_agregado.qtd_doc_ex_grad)', 'total_grad') + .field('SUM(docente_ies_agregado.qtd_doc_ex_esp)', 'total_esp') + .field('SUM(docente_ies_agregado.qtd_doc_ex_mest)', 'total_mest') + .field('SUM(docente_ies_agregado.qtd_doc_ex_dout)', 'total_dout') + .field('docente_ies_agregado.ano_censo', 'year') + .field('docente_ies_agregado.cod_ies', 'university_id') + .field('docente_ies_agregado.nome_ies', 'university_name') + .group('docente_ies_agregado.ano_censo') + .group('docente_ies_agregado.cod_ies') + .group('docente_ies_agregado.nome_ies') + .order('docente_ies_agregado.ano_censo') + }else if(req.query.dims && req.query.dims.includes('academic_organization')){ + req.sql.from('docente_ies_agregado') + .field('SUM(docente_ies_agregado.qtd_doc_exe)', 'total') + .field('docente_ies_agregado.tipo_org_acad', 'org_acad') + .field('docente_ies_agregado.ano_censo', 'year') + .field('docente_ies_agregado.cod_ies', 'university_id') + .field('docente_ies_agregado.nome_ies', 'university_name') + .group('docente_ies_agregado.ano_censo') + .group('docente_ies_agregado.cod_ies') + .group('docente_ies_agregado.nome_ies') + .group('docente_ies_agregado.tipo_org_acad') + .order('docente_ies_agregado.ano_censo') + }else if(req.query.dims && req.query.dims.includes('work_regime')){ + req.sql.from('docente_ies_agregado') + .field('SUM(docente_ies_agregado.qtd_doc_exe)', 'total') + .field('SUM(docente_ies_agregado.qtd_doc_ex_int)', 'total_tempo_integral') + .field('SUM(docente_ies_agregado.qtd_doc_ex_de)', 'total_de') + .field('SUM(docente_ies_agregado.qtd_doc_ex_int_sem_de)', 'total_tempo_integral_sem_de') + .field('SUM(docente_ies_agregado.qtd_doc_ex_parc)', 'total_tempo_parcial') + .field('SUM(docente_ies_agregado.qtd_doc_ex_hor)', 'total_horista') + .field('docente_ies_agregado.ano_censo', 'year') + .field('docente_ies_agregado.cod_ies', 'university_id') + .field('docente_ies_agregado.nome_ies', 'university_name') + .group('docente_ies_agregado.ano_censo') + .group('docente_ies_agregado.cod_ies') + .group('docente_ies_agregado.nome_ies') + .group('docente_ies_agregado.tipo_org_acad') + .order('docente_ies_agregado.ano_censo') + } + else { + req.sql.from('docente_ies_agregado') + .field('sum(docente_ies_agregado.qtd_doc_exe)', 'total') + .field('docente_ies_agregado.ano_censo', 'year') + .field('docente_ies_agregado.cod_ies', 'university_id') + .field('docente_ies_agregado.nome_ies', 'university_name') + .group('docente_ies_agregado.ano_censo') + .group('docente_ies_agregado.cod_ies') + .group('docente_ies_agregado.nome_ies') + .order('docente_ies_agregado.ano_censo') + console.log(req.sql.toString()) + } + next(); + } + else { + res.status(400); + next({ + status: 400, + message: 'Wrong/No filter specified' + }); + } +}, query, aggregateData, id2str.transform(false), response('teacher_ies')); + +module.exports = iesTeachers; diff --git a/src/libs/routes_v1/newPnad.js b/src/libs/routes_v1/newPnad.js index 5bfb7b8a23e5badace6614815f84ba4ae40515b3..58da21fbce84e310519b6a53d1378a908955f7c5 100644 --- a/src/libs/routes_v1/newPnad.js +++ b/src/libs/routes_v1/newPnad.js @@ -1,4 +1,4 @@ -/* + /* Copyright (C) 2024 Centro de Computacao Cientifica e Software Livre Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR