Skip to content

Commit

Permalink
fix(alerts): aggregated different confidence levels
Browse files Browse the repository at this point in the history
  • Loading branch information
willian-viana committed Jul 16, 2024
1 parent 4cf606b commit 8a4ec20
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions components/widgets/fires/fires-alerts/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ const getAllAlerts = createSelector([getAlerts], (alerts) => {
});

export const getData = createSelector(
[getAllAlerts, getLatest],
(data, latest) => {
[getAllAlerts, getLatest, getOptionsSelected],
(data, latest, options) => {
if (!data || isEmpty(data)) return null;

const { confidence } = options;
const parsedData = data.map((d) => ({
...d,
count: d.alert__count || d.area_ha || 0,
Expand Down Expand Up @@ -176,15 +176,34 @@ export const getData = createSelector(
return;
}

const alerts = [];
const yearDataLength = yearDataByWeek[i]
? yearDataByWeek[i].length - 1
: 0;

for (let index = 0; index <= yearDataLength; index += 1) {
if (yearDataByWeek[i]) {
formattedData.push(yearDataByWeek[i][index]);
alerts.push(yearDataByWeek[i][index]);
}
}

if (confidence.value === 'h') {
formattedData.push(...alerts);
} else {
const allConfidencesAggregated = alerts.reduce(
(acc, curr) => {
return {
...curr,
confidence__cat: '', // high, low and normal
alert__count: acc?.alert__count + curr?.alert__count,
count: acc?.alert__count + curr?.alert__count,
};
},
{ alert__count: 0 }
);

formattedData.push(allConfidencesAggregated);
}
}
});

Expand Down

0 comments on commit 8a4ec20

Please sign in to comment.