Commit 54135f44 authored by Pietro Cavassin's avatar Pietro Cavassin
Browse files

diagnosis by city instead of country

parent 73327842
Pipeline #26063 failed with stage
in 2 minutes and 44 seconds
......@@ -218,7 +218,27 @@ rqf.addField({
type: 'integer',
field: 'dependencia_adm_id'
}
}, 'filter');
}, 'filter') .addValue({
name: 'integral_time',
table: 'matricula',
tableField: 'tempo_integral',
resultField: 'integral_time_id',
where: {
relation: '=',
type: 'integer',
field: 'tempo_integral'
}
}).addValue({
name: 'education_level_short',
table: 'matricula',
tableField: 'etapa_resumida',
resultField: 'education_level_short_id',
where: {
relation: '=',
type: 'integer',
field: 'etapa_resumida'
}
});
classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
let classSize = JSON.parse(req.body.class_size) || null;
......@@ -394,6 +414,75 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
delete req.filter;
req.resetSql();
next();
}, rqf.parse(), (req, res, next) => {
req.dims.state = true;
req.dims.city = true;
req.dims.education_level_short = true;
req.dims.integral_time = true;
req.sql.field('COUNT(*)', 'total')
.field('matricula.ano_censo', 'year')
.from('matricula')
.group('matricula.ano_censo')
.order('matricula.ano_censo')
.where('((matricula.tipo<=3 OR matricula.tipo IS NULL) AND (matricula.tipo_atendimento_turma IS NULL OR matricula.tipo_atendimento_turma <= 2))');
next();
}, rqf.build(), query, id2str.transform(), (req, res, next) => {
var integral_time_result = req.result
req.integral_time = {}
for (let i = 0; i < integral_time_result.length; ++i){
// Se cidade não foi criada, cria
let integral_time = integral_time_result[i];
let cityHash = '' + integral_time.year + integral_time.city_id
//let currentCity = null;
let currentCity = req.integral_time[cityHash]
// Cria cidade caso não exista
if (currentCity === undefined){
let obj = {
year: integral_time.year,
city_id: integral_time.city_id,
city_name: integral_time.city_name,
integral_time: {}
}
req.integral_time[cityHash] = obj
currentCity = obj;
}
// Pega objeto com dados do nível atual
let level = integral_time.education_level_short_id
let levelObj = currentCity.integral_time[level]
if (levelObj === undefined){
levelObj = {
id: level,
integralTime: 0,
total: 0,
}
}
// Soma no total em integralTime, caso seja 1
levelObj.total += integral_time.total
if (integral_time.integral_time_id === 1){
levelObj.integralTime += integral_time.total
}
currentCity.integral_time[level] = levelObj
}
for (let i in req.integral_time){
let city = req.integral_time[i]
// Adiciona diagnóstico aos objetos
for (let key in city.integral_time){
let cur = city.integral_time[key]
cur["diagnosis"] = cur.total ? (cur.integralTime/cur.total)*100.0 : 0;
city.integral_time[key] = cur
}
}
delete req.dims;
delete req.filter;
req.resetSql();
next()
}, rqf.parse(), rqf.build(), (req, res, next) => {
// req.classroom = req.result;
// req.idm = req.result;
......@@ -431,6 +520,7 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
let ti = 0; // index for teacher table
// estado, cidade, local, prédio
while (i < req.classroom.length) {
let classroom = req.classroom[i];
// Cria hash única para cada espacialidade, dado um ano
......@@ -549,7 +639,7 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
educationLevel.classes_school_year = [];
}
// Para manter a ordem da etapa de ensino
// Para manter a ordem da etapa de ensino (insertion sort)
if (location.education_level.length == 0) {
location.education_level.push(educationLevel);
} else {
......@@ -630,8 +720,17 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
}
let enrollmentIdm = req.idm[ei];
let cur_year = enrollment.year
let cur_city = enrollment.city_id
let hash = '' + cur_year + cur_city
let cur_education_level_short = educationLevel.education_level_short_id
let cur_diagnosis = 0
if (req.integral_time[hash].integral_time[cur_education_level_short]){
cur_diagnosis = req.integral_time[hash].integral_time[cur_education_level_short].diagnosis
}
let currentIntegralOfferGoal = enrollmentEducationLevel.integralTimeOfferGoal;
let currentIntegralOfferGoal = Math.max(enrollmentEducationLevel.integralTimeOfferGoal, cur_diagnosis);
let currentNumberStudentClass = (enrollment.location_id == 1) ? enrollmentEducationLevel.numberStudentClass.urban : enrollmentEducationLevel.numberStudentClass.country;
// Soma os totais de matrícula da etapa de ensino
......
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