Commit dd43f642 authored by Pietro Cavassin's avatar Pietro Cavassin
Browse files

Merge branch 'classroom_count_hotfix' into 'homologa'

fix problem with missing teacher

See merge request !315
parents 83fd9e4f 5d53044c
......@@ -43,6 +43,8 @@ const cache = require('apicache').options({ debug: config.debug, statusCodes: {i
let rqf = new ReqQueryFields();
const fs = require('fs')
rqf.addField({
name: 'filter',
field: false,
......@@ -285,20 +287,20 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
next();
}, rqf.build(), query, id2str.transform(), (req, res, next) => {
req.enrollment = req.result;
// Gera a relação etapa de ensino X ano escolar
req.educationSchoolYear = {};
for(let i = 1; i < 15; ++i) {
if(id2str.educationLevelSchoolYear(i) !== id2str.educationLevelSchoolYear(99)) {
let educationLevelId = (i > 10) ? Math.floor(i/10) : i;
let classSize = req.classSize.find((el) => {return el.id === educationLevelId || el.id === i});
let integralTime = req.integralTime.find((el) => {return el.id === educationLevelId});
let numberStudentClass = (typeof classSize !== 'undefined') ? classSize.numberStudentClass : null;
// Usa o offerGoal que é passado como parâmetro (Brasil inteiro). Atenção para isso.
let integralTimeOfferGoal = (typeof integralTime !== 'undefined') ? integralTime.offerGoal : null;
let teacherByClass = (typeof classSize !== 'undefined') ? classSize.teacherByClass : null;
req.educationSchoolYear[i] = {
......@@ -310,6 +312,7 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
};
}
}
delete req.dims;
delete req.filter;
req.resetSql();
......@@ -334,13 +337,14 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
next();
}, rqf.build(), query, id2str.transform(), (req, res, next) => {
req.classroom = req.result;
delete req.dims;
delete req.filter;
req.resetSql();
next();
}, rqf.parse(), (req, res, next) => {
if (req.body.teacher_journey !== undefined) {
req.teacherJourney = JSON.parse(req.body.teacher_journey) || null;
// req.teacherJourney = JSON.parse(req.body.teacher_journey) || null;
let schoolDays = JSON.parse(req.body.school_days) || null;
let teacherFormation = JSON.parse(req.body.teacher_formation) || null;
......@@ -364,6 +368,7 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
schoolYear.shifts = shifts
teachingHoursParsed.push(schoolYear)
}
req.schoolDays = schoolDaysParsed;
req.teachingHours = teachingHoursParsed;
......@@ -372,7 +377,7 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
teacherFormationParsed.push(teacherFormation.find((el) => {return el.idFormationLevel === i}))
}
req.teacherFormation = teacherFormationParsed;
req.teacherCalc = true;
}
......@@ -389,6 +394,7 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
next();
}, rqf.build(), query, id2str.transform(), (req, res, next) => {
req.teacher = req.result;
delete req.dims;
delete req.filter;
req.resetSql();
......@@ -552,8 +558,18 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
currentClassroomObj = obj;
var id_attribute = req.dims.school ? "school_id" : "city_id"
while (req.teacher[ti][id_attribute] !== classroom[id_attribute]) { // match da tabela de professores.
var old_ti = ti;
while (ti < req.teacher.length && req.teacher[ti][id_attribute] !== classroom[id_attribute]) // match da tabela de professores.
ti++;
if (ti === req.teacher.length) {
console.log(classroom[id_attribute], "not found")
while (classroom[id_attribute] === enrollments[j][id_attribute])
enrollments.splice(j, 1)
ti = old_ti;
i++;
continue;
}
} else { // Se a hash já existe, já temos a cidade nos resultados. Como está ordenado, é o último valor nos resultados
......@@ -1077,53 +1093,6 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
total_teacher_full_period : numberOfTeacherFullPeriod,
total_teacher_partial : numberOfTeacherNight + numberOfTeacherDay
}
// schoolYear.teacherNumber.careerLevels = [];
// req.teacherFormation.forEach((formation, i) => {
// let totalTeacherFullPeriodCareer = Math.ceil(schoolYear.teacherNumber.total_teacher_full_period * teacherByFormation[i]);
// let totalTeacherPartialCareer = Math.ceil(schoolYear.teacherNumber.total_teacher_partial * teacherByFormation[i]);
// schoolYear.teacherNumber.careerLevels.push({
// sequence: formation.sequence,
// denomination: formation.denomination,
// formation_level_id: formation.idFormationLevel,
// total_teacher_career: totalTeacherFullPeriodCareer + totalTeacherPartialCareer,
// total_teacher_full_period_career: totalTeacherFullPeriodCareer,
// 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
......@@ -1193,37 +1162,6 @@ 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 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;
}
})
})
......@@ -1233,3 +1171,4 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
}, response('classroom_count'));
module.exports = classroomCountApp;
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