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,43 @@
#!/usr/bin/env node
const fs = require("fs/promises");
const { renderChart, makeBarConfig } = require("../lib/stats/charts");
const { fetchGoAccessJson, groupVisitsByMonth } = require("../lib/stats/goaccess");
const { loadToolsConfig } = require("../lib/config");
async function run({ stat, outputPath, publicPath }) {
if (!outputPath) {
throw new Error("outputPath manquant pour unique_visitors_per_month");
}
const toolsConfig = await loadToolsConfig();
const url = stat.url || toolsConfig.goaccess?.url || "";
const data = await fetchGoAccessJson(url);
const months = groupVisitsByMonth(data, { adjustCrawlers: true });
const labels = months.map((entry) => entry.month);
const values = months.map((entry) => entry.visitors);
const buffer = await renderChart(
makeBarConfig({
labels,
data: values,
title: "Visiteurs uniques par mois (hors crawlers)",
color: "rgba(239, 68, 68, 0.8)",
}),
);
await fs.writeFile(outputPath, buffer);
const latest = months[months.length - 1];
return {
image: publicPath,
meta: {
month: latest?.month || null,
visitors: latest?.visitors || 0,
},
};
}
module.exports = { run };