mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-09-27 01:07:53 +00:00
feat: collapse Sessions and Entry Points to top 10 too
Same "Show all N / Show fewer" pattern just added for Top Senders and Coverage by Observer, extended to Sessions and Entry Points — a 7-day window can have a lot of rows in all four tables. Entry Points splits the resolve step (async /resolve-hops call, runs once) from the render step (sync, runs once per toggle) so expanding doesn't re-hit the API. The Ambiguous bucket row, when present, stays always-visible and doesn't count against the top-10 limit. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
352e1e322c
commit
8344b08683
+45
-24
@@ -5539,11 +5539,12 @@ function destroy() { _stopRolesRefresh(); _stopScopesRefresh(); _stopForeignTraf
|
||||
return (ms / 1000).toFixed(1) + 's';
|
||||
}
|
||||
|
||||
function sessionsHtml(sessions) {
|
||||
function sessionsHtml(sessions, expanded) {
|
||||
if (!sessions || sessions.length === 0) {
|
||||
return '<p class="text-muted" style="font-size:0.85em">No wardriving sessions in this window.</p>';
|
||||
}
|
||||
var rows = sessions.map(function(s) {
|
||||
var shown = expanded ? sessions : sessions.slice(0, TOP_N_LIMIT);
|
||||
var rows = shown.map(function(s) {
|
||||
return '<tr><td>' + senderTriggerHtml(s.sender, s.startTime, s.endTime) + '</td>' +
|
||||
'<td>' + (typeof timeAgo === 'function' ? timeAgo(s.startTime) : s.startTime) + '</td>' +
|
||||
'<td>' + formatSessionDuration(s.durationMinutes) + '</td>' +
|
||||
@@ -5555,7 +5556,7 @@ function destroy() { _stopRolesRefresh(); _stopScopesRefresh(); _stopForeignTraf
|
||||
return '<table class="data-table analytics-table" data-wd-cols="7">' +
|
||||
'<thead><tr><th>Sender</th><th>Started</th><th>Duration</th><th>Messages</th><th>Entry Points</th><th>Observers</th><th>Airtime</th></tr></thead>' +
|
||||
'<tbody>' + rows + '</tbody>' +
|
||||
'</table>';
|
||||
'</table>' + topNToggleHtml(sessions.length, expanded, 'sessions');
|
||||
}
|
||||
|
||||
var TOP_N_LIMIT = 10;
|
||||
@@ -5587,10 +5588,12 @@ function destroy() { _stopRolesRefresh(); _stopScopesRefresh(); _stopForeignTraf
|
||||
// same unique_prefix-only discipline as the Foreign Traffic tab (a
|
||||
// non-unique_prefix resolution is a genuine hash collision across
|
||||
// multiple candidate repeaters — folded into "Ambiguous" rather than
|
||||
// guessing).
|
||||
async function entryPointsHtml(prefixes) {
|
||||
// guessing). Split into an async resolve step (runs once) and a sync
|
||||
// render step (runs once per collapse/expand toggle) so expanding
|
||||
// doesn't re-hit /resolve-hops.
|
||||
async function resolveEntryPoints(prefixes) {
|
||||
if (!prefixes || prefixes.length === 0) {
|
||||
return '<p class="text-muted" style="font-size:0.85em">No wardriving messages with a relay path in this window.</p>';
|
||||
return { state: 'empty' };
|
||||
}
|
||||
try {
|
||||
var resp = await api('/resolve-hops?hops=' + prefixes.map(function(p) { return p.prefix; }).join(','), { ttl: CLIENT_TTL.nodeDetail }).catch(function() { return null; });
|
||||
@@ -5608,24 +5611,40 @@ function destroy() { _stopRolesRefresh(); _stopScopesRefresh(); _stopForeignTraf
|
||||
}
|
||||
});
|
||||
named.sort(function(a, b) { return b.obs - a.obs; });
|
||||
var rows = named.map(function(e) {
|
||||
return '<tr><td><a href="#/nodes/' + encodeURIComponent(e.pubkey) + '">' + esc(e.name) + '</a></td>' +
|
||||
'<td>' + e.obs.toLocaleString() + '</td>' +
|
||||
'<td>' + pct(e.obs, totalObs) + '</td>' +
|
||||
'<td>' + e.msgs.toLocaleString() + '</td></tr>';
|
||||
}).join('') + (ambiguousObs > 0
|
||||
? '<tr><td class="text-muted">Ambiguous (hash prefix collides across multiple candidate repeaters)</td>' +
|
||||
'<td>' + ambiguousObs.toLocaleString() + '</td><td>' + pct(ambiguousObs, totalObs) + '</td><td>' + ambiguousMsgs.toLocaleString() + '</td></tr>'
|
||||
: '');
|
||||
return (named.length > 0 || ambiguousObs > 0)
|
||||
? '<table class="data-table analytics-table">' +
|
||||
'<thead><tr><th>Entry-Point Repeater</th><th>Observations</th><th>% of Observations</th><th>Distinct Messages</th></tr></thead>' +
|
||||
'<tbody>' + rows + '</tbody>' +
|
||||
'</table>'
|
||||
: '<p class="text-muted" style="font-size:0.85em">No traceable relay path yet for any wardriving message.</p>';
|
||||
return { state: 'ok', named: named, ambiguousObs: ambiguousObs, ambiguousMsgs: ambiguousMsgs, totalObs: totalObs };
|
||||
} catch (e) {
|
||||
return { state: 'error' };
|
||||
}
|
||||
}
|
||||
|
||||
function entryPointsHtml(data, expanded) {
|
||||
if (data.state === 'empty') {
|
||||
return '<p class="text-muted" style="font-size:0.85em">No wardriving messages with a relay path in this window.</p>';
|
||||
}
|
||||
if (data.state === 'error') {
|
||||
return '<p class="text-muted">Failed to resolve entry points.</p>';
|
||||
}
|
||||
var named = data.named, ambiguousObs = data.ambiguousObs, ambiguousMsgs = data.ambiguousMsgs, totalObs = data.totalObs;
|
||||
if (named.length === 0 && ambiguousObs === 0) {
|
||||
return '<p class="text-muted" style="font-size:0.85em">No traceable relay path yet for any wardriving message.</p>';
|
||||
}
|
||||
// The ambiguous bucket (if any) is a fixed, always-visible row — only
|
||||
// the named repeaters collapse to top-N, so "Ambiguous" doesn't
|
||||
// count against the limit or get hidden by it.
|
||||
var shownNamed = expanded ? named : named.slice(0, TOP_N_LIMIT);
|
||||
var rows = shownNamed.map(function(e) {
|
||||
return '<tr><td><a href="#/nodes/' + encodeURIComponent(e.pubkey) + '">' + esc(e.name) + '</a></td>' +
|
||||
'<td>' + e.obs.toLocaleString() + '</td>' +
|
||||
'<td>' + pct(e.obs, totalObs) + '</td>' +
|
||||
'<td>' + e.msgs.toLocaleString() + '</td></tr>';
|
||||
}).join('') + (ambiguousObs > 0
|
||||
? '<tr><td class="text-muted">Ambiguous (hash prefix collides across multiple candidate repeaters)</td>' +
|
||||
'<td>' + ambiguousObs.toLocaleString() + '</td><td>' + pct(ambiguousObs, totalObs) + '</td><td>' + ambiguousMsgs.toLocaleString() + '</td></tr>'
|
||||
: '');
|
||||
return '<table class="data-table analytics-table">' +
|
||||
'<thead><tr><th>Entry-Point Repeater</th><th>Observations</th><th>% of Observations</th><th>Distinct Messages</th></tr></thead>' +
|
||||
'<tbody>' + rows + '</tbody>' +
|
||||
'</table>' + topNToggleHtml(named.length, expanded, 'entry-point repeaters');
|
||||
}
|
||||
|
||||
function observersHtml(observers, expanded) {
|
||||
@@ -5926,7 +5945,7 @@ function destroy() { _stopRolesRefresh(); _stopScopesRefresh(); _stopForeignTraf
|
||||
var body;
|
||||
try {
|
||||
var d = await api('/analytics/wardriving?window=' + encodeURIComponent(w), { ttl: 30000 });
|
||||
var entryHtml = await entryPointsHtml(d.entryPoints || []);
|
||||
var entryData = await resolveEntryPoints(d.entryPoints || []);
|
||||
body =
|
||||
'<div id="wardrivingCards" class="stats-grid" style="margin-bottom:16px">' + cardsHtml(d) + '</div>' +
|
||||
'<div id="wardrivingChart" style="margin-bottom:16px">' + chartHtml(d.timeSeries) + '</div>' +
|
||||
@@ -5941,10 +5960,10 @@ function destroy() { _stopRolesRefresh(); _stopScopesRefresh(); _stopForeignTraf
|
||||
'<div id="wardrivingSenders">' + sendersHtml(d.topSenders, d.totalMessages, false) + '</div>' +
|
||||
'<h4 style="margin:24px 0 4px">Sessions</h4>' +
|
||||
'<p class="text-muted" style="margin:0 0 8px;font-size:0.85em">Each sender\'s messages grouped into distinct runs — a gap of more than 15 minutes starts a new session.</p>' +
|
||||
'<div id="wardrivingSessions">' + sessionsHtml(d.sessions) + '</div>' +
|
||||
'<div id="wardrivingSessions">' + sessionsHtml(d.sessions, false) + '</div>' +
|
||||
'<h4 style="margin:24px 0 4px">Entry Points</h4>' +
|
||||
'<p class="text-muted" style="margin:0 0 8px;font-size:0.85em">Which local repeater first relayed each wardriving message — the hop closest to the origin (path[0]) across every observed copy.</p>' +
|
||||
'<div id="wardrivingEntryPoints">' + entryHtml + '</div>' +
|
||||
'<div id="wardrivingEntryPoints">' + entryPointsHtml(entryData, false) + '</div>' +
|
||||
'<h4 style="margin:24px 0 4px">Coverage by Observer</h4>' +
|
||||
'<p class="text-muted" style="margin:0 0 8px;font-size:0.85em">Which observer stations actually heard wardriving traffic — observers sit at fixed, known locations, so this is the reliable half of "how far did it reach."</p>' +
|
||||
'<div id="wardrivingObservers">' + observersHtml(d.observers, false) + '</div>' +
|
||||
@@ -5971,6 +5990,8 @@ function destroy() { _stopRolesRefresh(); _stopScopesRefresh(); _stopForeignTraf
|
||||
if (d) {
|
||||
wireExpandToggle('wardrivingSenders', function(exp) { return sendersHtml(d.topSenders, d.totalMessages, exp); });
|
||||
wireExpandToggle('wardrivingObservers', function(exp) { return observersHtml(d.observers, exp); });
|
||||
wireExpandToggle('wardrivingSessions', function(exp) { return sessionsHtml(d.sessions, exp); });
|
||||
wireExpandToggle('wardrivingEntryPoints', function(exp) { return entryPointsHtml(entryData, exp); });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -251,6 +251,39 @@ function makeApiStub(wardrivingResp, resolveHopsResp) {
|
||||
assert.ok(observersSection.includes('Show all 12 observers'), 'a "Show all" toggle should appear when there are more than 10 observers');
|
||||
});
|
||||
|
||||
await testAsync('Sessions and Entry Points collapse to top 10 with a "Show all" toggle', async () => {
|
||||
const manySessions = [];
|
||||
for (let i = 0; i < 13; i++) {
|
||||
manySessions.push({
|
||||
sender: 'Sender' + i, startTime: '2026-07-20T0' + (i % 9) + ':00:00Z', endTime: '2026-07-20T0' + (i % 9) + ':05:00Z',
|
||||
durationMinutes: 5, messageCount: 1, entryPointCount: 1, observerCount: 1, airtimeMs: 100,
|
||||
});
|
||||
}
|
||||
const manyPrefixes = [];
|
||||
const resolved = {};
|
||||
for (let i = 0; i < 14; i++) {
|
||||
const prefix = 'P' + String(i).padStart(3, '0');
|
||||
manyPrefixes.push({ prefix, observationCount: 14 - i, messageCount: 1 });
|
||||
resolved[prefix] = { name: 'Repeater' + i, pubkey: 'pk' + i, confidence: 'unique_prefix' };
|
||||
}
|
||||
const ctx = makeAnalyticsSandbox(makeApiStub(
|
||||
makeWardrivingResponse({ sessions: manySessions, entryPoints: manyPrefixes }),
|
||||
{ resolved }
|
||||
));
|
||||
const el = fakeEl();
|
||||
await ctx.window._analyticsRenderWardrivingTab(el);
|
||||
|
||||
const sessionsSection = el.innerHTML.slice(el.innerHTML.indexOf('id="wardrivingSessions"'), el.innerHTML.indexOf('id="wardrivingEntryPoints"'));
|
||||
assert.ok(sessionsSection.includes('>Sender9<'), 'the 10th session (index 9) should be shown');
|
||||
assert.ok(!sessionsSection.includes('>Sender10<'), 'the 11th session should be collapsed away by default');
|
||||
assert.ok(sessionsSection.includes('Show all 13 sessions'), 'a "Show all" toggle should appear when there are more than 10 sessions');
|
||||
|
||||
const entrySection = el.innerHTML.slice(el.innerHTML.indexOf('id="wardrivingEntryPoints"'), el.innerHTML.indexOf('id="wardrivingObservers"'));
|
||||
assert.ok(entrySection.includes('Repeater9'), 'the 10th entry point (index 9, highest observation count) should be shown');
|
||||
assert.ok(!entrySection.includes('Repeater10'), 'the 11th entry point should be collapsed away by default');
|
||||
assert.ok(entrySection.includes('Show all 14 entry-point repeaters'), 'a "Show all" toggle should appear when there are more than 10 entry points');
|
||||
});
|
||||
|
||||
await testAsync('Top Senders names are clickable drill-down triggers (whole-window, no since/until)', async () => {
|
||||
const ctx = makeAnalyticsSandbox(makeApiStub(makeWardrivingResponse()));
|
||||
const el = fakeEl();
|
||||
|
||||
Reference in New Issue
Block a user