Skip to content
Snippets Groups Projects
Commit 4977005a authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Merge branch 'issue/423' into development

parents e1bfd6c9 e3742a20
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -668,6 +668,132 @@ enrollmentApp.get('/diagnosis', rqf.parse(), (req, res, next) => {
req.result = result;
next();
}, response('enrollment_diagnosis') );
}, response('enrollment_diagnosis'));
enrollmentApp.get('/projection', rqf.parse(), (req, res, next) => {
req.dims = {};
req.dims.location = true;
req.dims.school_year = true;
req.dims.adm_dependency = true;
req.dims.period = true;
req.filter.adm_dependency = [1,2,3];
req.sql.field('COUNT(*)', 'total')
.field("'Brasil'", 'name')
.field('matricula.ano_censo', 'year')
.from('matricula')
.group('matricula.ano_censo')
.order('matricula.ano_censo')
.where('matricula.tipo<=3');
next();
}, rqf.build(), query, id2str.transform(), (req, res, next) => {
let enrollments = req.result;
// Gera a relação etapa de ensino X ano escolar
let educationSchoolYear = {};
for(let i = 10; i < 80; ++i) {
if(id2str.schoolYear(i) !== id2str.schoolYear(99)) {
let educationLevelId = Math.floor(i/10);
educationSchoolYear[i] = {
id: educationLevelId,
name: id2str.educationLevelShort(educationLevelId),
};
}
}
let result = [];
let educationLevelSet = new Set();
let schoolYearSet = new Set();
let i = 0;
while(i < enrollments.length) {
let enrollment = enrollments[i];
let educationLevelHash = '' + enrollment.year + educationSchoolYear[enrollment.school_year_id].id;
let schoolYearHash = '' + enrollment.year + enrollment.school_year_id;
let currentEducation = null;
// Busca ou cria a etada de ensino adequada
if(educationLevelSet.has(educationLevelHash)) {
let j = 0;
let edu = result[j];
while(j < result.length && (edu.year != enrollment.year || edu.education_level_school_year_id != educationSchoolYear[enrollment.school_year_id].id)) {
++j;
edu = result[j];
}
if((j >= result.length)) --j;
edu = result[j];
currentEducation = edu;
} else {
educationLevelSet.add(educationLevelHash);
let obj = {
year: enrollment.year,
name: enrollment.name,
education_level_school_year_id: educationSchoolYear[enrollment.school_year_id].id,
education_level_school_year_name: educationSchoolYear[enrollment.school_year_id].name,
urban_day_total: 0,
urban_night_total: 0,
rural_day_total: 0,
rural_night_total: 0
};
result.push(obj);
currentEducation = obj;
}
let currentSchoolYear = null;
// Busca ou cria a série adequada
if(schoolYearSet.has(schoolYearHash)) {
let j = 0;
let edu = result[j];
while(j < result.length && (edu.year != enrollment.year || edu.education_level_school_year_id != enrollment.school_year_id)){
++j;
edu = result[j];
}
if(j >= result.length) --j;
edu = result[j];
currentSchoolYear = edu;
} else {
schoolYearSet.add(schoolYearHash);
let obj = {
year: enrollment.year,
name: enrollment.name,
education_level_school_year_id: enrollment.school_year_id,
education_level_school_year_name: enrollment.school_year_name,
urban_day_total: 0,
urban_night_total: 0,
rural_day_total: 0,
rural_night_total: 0
};
result.push(obj);
currentSchoolYear = obj;
}
if(enrollment.location_id == 1) {
if(enrollment.period_id < 3) {
currentEducation.urban_day_total += enrollment.total;
currentSchoolYear.urban_day_total += enrollment.total;
} else {
currentEducation.urban_night_total += enrollment.total;
currentSchoolYear.urban_night_total += enrollment.total;
}
} else {
if(enrollment.period_id < 3) {
currentEducation.rural_day_total += enrollment.total;
currentSchoolYear.rural_day_total += enrollment.total;
} else {
currentEducation.rural_night_total += enrollment.total;
currentSchoolYear.rural_night_total += enrollment.total;
}
}
++i;
}
req.result = result;
next();
}, response('enrollment_projection'));
module.exports = enrollmentApp;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment