Page de statistiques
This commit is contained in:
43
tools/stats/unique_visitors_per_month.js
Normal file
43
tools/stats/unique_visitors_per_month.js
Normal 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 };
|
||||
Reference in New Issue
Block a user