diff --git a/CHANGELOG.md b/CHANGELOG.md index ed4b3d282566a3b24cc9a5e35f65c9797a537fa7..0a6a11a238ee0f5c1285a605df7b83f14d502ab1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ 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.2.2 - 2018-05-22 +### Changed +- Fixed bug with missing education levels in classroom count + ## 1.2.1 - 2018-05-22 ### Changed - Add state id in infrastructure diff --git a/src/libs/routes/classroomCount.js b/src/libs/routes/classroomCount.js index b7c2aacda27984638fbcb1baae88d570aa5d357b..65fbceedfcb1e8ce21060b249f20851873dce367 100644 --- a/src/libs/routes/classroomCount.js +++ b/src/libs/routes/classroomCount.js @@ -184,7 +184,8 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { .from('matricula') .group('matricula.ano_censo') .order('matricula.ano_censo') - .where('matricula.tipo<=3'); + .where('matricula.tipo<=3') + .where('matricula.dependencia_adm_id < 4'); next(); }, rqf.build(), query, id2str.transform(), (req, res, next) => { @@ -225,7 +226,8 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { .from('escola') .group('escola.ano_censo') .order('escola.ano_censo') - .where('escola.situacao_de_funcionamento = 1 AND escola.local_func_predio_escolar = 1'); + .where('escola.situacao_de_funcionamento = 1 AND escola.local_func_predio_escolar = 1') + .where('escola.dependencia_adm_id < 4'); next(); }, rqf.build(), query, id2str.transform(), (req, res, next) => { @@ -243,6 +245,7 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { let j = 0; let result = []; let hashSet = new Set(); + let enrollments = [...req.enrollment]; while (i < req.classroom.length) { let classroom = req.classroom[i]; // Cria hash única para cada espacialidade, dado um ano @@ -282,14 +285,15 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { let enrollmentMatch = true; j = 0; let educationLevelSet = new Set(); - while(enrollmentMatch && j < req.enrollment.length) { - let enrollment = req.enrollment[j]; + let enrollment = enrollments[j]; + while(enrollmentMatch && j < enrollments.length) { + enrollment = enrollments[j]; if(typeof enrollment === 'undefined') { - enrollmentMatch = false; + ++j; continue; } if(enrollment.city_id != classroom.city_id) { // Se as cidades não são iguais, já passamos do range - enrollmentMatch = false; + ++j; continue; } @@ -300,13 +304,13 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { // Remove se o perÃodo é nulo (não dá pra usar no cálculo) if(enrollment.period_id == null) { - req.enrollment.splice(j, 1); + enrollments.splice(j, 1); continue; } // Temos uma matrÃcula com cidade, ano e localidades certos // "Consome" a matrÃcula (remove do vetor de matrÃculas) - req.enrollment.splice(j, 1); + enrollments.splice(j, 1); // Cria a etapa de ensino adequada let enrollmentEducationLevel = req.educationSchoolYear[enrollment.school_year_id]; @@ -377,6 +381,7 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { if(educationLevel.enrollment.night_classes > educationLevel.enrollment.day_classes) educationLevel.enrollment.total_classrooms_needed += (educationLevel.enrollment.night_classes - educationLevel.enrollment.day_classes); + enrollment = enrollments[j]; } // Calculamos o total classroom be built para o municÃpio usando reduce @@ -487,7 +492,7 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { } } - req.result = reduction || result; + req.result = /*{result, enrollments} //*/ reduction || result; next(); }, response('classroom_count'));