Commit cc48b973 authored by jvfpw18's avatar jvfpw18

Make sure careerLevels sum is equals to etapa sum

parent d99543c4
Pipeline #22172 failed with stage
in 60 minutes
......@@ -954,6 +954,8 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
}
}
// console.log(teacherByFormation);
lastLocations.forEach((location) => {
location.education_level.forEach((educationLevel) => {
let educationLevelId = educationLevel.education_level_short_id;
......@@ -994,6 +996,38 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
total_teacher_partial_career: totalTeacherPartialCareer,
})
})
// Garantimos que a soma das porcentagens deu 100% usando reduce, geralmente não ocorre devido à função teto.
function reducer(key) { return (sum, elem) => sum + elem[key]};
let teacherDiffFullPeriod = schoolYear.teacherNumber.careerLevels.reduce(reducer('total_teacher_full_period_career'), 0) - schoolYear.teacherNumber.total_teacher_full_period;
let teacherDiffPartial = schoolYear.teacherNumber.careerLevels.reduce(reducer('total_teacher_partial_career'), 0) - schoolYear.teacherNumber.total_teacher_partial;
// Remove primeiro do ensino superior, caso não tenha suficiente remove do nível médio.
schoolYear.teacherNumber.careerLevels[1].total_teacher_full_period_career -= teacherDiffFullPeriod;
if (schoolYear.teacherNumber.careerLevels[1].total_teacher_full_period_career < 0) {
teacherDiffFullPeriod = (-1)*schoolYear.teacherNumber.careerLevels[1].total_teacher_full_period_career;
schoolYear.teacherNumber.careerLevels[1].total_teacher_full_period_career = 0;
schoolYear.teacherNumber.careerLevels[0].total_teacher_full_period_career -= teacherDiffFullPeriod;
if (schoolYear.teacherNumber.careerLevels[0].total_teacher_full_period_career < 0)
schoolYear.teacherNumber.careerLevels[0].total_teacher_full_period_career = 0;
}
// Repete calculos para parcial
schoolYear.teacherNumber.careerLevels[1].total_teacher_partial_career -= teacherDiffPartial;
if (schoolYear.teacherNumber.careerLevels[1].total_teacher_partial_career < 0) {
teacherDiffPartial = (-1)*schoolYear.teacherNumber.careerLevels[1].total_teacher_partial_career;
schoolYear.teacherNumber.careerLevels[1].total_teacher_partial_career = 0;
schoolYear.teacherNumber.careerLevels[0].total_teacher_partial_career -= teacherDiffPartial;
if (schoolYear.teacherNumber.careerLevels[0].total_teacher_partial < 0)
schoolYear.teacherNumber.careerLevels[0].total_teacher_partial_career = 0;
}
// Atualiza os totais das carreiras
schoolYear.teacherNumber.careerLevels[1].total_teacher_career = schoolYear.teacherNumber.careerLevels[1].total_teacher_full_period_career + schoolYear.teacherNumber.careerLevels[1].total_teacher_partial_career;
schoolYear.teacherNumber.careerLevels[0].total_teacher_career = schoolYear.teacherNumber.careerLevels[0].total_teacher_full_period_career + schoolYear.teacherNumber.careerLevels[0].total_teacher_partial_career;
})
// Calculamos para o educationLevel usando reduce
......@@ -1051,21 +1085,36 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
})
// // Garantimos que a soma das porcentagens deu 100% usando reduce, geralmente não ocorre devido à função teto.
// function reducer(key) { return (sum, elem) => sum + elem[key]};
// let teacherDiff = educationLevel.teacherNumber.careerLevels.reduce(reducer('total_teacher_career')) - educationLevel.teacherNumber.total_teacher;
// if (teacherDiff > 0) {
// if (educationLevel.teacherNumber.careerLevels[1] > teacherDiff) {
// educationLevel.teacherNumber.careerLevels[1].total_teacher_career -= teacherDiff;
// educationLevel.teacherNumber.careerLevels[1].total_teacher_full_period_career -= teacherDiff;
// }
// else {
// educationLevel.teacherNumber.careerLevels[0].total_teacher_career -= teacherDiff;
// educationLevel.teacherNumber.careerLevels[0].total_teacher_full_period_career -= teacherDiff;
// }
// }
// Garantimos que a soma das porcentagens deu 100% usando reduce, geralmente não ocorre devido à função teto.
function reducer(key) {return (sum, elem) => sum + elem[key]};
let teacherDiffFullPeriod = educationLevel.teacherNumber.careerLevels.reduce(reducer('total_teacher_full_period_career'), 0) - educationLevel.teacherNumber.total_teacher_full_period;
let teacherDiffPartial = educationLevel.teacherNumber.careerLevels.reduce(reducer('total_teacher_partial_career'), 0) - educationLevel.teacherNumber.total_teacher_partial;
// Remove primeiro do ensino superior, caso não tenha suficiente remove do nível médio.
educationLevel.teacherNumber.careerLevels[1].total_teacher_full_period_career -= teacherDiffFullPeriod;
if (educationLevel.teacherNumber.careerLevels[1].total_teacher_full_period_career < 0) {
teacherDiffFullPeriod = (-1)*educationLevel.teacherNumber.careerLevels[1].total_teacher_full_period_career;
educationLevel.teacherNumber.careerLevels[1].total_teacher_full_period_career = 0;
educationLevel.teacherNumber.careerLevels[0].total_teacher_full_period_career -= teacherDiffFullPeriod;
if (educationLevel.teacherNumber.careerLevels[0].total_teacher_full_period_career < 0)
educationLevel.teacherNumber.careerLevels[0].total_teacher_full_period_career = 0;
}
// Repete calculos para parcial
educationLevel.teacherNumber.careerLevels[1].total_teacher_partial_career -= teacherDiffPartial;
if (educationLevel.teacherNumber.careerLevels[1].total_teacher_partial_career < 0) {
teacherDiffPartial = (-1)*educationLevel.teacherNumber.careerLevels[1].total_teacher_partial_career;
educationLevel.teacherNumber.careerLevels[1].total_teacher_partial_career = 0;
educationLevel.teacherNumber.careerLevels[0].total_teacher_partial_career -= teacherDiffPartial;
if (educationLevel.teacherNumber.careerLevels[0].total_teacher_partial < 0)
educationLevel.teacherNumber.careerLevels[0].total_teacher_partial_career = 0;
}
// Atualiza os totais das carreiras
educationLevel.teacherNumber.careerLevels[1].total_teacher_career = educationLevel.teacherNumber.careerLevels[1].total_teacher_full_period_career + educationLevel.teacherNumber.careerLevels[1].total_teacher_partial_career;
educationLevel.teacherNumber.careerLevels[0].total_teacher_career = educationLevel.teacherNumber.careerLevels[0].total_teacher_full_period_career + educationLevel.teacherNumber.careerLevels[0].total_teacher_partial_career;
}
})
})
......
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