diff --git a/src/libs/middlewares/aggregateData.js b/src/libs/middlewares/aggregateData.js index 41c32836d5f1eef6fbfe1a8903da53a0442daa54..f0378d0bc7829241ca435b905809d342686af3e5 100644 --- a/src/libs/middlewares/aggregateData.js +++ b/src/libs/middlewares/aggregateData.js @@ -5,12 +5,13 @@ const convert = { "age_range": "ageRangeAggregate", "gender": "gender", "ethnic_group": "ethnicGroup", - "education_level_mod_agg": "educationLevelModAgg" + "education_level_mod_agg": "educationLevelModAgg", + 'integral_time_agg': 'integralTime' } function aggregateData(req, res, next) { const newResult = [] - const aggregateFields = ['gender', 'age_range', 'ethnic_group', 'education_level_mod_agg'] + const aggregateFields = ['gender', 'age_range', 'ethnic_group', 'education_level_mod_agg', 'integral_time_agg'] let id; const fields = req.query.dims.split(','); let currentAggregateField; @@ -19,7 +20,7 @@ function aggregateData(req, res, next) { if (currentAggregateField) { console.log(currentAggregateField); req.result.forEach((r) => { - id = currentAggregateField === 'ethnic_group' ? 0 : 1; + id = ['ethnic_group', 'integral_time_agg'].includes(currentAggregateField) ? 0 : 1; for (const property in r) { if (property.includes("total_")) { let data = { diff --git a/src/libs/routes_v1/enrollmentAggregate.js b/src/libs/routes_v1/enrollmentAggregate.js index 95de1c2512a4de0fbc29a8c687cd7542c219f56c..c12329cdbfd71eb68428f4cefe2bfaa901d998ed 100644 --- a/src/libs/routes_v1/enrollmentAggregate.js +++ b/src/libs/routes_v1/enrollmentAggregate.js @@ -355,6 +355,17 @@ enrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .group('escola.ano_censo') .order('escola.ano_censo'); } + else if (req.query.dims && req.query.dims.includes('integral_time_agg')) { + + req.sql.from('turma,escola') + .field('SUM(CASE WHEN turma.tempo_integral=0 then turma.num_matricula ELSE 0 END)', 'total_int_nao') + .field('SUM(CASE WHEN turma.tempo_integral=1 then turma.num_matricula ELSE 0 END)', 'total_int') + .field('SUM(CASE WHEN turma.tempo_integral=2 then turma.num_matricula ELSE 0 END)', 'total_int_nao_aplica') + .field('escola.ano_censo', 'year') + .group('escola.ano_censo') + .order('escola.ano_censo') + .where('turma.tipo_atendimento_id <= 2 and turma.escola_id = escola.id and turma.ano_censo = escola.ano_censo'); + } else { req.sql.from('escola') .field('SUM(escola.qt_mat_bas)', 'total')