Commit b5d902fe authored by Vytor Calixto's avatar Vytor Calixto 👾

First prototype of classroom count route

parent b6916c1e
Pipeline #15012 failed with stage
in 7 minutes and 27 seconds
...@@ -202,13 +202,14 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { ...@@ -202,13 +202,14 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
.group('escola.ano_censo') .group('escola.ano_censo')
.order('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');
next(); next();
}, rqf.build(), query, id2str.transform(), (req, res, next) => { }, rqf.build(), query, id2str.transform(), (req, res, next) => {
let classSize = JSON.parse(req.body.class_size) || null; let classSize = JSON.parse(req.body.class_size) || null;
let integralTime = JSON.parse(req.body.integral_time) || null; let integralTime = JSON.parse(req.body.integral_time) || null;
console.log(classSize, integralTime); // console.log(classSize, integralTime);
req.classroom = req.result; req.classroom = req.result;
let classroom = []; let classroom = [];
...@@ -240,29 +241,86 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { ...@@ -240,29 +241,86 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
}); });
let result = []; let result = [];
// Para cada resultado
classroom.forEach((c) => { classroom.forEach((c) => {
function filterUrbanEnrollment(e) {
return (e.city_id == c.city_id && e.year == c.year && e.location_id == 1);
}
function filterRuralEnrollment(e) {
return (e.city_id == c.city_id && e.year == c.year && e.location_id == 2);
}
let urbanEnrollments = req.enrollment.filter(filterUrbanEnrollment);
let ruralEnrollments = req.enrollment.filter(filterRuralEnrollment);
let r = c; let r = c;
// r.locations[0].enrollments = urbanEnrollments; // Para cada localização
// r.locations[1].enrollments = ruralEnrollments; c.locations.forEach((location, index) => {
function filterEnrollment(e) {
return (e.city_id == c.city_id && e.year == c.year && e.location_id == location.location_id);
}
let fEnrollments = req.enrollment.filter(filterEnrollment);
let educationLevels = [];
fEnrollments.forEach((fe) => {
let obj = {education_level_short_id: fe.education_level_short_id, education_level_short_name: fe.education_level_short_name};
if(educationLevels.findIndex((el) => {return el.education_level_short_id === obj.education_level_short_id}) === -1 ) {
educationLevels.push(obj);
}
});
let education_level = [];
// Para cada etapa de ensino
educationLevels.forEach((eduLevel) => {
function filterEducationLevel(e) {
return (e.city_id == c.city_id && e.year == c.year && e.location_id == location.location_id && e.education_level_short_id == eduLevel.education_level_short_id);
}
let fEducationLevel = fEnrollments.filter(filterEducationLevel);
let dayEnrollments = 0;
let nightEnrollments = 0;
// Para cada matrícula na etapa de ensino
fEducationLevel.forEach((fEduLevel) => {
if(fEduLevel.period_id < 3) dayEnrollments+= fEduLevel.total;
else if(fEduLevel.period_id === 3) nightEnrollments+= fEduLevel.total;
});
let size = classSize.find((el) => {
return el.id === eduLevel.education_level_short_id;
});
let fullPeriodTime = integralTime.find((el) => {
return el.id === eduLevel.education_level_short_id;
});
if(typeof size === 'undefined' || typeof fullPeriodTime === 'undefined') return;
size = size.numberStudentClass;
fullPeriodTime = fullPeriodTime.offerGoal;
let fullPeriodClasses = Math.ceil((dayEnrollments * (fullPeriodTime / 100))/size);
let dayClasses = Math.ceil((dayEnrollments/size) - fullPeriodClasses);
let nightClasses = Math.ceil(nightEnrollments/size);
let totalClassroomsNeeded = fullPeriodClasses + dayClasses;
if(nightClasses > dayClasses) totalClassroomsNeeded+= (nightClasses - dayClasses);
let obj = {
total_enrollment_day : dayEnrollments,
total_enrollment_night: nightEnrollments,
full_period_classes: fullPeriodClasses,
day_classes: dayClasses,
night_classes: nightClasses,
total_classrooms_needed: totalClassroomsNeeded
};
let educationLevelIndex = education_level.findIndex((el) => {return el.education_level_short_id === eduLevel.education_level_short_id});
if(educationLevelIndex === -1) {
educationLevelIndex = education_level.length;
education_level.push(eduLevel);
}
education_level[educationLevelIndex].enrollment = obj;
// education_level[educationLevelIndex].enrollments = fEducationLevel;
});
r.locations[index].education_level = education_level;
});
result.push(r); result.push(r);
}); });
console.log('FEITO'); // console.log('FEITO');
// console.log('SALAS');
// console.log(classroom[0]);
// console.log('FILTRO');
// console.log(classEnrollments);
req.result = result; req.result = result;
next(); next();
}, response('classroom_count')); }, response('classroom_count'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment