Adjusted the way statistics get processed

This commit is contained in:
Maximilian Giller 2022-02-02 13:05:56 +01:00
parent a18f1b0fb2
commit 46194ab4fe

View file

@ -245,50 +245,25 @@ export const juggl = {
}); });
}, },
loadDailyStatistics({ dispatch }, { date }) { loadDailyStatistics({ dispatch }, { date }) {
dispatch("loadStatistics", [{ from: date, until: date }]); dispatch("loadStatistics", { from: date, until: date });
}, },
loadMonthlyStatistics( loadMonthlyStatistics(
{ dispatch }, { dispatch },
{ startYear, startMonth, endYear, endMonth } { startYear, startMonth, endYear, endMonth }
) { ) {
var frames = []; var options = {
from: new Date(startYear, startMonth, 1),
until: new Date(endYear, endMonth, 0) // 0 leads to the last day of the given month
};
// Count all the months until end year and month dispatch("loadStatistics", options);
while (
startYear < endYear ||
(startYear == endYear && startMonth <= endMonth)
) {
// Create frame
frames.push({
from: new Date(startYear, startMonth, 1),
until: new Date(startYear, startMonth, 0) // 0 leads to the last day of the given month
});
// Count up
if (startMonth >= 12) {
startMonth = 1;
startYear++;
} else {
startMonth++;
}
}
dispatch("loadStatistics", frames);
}, },
async loadStatistics({ commit }, frames) { async loadStatistics({ commit }, options) {
var statistics = []; var results = Object.values(
(await jugglService.getStatistics(options)).data.statistics
);
for (const frame of frames) { commit("setStatistics", results);
var result = Object.values(
(await jugglService.getStatistics(frame)).data.statistics
);
if (result.length > 0) {
statistics = [...statistics, ...result];
}
}
commit("setStatistics", statistics);
}, },
loadRunningRecords({ commit, getters }) { loadRunningRecords({ commit, getters }) {
return jugglService.getRunningRecords().then(r => { return jugglService.getRunningRecords().then(r => {