Skip to content
Snippets Groups Projects

Despesas

Merged Joao Pedro Ramalho requested to merge despesas into development
1 file
+ 41
12
Compare changes
  • Side-by-side
  • Inline
@@ -308,20 +308,49 @@ rqf.addField({
@@ -308,20 +308,49 @@ rqf.addField({
}
}
});
});
// The queries are matched and the total is calculated
/*
function matchQueries(attendsSchoolObj, populationObj) {
The queries are matched and the total is calculated.
let match = [];
This function is necessary to match the results of the
2 queries with the right pair. In some queries, the result
for (let i = 0; i < attendsSchoolObj.length; i++) {
doesn't exist in one of the 2, so, we need to run this algorithm
let newObj = attendsSchoolObj[i];
to match them right.
*/
newObj.total = (attendsSchoolObj[i].total / populationObj[i].total) * 100;
newObj.age_range_id = newObj.faixa_etaria;
function matchQueries(queryPartial, queryTotal) {
delete newObj.faixa_etaria;
let match = [];
 
queryTotal.forEach((result) => {
 
let newObj = {};
 
let keys = Object.keys(result);
 
keys.forEach((key) => {
 
newObj[key] = result[key];
 
});
 
let index = keys.indexOf('total');
 
if(index > -1) keys.splice(index, 1);
 
let objMatch = null;
 
 
for(let i = 0; i < queryPartial.length; ++i) {
 
let partial = queryPartial[i];
 
let foundMatch = true;
 
for(let j = 0; j < keys.length; ++j) {
 
let key = keys[j];
 
if(partial[key] !== result[key]) {
 
foundMatch = false;
 
break;
 
}
 
}
 
if(foundMatch) {
 
objMatch = partial;
 
break;
 
}
 
}
match.push(newObj);
if(objMatch) {
}
newObj.denominator = result.total;
 
newObj.partial = objMatch.total;
 
newObj.total = (objMatch.total / result.total) * 100;
 
match.push(newObj);
 
}
 
});
return match;
return match;
}
}
Loading