From a18f1b0fb2e3152a4c29d173078d148e7bc27057 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 2 Feb 2022 11:50:34 +0100 Subject: [PATCH] Reworked statistics interface --- src/store/modules/juggl.js | 53 +++++++++++++++++++++++++++++++------- src/views/Statistics.vue | 2 +- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/store/modules/juggl.js b/src/store/modules/juggl.js index f8f9656..79a0f58 100644 --- a/src/store/modules/juggl.js +++ b/src/store/modules/juggl.js @@ -244,18 +244,51 @@ export const juggl = { commit("setRecords", allRecords); }); }, - loadTodaysStatistics({ dispatch }) { - dispatch("loadStatistics", { from: new Date(), until: new Date() }); + loadDailyStatistics({ dispatch }, { date }) { + dispatch("loadStatistics", [{ from: date, until: date }]); }, - loadStatistics({ commit }, { from, until }) { - var options = { - from: from, - until: until - }; + loadMonthlyStatistics( + { dispatch }, + { startYear, startMonth, endYear, endMonth } + ) { + var frames = []; - return jugglService.getStatistics(options).then(r => { - commit("setStatistics", r.data.statistics); - }); + // 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); + }, + async loadStatistics({ commit }, frames) { + var 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); }, loadRunningRecords({ commit, getters }) { return jugglService.getRunningRecords().then(r => { diff --git a/src/views/Statistics.vue b/src/views/Statistics.vue index 72c71fa..a338cc1 100644 --- a/src/views/Statistics.vue +++ b/src/views/Statistics.vue @@ -26,7 +26,7 @@ export default { }; }, created: function() { - store.dispatch("loadTodaysStatistics"); + store.dispatch("loadDailyStatistics", { date: new Date() }); }, computed: { visibleStatistics: () => {