Skip to content
Snippets Groups Projects
Commit 6e2135b8 authored by jvfpw18's avatar jvfpw18
Browse files

v1.11.7

parent d3d0da9d
No related branches found
No related tags found
1 merge request!224v1.11.7
Pipeline #20849 failed
...@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. ...@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/). and this project adheres to [Semantic Versioning](http://semver.org/).
## 1.11.7 - 2019-07-12
## Changed
- EnrollmentProjection now returns empty values with 0
## 1.11.6 - 2019-07-11 ## 1.11.6 - 2019-07-11
## Changed ## Changed
- Return haveSportsCourtCoverage and haveCourtyardCoverage = [] in route school_infrastructure - Return haveSportsCourtCoverage and haveCourtyardCoverage = [] in route school_infrastructure
......
...@@ -36,8 +36,12 @@ const id2str = require(`${libs}/middlewares/id2str`); ...@@ -36,8 +36,12 @@ const id2str = require(`${libs}/middlewares/id2str`);
const config = require(`${libs}/config`); const config = require(`${libs}/config`);
const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware;
let rqf = new ReqQueryFields(); let rqf = new ReqQueryFields();
enrollmentProjectionApp.use(cache('15 day'));
rqf.addField({ rqf.addField({
name: 'filter', name: 'filter',
field: false, field: false,
...@@ -130,29 +134,99 @@ rqf.addField({ ...@@ -130,29 +134,99 @@ rqf.addField({
enrollmentProjectionApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { enrollmentProjectionApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
req.sql.field("'Brasil'", 'name') req.sql.field("'Brasil'", 'name')
.field('SUM(projecao_matricula.urbano_dia_total)', 'urban_day_total') .field('SUM(projecao_matricula.urbano_dia_total)', 'urban_day_total')
.field('SUM(projecao_matricula.urbano_noite_total)', 'urban_night_total') .field('SUM(projecao_matricula.urbano_noite_total)', 'urban_night_total')
.field('SUM(projecao_matricula.rural_dia_total)', 'rural_day_total') .field('SUM(projecao_matricula.rural_dia_total)', 'rural_day_total')
.field('SUM(projecao_matricula.rural_noite_total)', 'rural_night_total') .field('SUM(projecao_matricula.rural_noite_total)', 'rural_night_total')
.field('projecao_matricula.etapa_ensino_escola_ano_id', 'education_level_school_year_id') .field('projecao_matricula.etapa_ensino_escola_ano_id', 'education_level_school_year_id')
.field('projecao_matricula.ano_censo', 'year') .field('projecao_matricula.ano_censo', 'year')
.from('projecao_matricula') .from('projecao_matricula')
.where('projecao_matricula.etapa_ensino_escola_ano_id <> 7 AND projecao_matricula.etapa_ensino_escola_ano_id < 71') .where('projecao_matricula.etapa_ensino_escola_ano_id <> 7 AND projecao_matricula.etapa_ensino_escola_ano_id < 71')
.group('projecao_matricula.etapa_ensino_escola_ano_id') .group('projecao_matricula.etapa_ensino_escola_ano_id')
.group('projecao_matricula.ano_censo') .group('projecao_matricula.ano_censo')
.order('projecao_matricula.ano_censo') .order('projecao_matricula.ano_censo')
.order('projecao_matricula.etapa_ensino_escola_ano_id'); .order('projecao_matricula.etapa_ensino_escola_ano_id');
next(); next();
}, query, id2str.transform(), (req, res, next) => { }, query, id2str.transform(), (req, res, next) => {
req.result.forEach((r) => { let result = [];
r.urban_day_total = parseInt(r.urban_day_total, 10); let i = 0;
r.urban_night_total = ((r.education_level_school_year_id >= 3 && r.education_level_school_year_id < 10) || (r.education_level_school_year_id >= 30)) ? parseInt(r.urban_night_total, 10) : 0; //Não conta matrículas noturnas da pré-escola e da creche let j = 1;
r.rural_day_total = parseInt(r.rural_day_total, 10); let base_year = req.result[0].year;
r.rural_night_total = ((r.education_level_school_year_id >= 3 && r.education_level_school_year_id < 10) || (r.education_level_school_year_id >= 30)) ? parseInt(r.rural_night_total, 10) : 0;
}); let hashSet = new Set();
let atual_city_name;
let atual_city_id;
let atual_state_name;
let atual_state_id;
while (i < req.result.length || j <= 63) { // Adciona séries não existentes no banco com 0 nos totais.
let atual = req.result[i];
if (j > 63) { // Caso j passou da última série existente, mudamos de dimensão.
j = 1;
if (base_year !== atual.year) {
base_year = atual.year;
hashSet = new Set();
}
}
if (id2str.educationLevelSchoolYear(j) === id2str.educationLevelSchoolYear(99) || j === 7) {
j++;
continue;
}
if (j == 1) {
let hash = ""
if ('state' in req.dims)
hash += atual.state_id;
if ('city' in req.dims)
hash += atual.city_id;
if (!hashSet.has(hash)) {
hashSet.add(hash);
atual_city_id = atual.city_id;
atual_city_name = atual.city_name;
atual_state_id = atual.state_id;
atual_state_name = atual.state_name;
}
}
if (atual !== undefined && atual.education_level_school_year_id === j) { // Série existe.
atual.urban_day_total = parseInt(atual.urban_day_total, 10);
atual.urban_night_total = ((atual.education_level_school_year_id >= 3 && atual.education_level_school_year_id < 10) || (atual.education_level_school_year_id >= 30)) ? parseInt(atual.urban_night_total, 10) : 0; //Não conta matrículas noturnas da pré-escola e da creche
atual.rural_day_total = parseInt(atual.rural_day_total, 10);
atual.rural_night_total = ((atual.education_level_school_year_id >= 3 && atual.education_level_school_year_id < 10) || (atual.education_level_school_year_id >= 30)) ? parseInt(atual.rural_night_total, 10) : 0;
result.push(atual);
i++;
}
else { // Série não existe, adcionamos 0 ao resultado.
let base_result = {
name: req.result[0].name,
urban_day_total: 0,
urban_night_total: 0,
rural_day_total: 0,
rural_night_total: 0,
education_level_school_year_id: j,
year: base_year,
education_level_school_year_name: id2str.educationLevelSchoolYear(j)
};
if ('city' in req.dims) { // adciona os campos de cidade e/ou estado
base_result.city_id = atual_city_id;
base_result.city_name = atual_city_name;
}
if ('state' in req.dims) {
base_result.state_id = atual_state_id;
base_result.state_name = atual_state_name;
}
result.push(base_result)
}
j++;
}
req.result = result;
next(); next();
}, response('enrollment_projection')); }, response('enrollment_projection'));
......
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