diff --git a/src/libs/routes_v1/superiorEnrollmentAggregate.js b/src/libs/routes_v1/superiorEnrollmentAggregate.js index e2c477283bedcd3181be0d39331d420bdffc541e..e37d4cb5f55d37c1d9654497e26f86ab11f76777 100644 --- a/src/libs/routes_v1/superiorEnrollmentAggregate.js +++ b/src/libs/routes_v1/superiorEnrollmentAggregate.js @@ -52,193 +52,80 @@ 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 = [] +superiorEnrollmentAggregateApp.get('/years', (req, res, next) => { + req.sql.from('curso_superior_agregado') + .field('DISTINCT curso_superior_agregado.ano_censo', 'year') + .where('curso_superior_agregado.ano_censo >= 2020') + next(); +}, query, response('years')); -// for (let i = 1; i <= 2; i++) { -// req.result.push({ -// id: i, name: id2str.specialEducation(i) -// }); -// } +superiorEnrollmentAggregateApp.get('/qtd_graduates', (req, res, next) => { + req.sql.from('curso_superior_agregado') + .field('DISTINCT SUM(curso_superior_agregado.qtd_concluintes)', 'qtd_graduates') + .where('curso_superior_agregado.ano_censo >= 2020') + next(); + +}) -// next(); -// }, response('special_education')); +superiorEnrollmentAggregateApp.get('/tp_categ_adm', (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('/cine_global', (req, res, next) => { + req.result = []; + for(let i = 0; i <= 10; ++i) { + req.result.push({ + id: i, + name: id2str.cineGeral(i) + }); + }; + next(); +}, response('cine_global')); + +superiorEnrollmentAggregateApp.get('/cine_specific', (req, res, next) => { + req.result = []; + const defaultCase = null; + for(let i = 0; i <= 104; ++i) { + let obj = { + id: i, + name: id2str.cineSpecific(i) + }; + if (obj.name !== id1str.cineSpecific(defaultCase)){ + req.result.push(obj); + } + }; + req.result.push({ + id: defaultCase, + name: id2str.cineSpecific(defaultCase) + }); + next(); +}, response('cine_specific')); + +superiorEnrollmentAggregateApp.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')); rqf.addField({ name: 'filter', @@ -373,58 +260,45 @@ rqf.addField({ type: 'integer', field: 'tp_org_acad' } -}); - -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('cod'); - 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.cod; - newObj.partial = objMatch.cod; - // newObj.total = (objMatch.total / result.total) * 100; - match.push(newObj); - } - }); +}).addValue({ + name: 'region_agg', + table: 'curso_superior_agregado', + tableField: 'nome_reg', + resultField: 'reg_name', + where: { + relation: '=', + type: 'integer', + field: 'cod_reg' + } +}).addValue({ + name: 'uf_agg', + table: 'curso_superior_agregado', + tableField: 'nome_uf', + resultField: 'uf_name', + where: { + relation: '=', + type: 'integer', + field: 'cod_uf' + } +}).addValue({ + name: 'mun_agg', + table: 'curso_superior_agregado', + tableField: 'nome_mun', + resultField: 'mun_name', + where: { + relation: '=', + type: 'integer', + field: 'cod_mun' + } +}) - return match; -} superiorEnrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { - req.querySet = []; - - let basic = req.sql.clone(); - let curso = req.sql.clone(); - let ies = req.sql.clone(); - basic.field('curso_superior_agregado.ano_censo', 'year'); + req.sql.field('curso_superior_agregado.ano_censo', 'year'); if (req.query.dims && req.query.dims.includes("ethnic_group")){ - basic.field.field('sum(qtd_mat_branca)', 'total_branca') + req.sql.field.field('sum(qtd_mat_branca)', 'total_branca') .field('sum(qtd_mat_preta)', 'total_preta') .field('sum(qtd_mat_parda)', 'total_parda') .field('sum(qtd_mat_amarela)', 'total_amarela') @@ -432,12 +306,12 @@ superiorEnrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, nex .field('sum(qtd_mat_cor_nao_declarada)', 'total_nd'); } else if (req.query.dims && req.query.dims.includes("school_type")){ - basic.field('sum(qtd_mat_proces_publica)', 'total_publica') + req.sql.field('sum(qtd_mat_proces_publica)', 'total_publica') .field('sum(qtd_mat_proces_privada)', 'total_privada') .field('sum(qtd_mat_proces_nao_informada)', 'total_nao_informada'); } else if (req.query.dims && req.query.dims.includes("age_range_cescu")){ - basic.field('sum(qtd_mat_0_17)', 'total_0_17') + req.sql.field('sum(qtd_mat_0_17)', 'total_0_17') .field('sum(qtd_mat_18_24)', 'total_18_24') .field('sum(qtd_mat_25_29)', 'total_25_29') .field('sum(qtd_mat_30_34)', 'total_30_34') @@ -447,59 +321,26 @@ superiorEnrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, nex .field('sum(qtd_mat_60_mais)', 'total_60_mais'); } else if (req.query.dims && req.query.dims.includes("gender")){ - basic.field('sum(qtd_mat_fem)', 'total_fem') + req.sql.field('sum(qtd_mat_fem)', 'total_fem') .field('sum(qtd_mat_masc)', 'total_masc'); } else if (req.query.dims && req.query.dims.includes("modality_shift_superior")){ - basic.field('sum(qtd_mat_diurno)', 'total_diurno') + req.sql.field('sum(qtd_mat_diurno)', 'total_diurno') .field('sum(qtd_mat_noturno)', 'total_noturno'); } - else if (req.query.dims && req.query.dims.includes("region")){ - curso.field('qtd_matriculas', 'enrollment') - curso.field('cod_reg', 'cod') - curso.field('nome_reg', 'cod_name') - .where('tp_nivel_acad = 1') - .from('curso_superior_agregado') - .group('ano_censo') - .order('ano_censo'); - - ies.field('nome_regiao_ies', 'cod_name') - .where('tp_nivel_acad = 1') - .from('ies_ens_superior') - .where('ano_censo > 2019') - .group('ano_censo') - .order('ano_censo'); - } else { - basic.field('SUM(qtd_matriculas)', 'enrollment'); + req.sql.field('SUM(qtd_matriculas)', 'enrollment'); } - basic.from('curso_superior_agregado') - .from('ies_ens_superior') - // .join('ies_ens_superior', null, 'ies_ens_superior.ano_censo = curso_superior_agregado.ano_censo') + req.sql.from('curso_superior_agregado') .where('tp_nivel_acad = 1') .group('curso_superior_agregado.ano_censo') .order('curso_superior_agregado.ano_censo'); - // console.log(req.sql.toString()); - // // console.log(req.query.dims); - // console.log(req.sql.result); - req.querySet.push(basic); - req.querySet.push(curso); - req.querySet.push(ies); + console.log(req.sql.toString()); next(); -}, multiQuery, query, aggregateData, id2str.transform(false), response('superior_enrollment_aggregate'), (req, res, next) => { - - if (req.result[1] || req.result[2]){ - let newObj = matchQueries(req.result[1], req.result[2]); - req.result = newObj; - } - else { - req.result = req.result[0]; - } - next(); -}); +}, multiQuery, query, aggregateData, id2str.transform(false), response('superior_enrollment_aggregate')); module.exports = superiorEnrollmentAggregateApp;