Commit 727e2536 authored by Vytor Calixto's avatar Vytor Calixto 👾

Start work on state and brasil dimensions

parent ea9d7bc5
Pipeline #15437 canceled with stage
in 11 seconds
......@@ -233,7 +233,6 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
delete req.filter;
next();
}, rqf.parse(), rqf.build(), (req, res, next) => {
console.log('dims', req.dims);
req.classroom = req.result;
let classroom = [];
......@@ -247,29 +246,18 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
while (i < req.classroom.length) {
let classroom = req.classroom[i];
// Cria hash única para cada espacialidade, dado um ano
let hash = '' + classroom.year;
if(req.dims.state) hash+= '' + classroom.state_id;
if(req.dims.city) hash+= '' + classroom.state_id + classroom.city_id;
let hash = '' + classroom.year + classroom.state_id + classroom.city_id;
// Estrutura do objeto do resultado final
let obj = {
year: classroom.year,
name: classroom.name,
state_id: classroom.state_id,
state_name: classroom.state_name,
city_id: classroom.city_id,
city_name: classroom.city_name,
locations: []
};
if(req.dims.state) {
obj.state_id = classroom.state_id;
obj.state_name = classroom.state_name;
}
console.log('city', req.dims.city);
if(req.dims.city) {
obj.state_id = classroom.state_id;
obj.state_name = classroom.state_name;
obj.city_id = classroom.city_id;
obj.city_name = classroom.city_name;
}
let currentClassroomObj = null;
if( !hashSet.has(hash) ) {
hashSet.add(hash);
......@@ -401,7 +389,45 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
++i;
}
// TODO: agregar por estado e brasil
let reduction = null;
if(req.dims.state || !req.dims.city) { // Se um dos dois acontecer, sabemos que devemos agregar
let i = 0;
reduction = [];
let reductionSet = new Set();
while (i < result.length) {
let city = result[i];
let obj = {
year: city.year,
name: city.name
}
if(req.dims.state) {
obj.state_id = city.state_id;
obj.state_name = city.state_name;
}
obj.locations = [];
let hash = '' + city.year;
if(req.dims.state) hash += '' + city.state_id;
let currentObj = null;
if(!reductionSet.has(hash)) {
reductionSet.add(hash);
reduction.push(obj);
currentObj = obj;
} else { // Está ordenado, podemos pegar o último
currentObj = reduction[reduction.length - 1];
}
// TODO: Fazer "merge" do array locations da cidade com o da agregação
// TODO: Somar total de turmas, matrículas e salas a serem construídas
++i;
}
}
if(req.dims.state) {
console.log('ESTADO!!!!');
} else if(!req.dims.city) {
......
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