1

Page de statistiques

This commit is contained in:
2025-11-28 01:47:10 +01:00
parent 38926267a3
commit fd27dc7fb6
47 changed files with 3278 additions and 86 deletions

View File

@@ -0,0 +1,42 @@
#!/usr/bin/env node
const { fetchGoAccessJson, aggregateLastNDays } = require("../lib/stats/goaccess");
const { loadToolsConfig } = require("../lib/config");
let cache = null;
async function loadData(url) {
if (!cache) {
cache = await fetchGoAccessJson(url);
}
return cache;
}
function latestMonthEntry(months) {
if (!months || months.length === 0) return null;
return months[months.length - 1];
}
async function run({ stat }) {
const toolsConfig = await loadToolsConfig();
const url = stat.url || toolsConfig.goaccess?.url || "";
const metric = stat.metric || "hits";
const windowDays = Number.isFinite(stat.days) ? stat.days : 30;
const data = await loadData(url);
const window = aggregateLastNDays(data, windowDays, { adjustCrawlers: true });
if (!window || !window.to) return { value: 0 };
const value = metric === "visitors" ? window.visitors : window.hits;
return {
value,
meta: {
from: window.from || null,
to: window.to || null,
days: windowDays,
metric,
raw: value,
},
};
}
module.exports = { run };