diff --git a/src/libs/routes_v1/api.js b/src/libs/routes_v1/api.js index 9880ac847b42e8f32dde87e76a57ac81fb52d088..8d463a0469940971d0505c77667c5e89ce70965f 100644 --- a/src/libs/routes_v1/api.js +++ b/src/libs/routes_v1/api.js @@ -171,10 +171,17 @@ const adjustedLiquidFrequency = require(`${libs}/routes_v1/adjustedLiquidFrequen const iliteracyRate = require(`${libs}/routes_v1/iliteracyRate`); +// comentei para ver se o api.get abaixo ia dar certo (nao deu) +// const superiorEnrollmentAggregate = require(`${libs}/routes_v1/superiorEnrollmentAggregate`); + api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API v1 is running' }); }); +api.get('/superior_enrollment_aggregate', (req, res) => { + res.json({ msg: 'oi' }); +}) + // mount API routes_v1 api.use('/test', test); api.use('/user', user); @@ -244,6 +251,7 @@ api.use('/superior_education_conclusion_tax', superiorEducationConclusionTax) api.use('/basic_education_conclusion', basicEducationConclusion); api.use('/adjusted_liquid_frequency', adjustedLiquidFrequency); api.use('/iliteracy_rate', iliteracyRate); +// api.use('/superior_enrollment_aggregate', superiorEnrollmentAggregate); //Publication api.use('/publication', publication); diff --git a/src/libs/routes_v1/superiorEnrollmentAggregate.js b/src/libs/routes_v1/superiorEnrollmentAggregate.js new file mode 100644 index 0000000000000000000000000000000000000000..800fbfe1ce25b31ff12192ac6b91e94177405eda --- /dev/null +++ b/src/libs/routes_v1/superiorEnrollmentAggregate.js @@ -0,0 +1,526 @@ +/* +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 { result } = require('lodash'); + +const superiorEnrollmentAggregateApp = 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 ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); + +const aggregateData = require(`${libs}/middlewares/aggregateData`); + +const id2str = require(`${libs}/middlewares/id2str`); + +const config = require(`${libs}/config`); + +const addMissing = require(`${libs}/middlewares/addMissing`); + +const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware; + +superiorEnrollmentAggregateApp.use(cache('15 day')); + +let rqf = new ReqQueryFields(); + +// superiorEnrollmentAggregateApp.get('/years', (req, res, next) => { +// req.sql.from('escola') +// .field('DISTINCT escola.ano_censo', 'year') +// .where('escola.ano_censo >= 2021') +// next(); +// }, query, response('years')); + +// superiorEnrollmentAggregateApp.get('/adm_dependency', (req, res, next) => { +// req.result = [] + +// for (let i = 1; i <= 5; i++) { +// req.result.push({ +// id: i, name: id2str.admDependency(i) +// }); +// } +// next(); +// }, response('adm_dependency')); + +// superiorEnrollmentAggregateApp.get('/adm_dependency_detailed', (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')); + +// superiorEnrollmentAggregateApp.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')); + +// superiorEnrollmentAggregateApp.get('/education_level_mod_agg', (req, res, next) => { +// req.result = [] + +// for (let i = 1; i <= 13; i++) { +// req.result.push({ +// id: i, name: id2str.educationLevelMod(i) +// }); +// } +// next(); +// }, response('education_level_mod_agg')); + +// superiorEnrollmentAggregateApp.get('/integral_time_agg', (req, res, next) => { +// req.result = [] + +// for (let i = 0; i <= 3; i++) { +// req.result.push({ +// id: i, name: id2str.integralTime(i) +// }); +// } +// next(); +// }, response('integral_time_agg')); + +// superiorEnrollmentAggregateApp.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')); + +// superiorEnrollmentAggregateApp.get('/diff_location', (req, res, next) => { +// req.result = [] + +// for (let i = 0; i < 4; i++) { +// req.result.push({ +// id: i, name: id2str.diffLocation(i) +// }); +// } + +// req.result.push({ +// id: 8, name: 'Área onde se localizam povos e comunidades tradicionais' +// }) + +// next(); +// }, response('diff_location')); + +// superiorEnrollmentAggregateApp.get('/modality_integral_time', (req, res, next) => { +// req.result = [] + +// for (let i = 0; i <= 7; i++) { +// req.result.push({ +// id: i, name: id2str.educationLevelBasic(i) +// }); +// } + +// next(); +// }, response('modality_integral_time')); + +// superiorEnrollmentAggregateApp.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')); + +// superiorEnrollmentAggregateApp.get('/age_range', (req, res, next) => { +// req.result = [] + +// for (let i = 1; i <= 7; i++) { +// req.result.push({ +// id: i, name: id2str.ageRangeAggregate(i) +// }); +// } + +// next(); +// }, response('age_range')); + +// superiorEnrollmentAggregateApp.get('/ethnic_group', (req, res, next) => { +// req.result = [] + +// for (let i = 0; i <= 6; i++) { +// req.result.push({ +// id: i, name: id2str.ethnicGroup(i) +// }); +// } + +// next(); +// }, response('ethnic_group')); + +// superiorEnrollmentAggregateApp.get('/period_agg', (req, res, next) => { +// req.result = [] + +// for (let i = 0; i <= 5; i++) { +// req.result.push({ +// id: i, name: id2str.period(i) +// }); +// } + +// next(); +// }, response('period_agg')); + +// superiorEnrollmentAggregateApp.get('/region', (req, res, next) => { +// req.result = [] + +// for (let i = 0; i <= 5; i++) { +// req.result.push({ +// id: i, name: id2str.regionCode(i) +// }); +// } + +// next(); +// }, response('period_agg')); + +// superiorEnrollmentAggregateApp.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) +// }); +// } +// } + +// next(); +// }, response('state')); + +// superiorEnrollmentAggregateApp.get('/special_education', (req, res, next) => { +// req.result = [] + +// for (let i = 1; i <= 2; i++) { +// req.result.push({ +// id: i, name: id2str.specialEducation(i) +// }); +// } + +// next(); +// }, response('special_education')); + + +// rqf.addField({ +// name: 'filter', +// field: false, +// where: true +// }).addField({ +// name: 'dims', +// field: true, +// where: false +// }).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: 'education_level_mod', +// table: 'escola', +// tableField: 'etapas_mod_ensino_segmento_id', +// resultField: 'education_level_mod_id', +// where: { +// relation: '=', +// type: 'integer', +// field: 'etapas_mod_ensino_segmento_id' +// } +// }).addValue({ +// name:'integral_time', +// table: 'escola', +// tableField: 'tempo_integral', +// resultField: 'integral_time_id', +// where: { +// relation: '=', +// type: 'integer', +// field: 'tempo_integral' +// } +// }).addValue({ +// name: 'education_level_short', +// table: 'escola', +// tableField: 'etapa_resumida', +// resultField: 'education_level_short_id', +// where: { +// relation: '=', +// type: 'integer', +// field: 'etapa_resumida' +// } +// }).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: '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: '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', +// }, +// }).addValueToField({ +// name: 'state', +// table: 'estado', +// tableField: ['nome', 'id'], +// resultField: ['state_name', 'state_id'], +// where: { +// relation: '=', +// type: 'integer', +// field: 'id' +// }, +// join: { +// primary: 'id', +// foreign: 'estado_id', +// foreignTable: 'escola' +// } +// }, 'dims').addValueToField({ +// name: 'state', +// table: 'estado', +// tableField: 'nome', +// resultField: 'state_name', +// where: { +// relation: '=', +// type: 'integer', +// field: 'id' +// }, +// join: { +// primary: 'id', +// foreign: 'estado_id', +// foreignTable: 'escola' +// } +// }, 'filter').addValueToField({ +// name: 'city', +// table: 'municipio', +// tableField: ['nome', 'id'], +// resultField: ['city_name', 'city_id'], +// where: { +// relation: '=', +// type: 'integer', +// field: 'id' +// }, +// join: { +// primary: 'id', +// foreign: 'municipio_id', +// foreignTable: 'escola' +// } +// }, 'dims').addValueToField({ +// name: 'city', +// table: 'municipio', +// tableField: 'nome', +// resultField: 'city_name', +// where: { +// relation: '=', +// type: 'integer', +// field: 'id' +// }, +// join: { +// primary: 'id', +// foreign: 'municipio_id', +// foreignTable: 'escola' +// } +// }, 'filter').addValueToField({ +// name: 'school', +// table: 'escola', +// tableField: ['nome_escola', 'id'], +// resultField: ['school_name', 'school_id'], +// where: { +// relation: '=', +// type: 'integer', +// field: 'id' +// }, +// join: { +// primary: ['id', 'ano_censo'], +// foreign: ['escola_id', 'ano_censo'], +// foreignTable: 'escola' +// } +// }, 'dims').addValueToField({ +// name: 'locale_id', +// table: 'escola', +// tableField: 'localizacao_id', +// resultField: 'locale_id', +// where: { +// relation: '=', +// type: 'integer', +// field: 'localizacao_id' +// } +// }, 'dims').addValueToField({ +// name: 'school_id', +// table: 'escola', +// tableField: 'id', +// resultField: 'school_id', +// where: { +// relation: '=', +// type: 'integer', +// field: 'id' +// }, +// join: { +// primary: ['id', 'ano_censo'], +// foreign: ['escola_id', 'ano_censo'], +// foreignTable: 'escola' +// } +// }, 'dims').addValueToField({ +// name: 'school', +// table: 'escola', +// tableField: 'nome_escola', +// resultField: 'school_name', +// where: { +// relation: '=', +// type: 'integer', +// field: 'id' +// }, +// join: { +// primary: ['id', 'ano_censo'], +// foreign: ['escola_id', 'ano_censo'], +// foreignTable: 'escola' +// } +// }, 'filter').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: 'government_agreement', +// table: 'escola', +// tableField: 'dependencia_convenio_publico', +// resultField: 'government_agreement_id', +// where: { +// relation: '=', +// type: 'integer', +// field: 'dependencia_convenio_publico' +// } +// }); + +superiorEnrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + + req.sql.field('ano_censo', 'Ano') + .field('sum(qtd_matriculas)', 'Número de Matrículas') + .from('curso_superior_agregado') + .where('tp_nivel_acad = 1') + .where('qtd_cursos = 1') + .group('ano_censo') + .order('ano_censo'); + + console.log(req.sql.toString()); + next(); +}, id2str.transform(false), response('superiorEnrollmentAggregate')); + +module.exports = superiorEnrollmentAggregateApp;