From b300af3eaf0719652ceec4f9fea6b82dead30e3f Mon Sep 17 00:00:00 2001 From: Vytor Calixto <vytorcalixto@gmail.com> Date: Tue, 18 Sep 2018 10:54:56 -0300 Subject: [PATCH] Add school_years to kindergarden education level Related: simcaq/SCRUM#408 --- src/libs/routes/classroomCount.js | 63 +++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/src/libs/routes/classroomCount.js b/src/libs/routes/classroomCount.js index bdec29e5..fe153ef3 100644 --- a/src/libs/routes/classroomCount.js +++ b/src/libs/routes/classroomCount.js @@ -286,6 +286,7 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { let enrollmentMatch = true; j = 0; let educationLevelSet = new Set(); + let schoolYearSet = new Set(); let enrollment = enrollments[j]; while(enrollmentMatch && j < enrollments.length) { @@ -346,7 +347,11 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { total_classrooms_needed: 0 } }; - + + if(enrollmentEducationLevel.id == 1) { + educationLevel.classes_school_year = []; + } + // Para manter a ordem da etapa de ensino if (location.education_level.length == 0) { location.education_level.push(educationLevel); @@ -375,6 +380,38 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { educationLevel = location.education_level[k]; } + // Adiciona as séries da creche + let currentSchoolYear = null; + if(enrollmentEducationLevel.id == 1){ + let schoolYearHash = '' + enrollment.year + enrollment.city_id + enrollment.location_id + enrollment.school_year_id; + if(schoolYearSet.has(schoolYearHash)) { // Busca a série escolar + let k = 0; + let el = educationLevel.classes_school_year[k]; + while(k < educationLevel.classes_school_year.length) { + if(el.school_year_id != enrollment.school_year_id) { + ++k; + if(k < educationLevel.classes_school_year.length) el = educationLevel.classes_school_year[k]; + } else break; + } + if(k >= educationLevel.classes_school_year.length) --k; + currentSchoolYear = educationLevel.classes_school_year[k]; + } else { // Adiciona uma nova série escolar + let school_year = { + school_year_id: enrollment.school_year_id, + school_year_name: enrollment.school_year_name, + total_enrollment_day: 0, + total_enrollment_night: 0, + full_period_classes: 0, + day_classes: 0, + night_classes: 0, + total_classrooms_needed: 0 + } + schoolYearSet.add(schoolYearHash); + educationLevel.classes_school_year.push(school_year); + currentSchoolYear = school_year; + } + } + // Soma os totais de matrÃcula da etapa de ensino educationLevel.enrollment.total_enrollment_day += (enrollment.period_id < 3 && enrollment.period_id != null) ? enrollment.total : 0; educationLevel.enrollment.total_enrollment_night += (enrollment.period_id == 3) ? enrollment.total : 0; @@ -383,8 +420,7 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { // Turmas de perÃodo integral educationLevel.enrollment.full_period_classes = Math.ceil((educationLevel.enrollment.total_enrollment_day * (enrollmentEducationLevel.offerGoal/100)) / enrollmentEducationLevel.numberStudentClass); - // Turmas diurnas - // MatrÃculas diurnas - matrÃculas integrais + // Turmas diurnas (matrÃculas diurnas - matrÃculas integrais) educationLevel.enrollment.day_classes = Math.ceil((educationLevel.enrollment.total_enrollment_day * (1 - enrollmentEducationLevel.offerGoal/100)) / enrollmentEducationLevel.numberStudentClass); // Turmas noturnas @@ -397,6 +433,27 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { educationLevel.enrollment.total_classrooms_needed = Math.ceil(educationLevel.enrollment.total_classrooms_needed); + // Faz os mesmos cálculos para a série escolar + if(currentSchoolYear) { + // Totais de matrÃcula + currentSchoolYear.total_enrollment_day += (enrollment.period_id < 3 && enrollment.period_id != null) ? enrollment.total : 0; + currentSchoolYear.total_enrollment_night += (enrollment.period_id == 3) ? enrollment.total : 0; + + // Número de turmas parcial + currentSchoolYear.full_period_classes = Math.ceil((currentSchoolYear.total_enrollment_day * (enrollmentEducationLevel.offerGoal/100)) / enrollmentEducationLevel.numberStudentClass); + + currentSchoolYear.day_classes = Math.ceil((currentSchoolYear.total_enrollment_day * (1 - enrollmentEducationLevel.offerGoal/100)) / enrollmentEducationLevel.numberStudentClass); + + currentSchoolYear.night_classes = Math.ceil((currentSchoolYear.total_enrollment_night / enrollmentEducationLevel.numberStudentClass)); + + // Total de salas + currentSchoolYear.total_classrooms_needed = (currentSchoolYear.full_period_classes + currentSchoolYear.day_classes/2); + + if(currentSchoolYear.night_classes > (currentSchoolYear.day_classes/2)) currentSchoolYear.total_classrooms_needed += (currentSchoolYear.night_classes - (currentSchoolYear.day_classes/2)); + + currentSchoolYear.total_classrooms_needed = Math.ceil(currentSchoolYear.total_classrooms_needed); + } + enrollment = enrollments[j]; } -- GitLab