errors_list = all_data.map((a, idx, arr) => {
let sumTot = 0;
let sumEmp = 0;
let sumOcc = 0;
const errors = [];
homes.forEach(h => {
const hTot = a['rh.' + h.id + '.total'];
const hEmp = a['rh.' + h.id + '.employee'];
const hOcc = a['rh.' + h.id + '.occupant'];
if (+hTot != +hEmp + +hOcc) {
errors.push({rh: h.id, total: hTot, employee: hEmp, occupant: hOcc});
}
sumTot += +hTot;
sumEmp += +hEmp;
sumOcc += +hOcc;
});
const mainStat = stats_data[dateStr(a.date)];
if (idx > 0) {
for (const prop in a) {
checkDecrease(a, arr[idx-1], prop, errors);
}
const mainStatPrev = stats_data[dateStr(arr[idx-1].date)];
checkDecrease(mainStat, mainStatPrev, 'cases.rh.employee.confirmed.todate', errors);
checkDecrease(mainStat, mainStatPrev, 'cases.rh.occupant.confirmed.todate', errors);
}
const tot = a['rh.total'];
const emp = a['rh.employee.total'];
const occ = a['rh.occupant.total'];
if (tot != emp + occ) {
errors.push({total: tot, employee: emp, occupant: occ});
}
if (sumTot != tot) {
errors.push({total: tot, agg_total: sumTot});
}
if (sumEmp != emp) {
errors.push({employee: emp, agg_employee: sumEmp});
}
if (sumOcc != occ) {
errors.push({occupant: occ, agg_occupant: sumOcc});
}
if (occ != +mainStat['cases.rh.occupant.confirmed.todate']) {
errors.push({occupant: occ, stats_occupant: mainStat['cases.rh.occupant.confirmed.todate']});
}
if (emp != +mainStat['cases.rh.employee.confirmed.todate']) {
errors.push({employee: emp, stats_employee: mainStat['cases.rh.employee.confirmed.todate']});
}
return errors.length == 0
? null
: ({date: a.date, errors: errors});
}).filter(a => a);