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 }) {
dispatch("loadStatistics", [{ from: date, until: date }]);
dispatch("loadStatistics", { from: date, until: date });
},
loadMonthlyStatistics(
{ dispatch },
{ 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
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);
dispatch("loadStatistics", options);
},
async loadStatistics({ commit }, frames) {
var statistics = [];
async loadStatistics({ commit }, options) {
var results = Object.values(
(await jugglService.getStatistics(options)).data.statistics
);
for (const frame of frames) {
var result = Object.values(
(await jugglService.getStatistics(frame)).data.statistics
);
if (result.length > 0) {
statistics = [...statistics, ...result];
}
}
commit("setStatistics", statistics);
commit("setStatistics", results);
},
loadRunningRecords({ commit, getters }) {
return jugglService.getRunningRecords().then(r => {