diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c3d8ea79aefb3b458485b35211c3be9dc9d0cf3..a96cd52b986189a1832994fb2d3f67ee8fafabfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 1.14.2 - 2020-07-14 +## Changed +- Courses route +- Addmissing + ## 1.14.1 - 2020-06-24 - Fix gross and liquid enrollment ratio indicators diff --git a/src/libs/middlewares/addMissing.js b/src/libs/middlewares/addMissing.js index 1050a1df0332f922313dadcc51d10ae84bcb41d8..298deaee0bf7bc9430d24e9c1d6bd8262e00347d 100644 --- a/src/libs/middlewares/addMissing.js +++ b/src/libs/middlewares/addMissing.js @@ -72,7 +72,7 @@ module.exports = function addMissing(rqf) { } if (dimsValues[rqfName].indexOf(r[rqfName]) === -1) { - if (['school', 'city', 'state', 'region', 'arrangement'].includes(dim)) { // those should be ordered by its name + if (['school', 'arrangement'].includes(dim)) { // those should be ordered by its name let namePosition = binarySearch(r[secondaryRqfName], dimsNames[secondaryRqfName], 0, dimsNames[secondaryRqfName].length) // find the position of the name in alphabetical order and keep the names vector ordered dimsValues[rqfName].splice(namePosition.pos, 0, r[rqfName]); dimsNames[secondaryRqfName].splice(namePosition.pos, 0, r[secondaryRqfName]); diff --git a/src/libs/routes/courseCount.js b/src/libs/routes/courseCount.js index 9a7f9d4e9ca5f92bd74c7d0282dbfc70aea97399..fce35171d07995e2a82b9bae60ad4e0ea2918eaf 100644 --- a/src/libs/routes/courseCount.js +++ b/src/libs/routes/courseCount.js @@ -40,12 +40,8 @@ const config = require(`${libs}/config`); const addMissing = require(`${libs}/middlewares/addMissing`); -const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware; - let rqf = new ReqQueryFields(); -courseCountApp.use(cache('15 day')); - courseCountApp.get('/upper_adm_dependency', (req, res, next) => { req.result = []; for(let i = 1; i <= 7; ++i) { @@ -59,7 +55,8 @@ courseCountApp.get('/upper_adm_dependency', (req, res, next) => { courseCountApp.get('/years', (req, res, next) => { req.sql.from('curso_ens_superior') - .field('DISTINCT curso_ens_superior.ano_censo', 'year'); + .field('DISTINCT curso_ens_superior.ano_censo', 'year') + .where('curso_ens_superior.ano_censo > 2010'); next(); }, query, response('years')); @@ -81,15 +78,6 @@ courseCountApp.get('/academic_organization', (req, res, next) => { next(); }, response('academic_organization')); -courseCountApp.get('/capital', (req, res, next) => { - req.result = [ - {id: null, name: 'Não Classificado'}, - {id: 0, name: 'Não'}, - {id: 1, name: 'Sim'} - ]; - next(); -}, response('capital')); - courseCountApp.get('/ocde_geral', (req, res, next) => { req.result = []; for(let i = 1; i <= 8; ++i) { @@ -139,6 +127,55 @@ courseCountApp.get('/ocde_detailed', (req, res, next) => { next(); }, response('ocde_detailed')); +courseCountApp.get('/cine_geral', (req, res, next) => { + req.result = []; + for(let i = 0; i <= 10; ++i) { + req.result.push({ + id: i, + name: id2str.cineGeral(i) + }); + }; + next(); +}, response('cine_geral')); + +courseCountApp.get('/cine_specific', (req, res, next) => { + req.result = []; + const defaultCase = null; + for(let i = 1; i <= 104; ++i) { + let obj = { + id: i, + name: id2str.cineSpecific(i) + }; + if (obj.name !== id2str.cineSpecific(defaultCase)){ + req.result.push(obj); + } + }; + req.result.push({ + id: defaultCase, + name: id2str.cineSpecific(defaultCase) + }); + next(); +}, response('cine_specific')); + +courseCountApp.get('/cine_detailed', (req, res, next) => { + req.result = []; + const defaultCase = null; + for(let i = 11; i <= 1041; ++i) { + let obj = { + id: i, + name: id2str.cineDetailed(i) + }; + if (obj.name !== id2str.cineDetailed(defaultCase)){ + req.result.push(obj); + } + }; + req.result.push({ + id: defaultCase, + name: id2str.cineDetailed(defaultCase) + }); + next(); +}, response('cine_detailed')); + courseCountApp.get('/academic_level', (req, res, next) => { req.result = []; for(let i = 1; i <= 4; ++i) { @@ -186,6 +223,13 @@ courseCountApp.get('/university', (req, res, next) => { next(); }, query, response('university')); +courseCountApp.get('/localoffer', (req, res, next) => { + req.sql.from('localoferta_ens_superior', 'l') + .field('DISTINCT l.nome', 'localoffer_name') + .field('l.cod_local_oferta', 'localoffer_id'); + next(); +}, query, response('localoffer')); + rqf.addField({ name: 'filter', field: false, @@ -196,49 +240,67 @@ rqf.addField({ where: false }).addValue({ name: 'region', - table: 'regiao', - tableField: ['nome', 'id'], + table: 'localoferta_ens_superior', + tableField: ['nome_regiao', 'cod_regiao'], resultField: ['region_name', 'region_id'], where: { relation: '=', type: 'integer', - field: 'id' + field: 'cod_regiao', + table: 'localoferta_ens_superior' }, join: { - primary: 'nome', - foreign: 'nome_regiao_curso', + primary: ['ano_censo', 'cod_curso'], + foreign: ['ano_censo', 'cod_curso'], foreignTable: 'curso_ens_superior' } }).addValue({ name: 'state', - table: 'estado', - tableField: ['nome', 'id'], + table: 'localoferta_ens_superior', + tableField: ['sigla_uf_t', 'cod_uf_t'], resultField: ['state_name', 'state_id'], where: { relation: '=', type: 'integer', - field: 'id' + field: 'cod_uf', + table: 'localoferta_ens_superior' }, join: { - primary: 'id', - foreign: 'cod_uf_curso', + primary: ['ano_censo', 'cod_curso'], + foreign: ['ano_censo', 'cod_curso'], foreignTable: 'curso_ens_superior' } }).addValue({ name: 'city', - table: 'municipio', - tableField: ['nome', 'id'], - resultField: ['city_name', 'city_id'], + table: 'localoferta_ens_superior', + tableField: ['cod_municipio_t', 'nome_municipio_t'], + resultField: ['city_id', 'city_name'], where: { relation: '=', type: 'integer', - field: 'cod_municipio_curso', - table: '@' + field: 'cod_municipio', + table: 'localoferta_ens_superior' }, join: { - primary: 'id', - foreign: 'cod_municipio_curso', - foreignTable: '@' + primary: ['ano_censo', 'cod_curso'], + foreign: ['ano_censo', 'cod_curso'], + foreignTable: 'curso_ens_superior' + } +}).addValue({ + name: 'localoffer', + table: 'localoferta_ens_superior', + tableField: ['cod_local_oferta', 'nome'], + resultField: ['localoffer_id', 'localoffer_name'], + where: { + relation: '=', + type: 'integer', + field: 'cod_curso', + table: 'curso_ens_superior' + }, + join: { + primary: ['ano_censo', 'cod_curso'], + foreign: ['ano_censo', 'cod_curso'], + foreignTable: 'curso_ens_superior' } }).addValue({ name: 'university', @@ -270,16 +332,6 @@ rqf.addField({ type: 'integer', field: 'cod_organizacao_academica' } -}).addValue({ - name:'capital', - table: 'curso_ens_superior', - tableField: 'tfd_capital_curso', - resultField: 'capital_id', - where: { - relation: '=', - type: 'integer', - field: 'tfd_capital_curso' - } }).addValue({ name:'course', table: 'curso_ens_superior', @@ -314,12 +366,42 @@ rqf.addField({ name:'ocde_detailed', table: 'curso_ens_superior', tableField: ['cod_ocde_area_detalhada', 'nome_ocde_area_detalhada'], - resultField: ['ocde_detailed_id', 'ocde_datailed_name'], + resultField: ['ocde_detailed_id', 'ocde_detailed_name'], where: { relation: '=', type: 'integer', field: 'cod_ocde_area_detalhada' } +}).addValue({ + name:'cine_specific', + table: 'curso_ens_superior', + tableField: ['cod_cine_area_especifica', 'nome_cine_area_especifica'], + resultField: ['cine_specific_id', 'cine_specific_name'], + where: { + relation: '=', + type: 'integer', + field: 'cod_cine_area_especifica' + } +}).addValue({ + name:'cine_geral', + table: 'curso_ens_superior', + tableField: ['cod_cine_area_geral', 'nome_cine_area_geral'], + resultField: ['cine_geral_id', 'cine_geral_name'], + where: { + relation: '=', + type: 'integer', + field: 'cod_cine_area_geral' + } +}).addValue({ + name:'cine_detailed', + table: 'curso_ens_superior', + tableField: ['cod_cine_area_detalhada', 'nome_cine_area_detalhada'], + resultField: ['cine_detailed_id', 'cine_detailed_name'], + where: { + relation: '=', + type: 'integer', + field: 'cod_cine_area_detalhada' + } }).addValue({ name:'academic_level', table: 'curso_ens_superior', @@ -353,12 +435,12 @@ rqf.addField({ }).addValue({ name:'night_time', table: 'curso_ens_superior', - tableField: 'noturno_curso', + tableField: 'noturno_curso_t', resultField: 'night_time_id', where: { relation: '=', type: 'boolean', - field: 'noturno_curso' + field: 'noturno_curso_t' } }).addValue({ name:'situation', @@ -405,7 +487,41 @@ rqf.addField({ }); courseCountApp.get('/', rqf.parse(), (req, res, next) => { - if ("university" in req.dims) { + if ("localoffer" in req.dims) { + if ("university" in req.dims) { + req.sql.from('curso_ens_superior') + .field('curso_ens_superior.ano_censo', 'year') + .field('COUNT(localoferta_ens_superior.cod_local_oferta)', 'total') + .where('curso_ens_superior.tipo_atributo_ingresso <> 1 OR curso_ens_superior.tipo_atributo_ingresso is NULL') + .where('curso_ens_superior.cod_nivel_academico = 1') + .group('curso_ens_superior.ano_censo') + .order('curso_ens_superior.ano_censo') + .order('localoferta_ens_superior.cod_local_oferta'); + } else { + req.sql.from('curso_ens_superior') + .field('curso_ens_superior.ano_censo', 'year') + .field('COUNT(localoferta_ens_superior.cod_local_oferta)', 'total') + .field('localoferta_ens_superior.cod_ies', 'university_id') + .field('curso_ens_superior.nome_ies', 'university_name') + .where('curso_ens_superior.tipo_atributo_ingresso <> 1 OR curso_ens_superior.tipo_atributo_ingresso is NULL') + .where('curso_ens_superior.cod_nivel_academico = 1') + .group('curso_ens_superior.ano_censo') + .group('localoferta_ens_superior.cod_ies') + .group('curso_ens_superior.nome_ies') + .order('curso_ens_superior.ano_censo') + .order('localoferta_ens_superior.cod_local_oferta'); + } + } else if (("state" in req.dims) || ("city" in req.dims) || ("region" in req.dims) || + ("state" in req.filter) || ("city" in req.filter) || ("region" in req.filter)) { + req.sql.from('curso_ens_superior') + .field('COUNT(DISTINCT curso_ens_superior.cod_curso)', 'total') + .field("'Brasil'", 'name') + .field('curso_ens_superior.ano_censo', 'year') + .group('curso_ens_superior.ano_censo') + .order('curso_ens_superior.ano_censo') + .where('curso_ens_superior.tipo_atributo_ingresso <> 1 OR curso_ens_superior.tipo_atributo_ingresso is NULL') + .where('curso_ens_superior.cod_nivel_academico = 1'); + } else if ("university" in req.dims) { req.sql.from('curso_ens_superior') .field('COUNT(curso_ens_superior.cod_curso)', 'total') .field("'Brasil'", 'name') @@ -416,8 +532,7 @@ courseCountApp.get('/', rqf.parse(), (req, res, next) => { .order('curso_ens_superior.ano_censo') .where('curso_ens_superior.tipo_atributo_ingresso <> 1 OR curso_ens_superior.tipo_atributo_ingresso is NULL') .where('curso_ens_superior.cod_nivel_academico = 1'); - } - else { + } else { req.sql.from('curso_ens_superior') .field('COUNT(curso_ens_superior.cod_curso)', 'total') .field("'Brasil'", 'name')