Skip to content
Snippets Groups Projects
Commit 62322835 authored by Fernando Erd's avatar Fernando Erd :ok_hand:
Browse files

v1.9.8

parent 770cd7c0
No related branches found
No related tags found
1 merge request!197v1.9.8
Pipeline #20232 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.9.8 - 2019-08-02
## Changed
- Fix bug duplicate city name in classroom count
## 1.9.7 - 2019-05-02 ## 1.9.7 - 2019-05-02
## Changed ## Changed
- Fix enrollment projection - Fix enrollment projection
......
...@@ -265,7 +265,6 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { ...@@ -265,7 +265,6 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
next(); next();
}, rqf.parse(), rqf.build(), (req, res, next) => { }, rqf.parse(), rqf.build(), (req, res, next) => {
req.classroom = req.result; req.classroom = req.result;
let classroom = [];
// req.result = [{classroom: req.classroom, enrollment: req.enrollment}]; return next(); // req.result = [{classroom: req.classroom, enrollment: req.enrollment}]; return next();
...@@ -304,10 +303,11 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { ...@@ -304,10 +303,11 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
if( !hashSet.has(hash) ) { if( !hashSet.has(hash) ) {
if (result[result.length - 1] !== undefined) { // Após mudar de cidade, passamos pela cidade anterior e juntamos o valor to_be_built de localizações com o mesmo id if (result[result.length - 1] !== undefined) { // Após mudar de cidade, passamos pela cidade anterior e juntamos o valor to_be_built de localizações com o mesmo id
let last_locations = result[result.length - 1].locations let last_locations = result[result.length - 1].locations
for (let i = 1; i < last_locations.length; i++) { for (let i = 0; i < last_locations.length - 1; i++) {
if (last_locations[i].location_id === last_locations[i-1].location_id) { if (last_locations[i].location_id === last_locations[i+1].location_id) {
last_locations[i].total_classroom_be_built += last_locations[i-1].total_classroom_be_built; last_locations[i].total_classroom_be_built += last_locations[i+1].total_classroom_be_built;
last_locations[i-1].total_classroom_be_built = 0; last_locations[i].total_classroom += last_locations[i+1].total_classroom;
last_locations.splice(i+1, 1);
} }
} }
for (let i = 0; i < last_locations.length; i++) { // Passamos agora para não deixar to_be_built < 0 for (let i = 0; i < last_locations.length; i++) { // Passamos agora para não deixar to_be_built < 0
...@@ -337,18 +337,10 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { ...@@ -337,18 +337,10 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
continue; continue;
} }
if(classroom.city_name < enrollment.city_name) { // Se as cidades não são iguais, já passamos do range if(classroom.city_id !== enrollment.city_id) { // Se as cidades não são iguais, já passamos do range
enrollmentMatch = false; enrollmentMatch = false;
continue; continue;
} else if(classroom.city_name > enrollment.city_name) { }
let enrollmentHash = '' + enrollment.year + enrollment.state_id + enrollment.city_id;
if(hashSet.has(enrollmentHash)) {
leftovers.push(enrollments.splice(j, 1)); // Para inspeção, adiciona os que "sobram" no array de sobras
} else {
++j;
}
continue;
}
if(enrollment.year != classroom.year || enrollment.location_id != classroom.location_id) { // Se ano ou localização são diferentes, passa para o próximo if(enrollment.year != classroom.year || enrollment.location_id != classroom.location_id) { // Se ano ou localização são diferentes, passa para o próximo
++j; ++j;
...@@ -515,6 +507,21 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { ...@@ -515,6 +507,21 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
++i; ++i;
} }
// Tratamento do último resultado, para remover double location, tirar negativo do to_be_built.
if (result[result.length - 1] !== undefined) { // Após mudar de cidade, passamos pela cidade anterior e juntamos o valor to_be_built de localizações com o mesmo id
let last_locations = result[result.length - 1].locations
for (let i = 0; i < last_locations.length - 1; i++) {
if (last_locations[i].location_id === last_locations[i+1].location_id) {
last_locations[i].total_classroom_be_built += last_locations[i+1].total_classroom_be_built;
last_locations[i].total_classroom += last_locations[i+1].total_classroom;
last_locations.splice(i+1, 1);
}
}
for (let i = 0; i < last_locations.length; i++) { // Passamos agora para não deixar to_be_built < 0
last_locations[i].total_classroom_be_built = (last_locations[i].total_classroom_be_built < 0) ? 0 : last_locations[i].total_classroom_be_built;
}
}
// Agregar por estado e brasil // Agregar por estado e brasil
let reduction = null; let reduction = null;
if(req.dims.state || !req.dims.city) { // Se um dos dois acontecer, sabemos que devemos agregar if(req.dims.state || !req.dims.city) { // Se um dos dois acontecer, sabemos que devemos agregar
...@@ -551,6 +558,15 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { ...@@ -551,6 +558,15 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
if(currentObj.locations.length == 0) { if(currentObj.locations.length == 0) {
// Pode ser que a cidade atual tenha menos localidades que o total (só urbana ou só rural) // Pode ser que a cidade atual tenha menos localidades que o total (só urbana ou só rural)
currentObj.locations = [...city.locations]; currentObj.locations = [...city.locations];
if (currentObj.locations.length === 1) { // Se a cidade só tinha uma, adcionamos a outra manualmente.
currentObj.locations[1] = {
location_id: (currentObj.locations[0].location_id === 1) ? 2 : 1, // Oposto da adcionada
location_name: (currentObj.locations[0].location_id === 1) ? 'Rural' : 'Urbana', // Oposto da adcionada
total_classroom: 0,
total_classroom_be_built: 0,
education_level: []
}
}
} else { } else {
let j = 0; let j = 0;
let k = 0; let k = 0;
...@@ -566,12 +582,6 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { ...@@ -566,12 +582,6 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
} else if(cityLocation.location_id > currentLocation.location_id) { } else if(cityLocation.location_id > currentLocation.location_id) {
++k; ++k;
currentLocation = currentObj.locations[k]; currentLocation = currentObj.locations[k];
// Se a localidade da cidade é maior que a localidade do objeto atual E o vetor de localidades do objeto atual
// acaba, então esta localidade falta no objeto atual, pois as localidades estão ordenadas
if(typeof currentLocation == 'undefined' && typeof cityLocation !== 'undefined') {
currentObj.locations[k] = cityLocation;
currentLocation = currentObj.locations[k];
}
continue; continue;
} }
......
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