2024-06-26 16:01:50 +03:00
|
|
|
export default function mergeStatsByDate(list) {
|
|
|
|
const reducedStatsByDate = list.reduce((acc, current) => {
|
|
|
|
const currentDate = current.date;
|
2024-06-26 15:20:48 +03:00
|
|
|
|
2024-06-26 16:01:50 +03:00
|
|
|
if (!acc[currentDate]) {
|
|
|
|
acc[currentDate] = {
|
|
|
|
date: currentDate,
|
|
|
|
count: 0,
|
|
|
|
positiveDelta: 0,
|
|
|
|
negativeDelta: 0,
|
|
|
|
signups: 0,
|
|
|
|
cancellations: 0
|
|
|
|
};
|
|
|
|
}
|
2024-06-26 15:20:48 +03:00
|
|
|
|
2024-06-26 16:01:50 +03:00
|
|
|
acc[currentDate].count += current.count;
|
|
|
|
acc[currentDate].positiveDelta += current.positive_delta;
|
|
|
|
acc[currentDate].negativeDelta += current.negative_delta;
|
|
|
|
acc[currentDate].signups += current.signups;
|
|
|
|
acc[currentDate].cancellations += current.cancellations;
|
2024-06-26 15:20:48 +03:00
|
|
|
|
2024-06-26 16:01:50 +03:00
|
|
|
return acc;
|
|
|
|
}, {});
|
2024-06-26 15:20:48 +03:00
|
|
|
|
2024-06-26 16:01:50 +03:00
|
|
|
return Object.values(reducedStatsByDate);
|
2024-06-26 15:20:48 +03:00
|
|
|
}
|