Statistics: Fix issue with missing days

Fixes #397
This commit is contained in:
rubenwardy
2022-11-09 18:46:11 +00:00
parent 852e6ab5a0
commit e15a3c682f
5 changed files with 115 additions and 17 deletions

View File

@@ -32,6 +32,7 @@ function sum(list) {
const chartColorsBg = chartColors.map(color => `rgba(${hexToRgb(color.slice(1))}, 0.2)`);
const SECONDS_IN_A_DAY = 1000 * 3600 * 24;
async function load_data() {
const root = document.getElementById("stats-root");
@@ -46,6 +47,14 @@ async function load_data() {
return;
}
const startDate = new Date(json.start);
const endDate = new Date(json.end);
const numberOfDays = Math.round((endDate.valueOf() - startDate.valueOf()) / SECONDS_IN_A_DAY) + 1;
const dates = [...Array(numberOfDays)].map((_, i) => {
const date = new Date(startDate.valueOf() + i*SECONDS_IN_A_DAY);
return date.toISOString().split('T')[0];
});
const total7 = sum(json.platform_minetest.slice(-7)) + sum(json.platform_other.slice(-7));
document.getElementById("downloads_total7d").textContent = total7;
document.getElementById("downloads_avg7d").textContent = (total7 / 7).toFixed(0);
@@ -66,7 +75,7 @@ async function load_data() {
root.style.display = "block";
function getData(list) {
return list.map((value, i) => ({ x: json.dates[i], y: value }));
return list.map((value, i) => ({ x: dates[i], y: value }));
}
{