v1.6.28 : drill-down IP par AS dans stats pays, suppression Répartition par réseau
- Admin stats : clic sur un réseau AS affiche les IPs avec mini sparkline 14 jours + articles/livres consultés - AccessLogParser : calcul ip_data (daily + top paths) inclus dans le cache stats - Suppression du tableau statique "Répartition par réseau" (fusionné dans accordéon pays) - PHP-CS-Fixer appliqué sur l'ensemble des fichiers modifiés Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+107
-41
@@ -1,35 +1,63 @@
|
||||
/* Admin stats : groupes AS + chargement pages via flux RSS XML /trending?period=14d */
|
||||
/* Admin stats : graphiques, sparklines, accordéon pays/AS/IP */
|
||||
|
||||
function esc(s) {
|
||||
return String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
||||
}
|
||||
|
||||
// ── Visiteurs par pays ────────────────────────────────────────────────────────
|
||||
(function () {
|
||||
var el = document.getElementById('stats-country-container');
|
||||
var asList = (typeof FOLIO_AS_LIST !== 'undefined') ? FOLIO_AS_LIST : [];
|
||||
var ipData = (typeof FOLIO_IP_DATA !== 'undefined') ? FOLIO_IP_DATA : {};
|
||||
if (!el || !asList.length) { return; }
|
||||
|
||||
// Noms de pays en français via l'API Intl
|
||||
var dispNames = null;
|
||||
try { dispNames = new Intl.DisplayNames(['fr'], { type: 'region' }); } catch (e) {}
|
||||
function countryName(code) {
|
||||
if (!code || code === '??') { return 'Inconnu'; }
|
||||
try { return dispNames ? dispNames.of(code) : code; } catch (e) { return code; }
|
||||
}
|
||||
|
||||
// Drapeau emoji depuis le code ISO-2
|
||||
function flag(code) {
|
||||
if (!code || code.length !== 2) { return ''; }
|
||||
var cp = Array.from(code.toUpperCase()).map(function (c) {
|
||||
return 0x1F1E6 + c.charCodeAt(0) - 65;
|
||||
});
|
||||
return String.fromCodePoint(cp[0], cp[1]) + ' ';
|
||||
var cp = Array.from(code.toUpperCase()).map(function (c) { return 0x1F1E6 + c.charCodeAt(0) - 65; });
|
||||
return String.fromCodePoint(cp[0], cp[1]) + ' ';
|
||||
}
|
||||
|
||||
// Index IPs par ASN pour le drill-down
|
||||
var ipsByAsn = {};
|
||||
Object.keys(ipData).forEach(function (ip) {
|
||||
var d = ipData[ip];
|
||||
var key = d.asn || '__unknown__';
|
||||
if (!ipsByAsn[key]) { ipsByAsn[key] = []; }
|
||||
ipsByAsn[key].push({ ip: ip, hits: d.hits, daily: d.daily, paths: d.paths });
|
||||
});
|
||||
Object.keys(ipsByAsn).forEach(function (k) {
|
||||
ipsByAsn[k].sort(function (a, b) { return b.hits - a.hits; });
|
||||
});
|
||||
|
||||
// Mini sparkline (80×20px polyline) pour chaque IP
|
||||
function ipSparkline(daily) {
|
||||
if (!daily || !daily.length) { return ''; }
|
||||
var W = 80, H = 20, padX = 1, padY = 2;
|
||||
var max = Math.max.apply(null, daily) || 1;
|
||||
var n = daily.length;
|
||||
var pts = daily.map(function (v, i) {
|
||||
var x = padX + i * (W - 2 * padX) / (n - 1);
|
||||
var y = H - padY - (v / max) * (H - 2 * padY);
|
||||
return x.toFixed(1) + ',' + y.toFixed(1);
|
||||
}).join(' ');
|
||||
return '<svg xmlns="http://www.w3.org/2000/svg" width="' + W + '" height="' + H
|
||||
+ '" style="display:block;flex-shrink:0">'
|
||||
+ '<polyline points="' + pts + '" fill="none" stroke="#6c757d"'
|
||||
+ ' stroke-width="1.2" stroke-linejoin="round" stroke-linecap="round"/>'
|
||||
+ '</svg>';
|
||||
}
|
||||
|
||||
// Agréger par pays
|
||||
var byCountry = {};
|
||||
var asByCountry = {}; // country → [{name, asn, hits}]
|
||||
var byCountry = {}, asByCountry = {};
|
||||
asList.forEach(function (as) {
|
||||
var c = as.country || '??';
|
||||
byCountry[c] = (byCountry[c] || 0) + as.hits;
|
||||
byCountry[c] = (byCountry[c] || 0) + as.hits;
|
||||
if (!asByCountry[c]) { asByCountry[c] = []; }
|
||||
asByCountry[c].push(as);
|
||||
});
|
||||
@@ -41,26 +69,83 @@
|
||||
if (!countries.length) { el.innerHTML = '<p class="text-muted mb-0">Aucune donnée.</p>'; return; }
|
||||
|
||||
var maxH = countries[0].hits || 1;
|
||||
|
||||
var html = '<div class="accordion accordion-flush" id="acc-countries">';
|
||||
countries.forEach(function (c, i) {
|
||||
|
||||
countries.forEach(function (c, ci) {
|
||||
var pct = Math.round(c.hits / maxH * 100);
|
||||
var cname = flag(c.code) + countryName(c.code);
|
||||
var vis = c.hits.toLocaleString('fr-FR');
|
||||
var accId = 'acc-country-' + i;
|
||||
var accId = 'acc-country-' + ci;
|
||||
var nets = c.networks.slice().sort(function (a, b) { return b.hits - a.hits; });
|
||||
var maxN = nets[0] ? nets[0].hits : 1;
|
||||
|
||||
var netRows = nets.map(function (n) {
|
||||
var npct = Math.round(n.hits / maxN * 100);
|
||||
return '<div class="d-flex align-items-center gap-2 py-1">'
|
||||
+ '<div class="text-muted small" style="width:9rem;flex-shrink:0">'
|
||||
+ (n.name || '?') + (n.asn ? ' <span class="opacity-50">AS' + n.asn + '</span>' : '') + '</div>'
|
||||
var netRows = nets.map(function (n, ni) {
|
||||
var npct = Math.round(n.hits / maxN * 100);
|
||||
var asId = 'acc-as-' + ci + '-' + ni;
|
||||
var asnKey = n.asn || '__unknown__';
|
||||
var ips = ipsByAsn[asnKey] || [];
|
||||
|
||||
// Lignes IP avec mini sparkline + chemins
|
||||
var ipRows = ips.slice(0, 20).map(function (ipInfo) {
|
||||
var articles = [], books = [];
|
||||
Object.keys(ipInfo.paths || {}).forEach(function (path) {
|
||||
var cnt = ipInfo.paths[path];
|
||||
if (path.indexOf('/post/') === 0) { articles.push({ path: path, cnt: cnt }); }
|
||||
else if (path.indexOf('/book/') === 0) { books.push({ path: path, cnt: cnt }); }
|
||||
});
|
||||
articles.sort(function (a, b) { return b.cnt - a.cnt; });
|
||||
books.sort(function (a, b) { return b.cnt - a.cnt; });
|
||||
|
||||
var pathsHtml = '';
|
||||
if (articles.length) {
|
||||
pathsHtml += '<div style="font-size:.75rem;color:#6c757d">Articles : '
|
||||
+ articles.slice(0, 3).map(function (p) {
|
||||
var slug = decodeURIComponent(p.path.replace('/post/', ''));
|
||||
return '<a href="' + esc(p.path) + '" target="_blank" style="color:inherit">'
|
||||
+ esc(slug.length > 28 ? slug.slice(0, 28) + '…' : slug)
|
||||
+ '</a> (' + p.cnt + ')';
|
||||
}).join(', ') + '</div>';
|
||||
}
|
||||
if (books.length) {
|
||||
pathsHtml += '<div style="font-size:.75rem;color:#6c757d">Livres : '
|
||||
+ books.slice(0, 3).map(function (p) {
|
||||
var slug = decodeURIComponent(p.path.replace('/book/', ''));
|
||||
return '<a href="' + esc(p.path) + '" target="_blank" style="color:inherit">'
|
||||
+ esc(slug.length > 28 ? slug.slice(0, 28) + '…' : slug)
|
||||
+ '</a> (' + p.cnt + ')';
|
||||
}).join(', ') + '</div>';
|
||||
}
|
||||
if (!pathsHtml) { pathsHtml = '<span style="font-size:.75rem;color:#adb5bd">—</span>'; }
|
||||
|
||||
return '<div class="d-flex align-items-center gap-2 py-1 border-bottom">'
|
||||
+ '<code style="width:9rem;flex-shrink:0;font-size:.72rem;color:#6c757d">'
|
||||
+ esc(ipInfo.ip) + '</code>'
|
||||
+ ipSparkline(ipInfo.daily || [])
|
||||
+ '<div class="flex-grow-1">' + pathsHtml + '</div>'
|
||||
+ '<div class="text-end text-muted small" style="width:4rem;flex-shrink:0">'
|
||||
+ (ipInfo.hits || 0).toLocaleString('fr-FR') + '</div>'
|
||||
+ '</div>';
|
||||
}).join('');
|
||||
|
||||
var hasIps = ips.length > 0;
|
||||
var toggleAttrs = hasIps ? ' data-bs-toggle="collapse" data-bs-target="#' + asId + '" role="button"' : '';
|
||||
var chevron = hasIps ? '<span class="text-muted ms-1" style="font-size:.65rem">▾</span>' : '';
|
||||
|
||||
return '<div>'
|
||||
+ '<div class="d-flex align-items-center gap-2 py-1"' + toggleAttrs + '>'
|
||||
+ '<div class="small" style="width:9rem;flex-shrink:0">'
|
||||
+ esc(n.name || '?')
|
||||
+ (n.asn ? ' <span class="text-muted">AS' + esc(n.asn) + '</span>' : '')
|
||||
+ chevron + '</div>'
|
||||
+ '<div class="flex-grow-1"><div class="progress" style="height:4px">'
|
||||
+ '<div class="progress-bar bg-info" style="width:' + npct + '%"></div>'
|
||||
+ '</div></div>'
|
||||
+ '<div class="text-end text-muted small" style="width:4rem;flex-shrink:0">'
|
||||
+ n.hits.toLocaleString('fr-FR') + '</div>'
|
||||
+ '</div>'
|
||||
+ (hasIps ? '<div id="' + asId + '" class="collapse">'
|
||||
+ '<div class="border-start ms-3 ps-2 pb-1">' + ipRows + '</div>'
|
||||
+ '</div>' : '')
|
||||
+ '</div>';
|
||||
}).join('');
|
||||
|
||||
@@ -80,6 +165,7 @@
|
||||
+ '</div>'
|
||||
+ '</div>';
|
||||
});
|
||||
|
||||
html += '</div>';
|
||||
el.innerHTML = html;
|
||||
}());
|
||||
@@ -91,10 +177,6 @@
|
||||
var pagesByDay = (typeof FOLIO_PAGES_BY_DAY !== 'undefined') ? FOLIO_PAGES_BY_DAY : {};
|
||||
if (!container) { return; }
|
||||
|
||||
function esc(s) {
|
||||
return String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
||||
}
|
||||
|
||||
function sparkline(data) {
|
||||
var W = 120, H = 28, padX = 2, padY = 3;
|
||||
var max = Math.max.apply(null, data) || 1;
|
||||
@@ -104,7 +186,6 @@
|
||||
var y = H - padY - (v / max) * (H - 2 * padY);
|
||||
return x.toFixed(1) + ',' + y.toFixed(1);
|
||||
}).join(' ');
|
||||
// Zone remplie sous la courbe
|
||||
var first = padX.toFixed(1) + ',' + (H - padY).toFixed(1);
|
||||
var last = (W - padX).toFixed(1) + ',' + (H - padY).toFixed(1);
|
||||
return '<svg xmlns="http://www.w3.org/2000/svg" width="' + W + '" height="' + H + '" style="display:block;overflow:visible">'
|
||||
@@ -123,17 +204,15 @@
|
||||
|
||||
var n = totals.length;
|
||||
var VW = 900, VH = 480;
|
||||
var ml = 44, mr = 12, mt = 12, mb = 28; // marges pour axes
|
||||
var ml = 44, mr = 12, mt = 12, mb = 28;
|
||||
var W = VW - ml - mr;
|
||||
var H = VH - mt - mb;
|
||||
|
||||
// Échelle Y — plafond arrondi à un multiple "propre"
|
||||
var rawMax = Math.max.apply(null, totals) || 1;
|
||||
var mag = Math.pow(10, Math.floor(Math.log(rawMax) / Math.LN10));
|
||||
var maxV = Math.ceil(rawMax / mag) * mag;
|
||||
var nTicks = 4;
|
||||
|
||||
// Dates
|
||||
var now = new Date();
|
||||
var labels = totals.map(function (_, i) {
|
||||
var d = new Date(now);
|
||||
@@ -141,17 +220,10 @@
|
||||
return d.toLocaleDateString('fr-FR', { day: 'numeric', month: 'short' });
|
||||
});
|
||||
|
||||
// Coordonnées des points
|
||||
var pts = totals.map(function (v, i) {
|
||||
return {
|
||||
x: ml + i * W / (n - 1),
|
||||
y: mt + H - (v / maxV) * H,
|
||||
v: v,
|
||||
l: labels[i]
|
||||
};
|
||||
return { x: ml + i * W / (n - 1), y: mt + H - (v / maxV) * H, v: v, l: labels[i] };
|
||||
});
|
||||
|
||||
// Courbe bezier lisse (tension 0.35)
|
||||
function smoothPath(points) {
|
||||
var d = 'M ' + points[0].x.toFixed(1) + ' ' + points[0].y.toFixed(1);
|
||||
for (var i = 0; i < points.length - 1; i++) {
|
||||
@@ -176,7 +248,6 @@
|
||||
+ ' L ' + pts[n - 1].x.toFixed(1) + ' ' + (mt + H)
|
||||
+ ' L ' + pts[0].x.toFixed(1) + ' ' + (mt + H) + ' Z';
|
||||
|
||||
// Grille horizontale + labels Y
|
||||
var grid = '', yLabels = '';
|
||||
for (var t = 0; t <= nTicks; t++) {
|
||||
var val = Math.round(maxV * t / nTicks);
|
||||
@@ -187,7 +258,6 @@
|
||||
+ ' font-size="11" fill="#adb5bd">' + val + '</text>';
|
||||
}
|
||||
|
||||
// Labels X (toutes les 2 dates + dernière)
|
||||
var xLabels = '';
|
||||
pts.forEach(function (p, i) {
|
||||
if (i % 2 === 0 || i === n - 1) {
|
||||
@@ -196,7 +266,6 @@
|
||||
}
|
||||
});
|
||||
|
||||
// Points interactifs (cercle invisible + tooltip natif)
|
||||
var dots = pts.map(function (p) {
|
||||
return '<circle cx="' + p.x.toFixed(1) + '" cy="' + p.y.toFixed(1) + '" r="14"'
|
||||
+ ' fill="transparent" cursor="default">'
|
||||
@@ -238,7 +307,6 @@
|
||||
var W = VW - ml - mr;
|
||||
var H = VH - mt - mb;
|
||||
|
||||
// Top articles par total (max 10), dans l'ordre du RSS
|
||||
var series = [];
|
||||
rssRows.forEach(function (row) {
|
||||
var pm = row.link.match(/\/post\/[^?#]*/);
|
||||
@@ -312,7 +380,6 @@
|
||||
+ '" stroke-width="1.8" stroke-linejoin="round" stroke-linecap="round"/>' + dots;
|
||||
}).join('');
|
||||
|
||||
// Légende
|
||||
var legend = series.map(function (s, si) {
|
||||
var color = COLORS[si % COLORS.length];
|
||||
var short = s.title.length > 32 ? s.title.slice(0, 32) + '…' : s.title;
|
||||
@@ -351,7 +418,6 @@
|
||||
var daily = pm ? (pagesByDay[pm[0]] || null) : null;
|
||||
return { title: title, link: link, slug: slug, vis: vis, daily: daily };
|
||||
});
|
||||
// Graphique global : somme de tous les articles par jour
|
||||
var nDays = 14;
|
||||
var totals = new Array(nDays).fill(0);
|
||||
Object.values(pagesByDay).forEach(function (arr) {
|
||||
|
||||
Reference in New Issue
Block a user