Skip to content
Snippets Groups Projects
Commit f87d17d4 authored by Fernando Erd's avatar Fernando Erd :ok_hand:
Browse files

Fix six joins

parent 5b050304
No related branches found
No related tags found
No related merge requests found
Pipeline #18453 failed
...@@ -396,7 +396,7 @@ classCountApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { ...@@ -396,7 +396,7 @@ classCountApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
}, response('class_count')); }, response('class_count'));
// SimCAQ // SimCAQ
classCountApp.get('/count', rqf.parse(), rqf.build(), (req, res, next) => { classCountApp.get('/count', rqf.parse(), (req, res, next) => {
req.sql.field("'Brasil'", 'name') req.sql.field("'Brasil'", 'name')
.field('turma.ano_censo', 'year') .field('turma.ano_censo', 'year')
.field('AVG(turma.num_matricula)', 'average') .field('AVG(turma.num_matricula)', 'average')
...@@ -409,52 +409,6 @@ classCountApp.get('/count', rqf.parse(), rqf.build(), (req, res, next) => { ...@@ -409,52 +409,6 @@ classCountApp.get('/count', rqf.parse(), rqf.build(), (req, res, next) => {
.order('turma.ano_censo') .order('turma.ano_censo')
.where('turma.tipo_turma_id = 0 AND turma.dependencia_adm_id <= 3 AND ((turma.etapa_resumida >= 1 AND turma.etapa_resumida <= 7) OR turma.etapa_resumida = 99)'); .where('turma.tipo_turma_id = 0 AND turma.dependencia_adm_id <= 3 AND ((turma.etapa_resumida >= 1 AND turma.etapa_resumida <= 7) OR turma.etapa_resumida = 99)');
next(); next();
}, rqf.build(), query, id2str.transform(), (req, res, next) => { }, rqf.build(), query, id2str.transform(), response('class_count'));
req.partial = [];
if((req.dims) && (req.dims.size == 1)) {
req.partial = req.result;
// Se a consulta anterior selecionou dimensão:
// Considera apenas os anos escolhidos na consulta anterior para contar o número total de alunos
let yearFilter = {};
if("min_year" in req.filter)
yearFilter.min_year = req.filter.min_year;
if("max_year" in req.filter)
yearFilter.max_year = req.filter.max_year;
req.resetSql();
req.dims = {};
req.filter = yearFilter;
req.sql.field("'Brasil'", 'name')
.field('turma.ano_censo', 'year')
.field('AVG(turma.num_matricula)', 'average')
.field('MEDIAN(turma.num_matricula)', 'median')
.field('STDDEV_POP(turma.num_matricula)', 'stddev')
.field('QUANTILE(turma.num_matricula, 0.25)', 'first_qt')
.field('QUANTILE(turma.num_matricula, 0.75)', 'third_qt')
.from('turma')
.group('turma.ano_censo')
.order('turma.ano_censo')
.where('turma.tipo_turma_id = 0 AND turma.dependencia_adm_id <= 3 AND ((turma.etapa_resumida >= 1 AND turma.etapa_resumida <= 7) OR turma.etapa_resumida = 99)');
}
next();
}, rqf.build(), query, addMissing(rqf), id2str.transform(), (req, res, next) => {
// Se possui apenas uma dimensão
if(req.partial.length > 0) {
const yearClassCount = req.result;
req.result = req.partial;
// Adiciona os totais por anos ao fim da consulta
// Como esse tipo de total é específico desse indicador, um label foi adicionado para indicar
yearClassCount.forEach((result) => {
let obj = {};
obj = result;
obj.label = "total_year_average";
req.result.push(obj);
})
}
// Caso tenha mais de uma dimensão, retorna a consulta só pelas dimensões, sem linha de total (req.result)
next();
}, response('class_count'));
module.exports = classCountApp; module.exports = classCountApp;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment