Skip to content

Analytics: area overview and comparison by DAGI area (kommune, landsdel, region, postnummer) — research first #1002

Backlog

Description

@dborup

Idea

With the DAGI filter (#740: kommune, landsdel, region, postnummer), the Nodes page can narrow the list to an area and report how many nodes without a position it hid. Users also want numbers about the selected area and a way to compare areas.

This is separate from #740 M3c, which only makes the existing Analytics tabs honour the DAGI selection. This issue is a new overview.

Wanted (owner, 2026-11-27)

An overview of one selected area:

  • the number of nodes by role;
  • active vs quiet/stale nodes;
  • new nodes;
  • observers;
  • packets per hour;
  • the busiest repeaters;
  • the average number of hops.

A comparison across all kommuner, landsdele or regioner:

  • for example repeaters per kommune and repeaters per 100 km²;
  • where coverage or observers are missing;
  • possibly a choropleth map: kommuner coloured by a chosen metric.

Placement: a new Analytics tab, "Areas (DAGI)", sharing the analytics cache and the DAGI selection.

Research first (M0, no code)

  1. Metrics: for each wanted number, define it exactly, and say where it comes from: the in-memory store, the existing analytics snapshots, or the DAGI membership cache (code → set(pubkey)). Note the existing helpers it can reuse. Which numbers are cheap, and which are expensive?
  2. Semantics:
  3. Area-normalised metrics: per 100 km² from the DAGI areaM2. Is a per-inhabitant metric possible without new data (population is not in DAGI)? If not, leave it out.
  4. Performance (AGENTS.md rule 0):
    • the cost of computing per-area aggregates for all 99 kommuner, 11 landsdele, 5 regioner and ~600 postnumre;
    • one pass over nodes and traffic, cached and refreshed with the analytics cycle;
    • no per-area queries per request;
    • memory bounds.
  5. API shape: named structs (no map[string]interface{}); one endpoint for the overview of one area and one for the comparison table; how it fits the existing analytics cache keys and the DAGI selection (nodeScopeKey).
  6. UI:
    • the tab layout on desktop and a phone;
    • the comparison as a sortable table plus an optional choropleth (polygons from GET /api/config/dagi/polygons, the cost on a phone);
    • deep links (#/analytics?tab=areas&kommune=…);
    • the credit line.
  7. Privacy: hidden or blacklisted nodes must not leak through counts in small areas. Mirror how the existing analytics handle hidden identities.
  8. Plan: milestones (for example M1 the overview API and tab, M2 the comparison table, M3 the choropleth), each with tests, perf proof and customizer implications (rule 8).

Depends on #740 M1/M2 (merged) and M3a (merged).

🤖 Generated with Claude Code

Activity

  1. dborup commented on Nov 27, 2026

    @dborup
    OwnerAuthor

    Research (M0) — #1002

    Scope: #1002, an Analytics tab "Areas (DAGI)" with an overview of one area and a comparison across areas. Research and plan only: no repo change, no commit, no PR.

    Base: origin/master at 71372e99 (#740 M1 #983, M2 #988 and M3a #991 merged; M3b #1003 open; M3c not started). I exported it with git archive to a scratch folder. The measurements ran there as throw-away Go tests (not committed) against the real embedded DAGI asset, the real dagiMembership and a real PacketStore.

    Evidence labels: [T] tested on 2026-11-27 (a command was run and its output read); [K] read in code on origin/master; [A] assumption or judgement.


    1. Conclusion and recommendation

    1. One new background aggregate, computed in one pass for all 720 areas. That is 99 kommuner, 11 landsdele, 5 regioner and 605 postnummer filter areas (602 plus the 3 Copenhagen street groups).
      • It is a new analyticsRecomputer ("dagi-areas") on the existing analytics cycle (default 5 min).
      • It reads the node snapshot, the DAGI membership snapshot and one pass over the window's transmissions.
      • Measured: 23 ms for all 720 areas at 2,500 nodes and 70K transmissions per day [T].
      • The rejected per-area approach is ~2.4 s (a naive filtered pass per area) or ~38 s (one computeAnalyticsTopology per area) [T].
    2. Two endpoints, both served straight from the snapshot, with no per-request compute and no new cache keys:
      • GET /api/analytics/dagi-areas?layer=kommune: the comparison table for one layer.
      • GET /api/analytics/dagi-area?kommune=0751: the overview of one area.
    3. Attribution rules:
    4. Privacy: hidden identities (node blacklist, observer blacklist, hidden name prefixes) are left out of every count and every list, exactly as /api/nodes and M2's unpositionedHidden do. An area's node count therefore equals the Nodes page total for the same DAGI filter. No small-count suppression is needed, because every remaining node is already public with its position.
    5. The tab key must not be areas. That key is the existing configured-areas tab (public/analytics.js:250). Recommended: tab=dagi-areas, label "Areas (DAGI)".
    6. Per 100 km²: kommune, landsdel and region only. Not for postnummer, because DAGI's postnummer polygons reach into the sea: they total 147,662 km² against 43,058 km² of land [T].
      • Per inhabitant: left out, because the asset has no population field.
    7. Two findings outside this issue's scope (§7.3):
      • the existing /api/analytics/areas counts blacklisted and hidden nodes (tested);
      • computeNewNodes filters the blacklist but not hidden name prefixes.
    8. Plan:

    2. Research point 1: metrics (definition, source, reuse, cost)

    All metrics use one window, the last 24 h (§9, Q3).

    • If the store holds less than 24 h, the response reports the covered start (oldestLoaded, store.go:579) and partialWindow: true. Per-hour rates then divide by the covered hours.
    • A "visible" node is one that identityHidden (identity_visibility.go:15) does not hide.
    Metric Exact definition Source Reuse Cost [T]
    Nodes by role Visible nodes whose cached membership includes the area. Roles: repeater, room, companion, sensor, other Node snapshot getCachedNodesAndPMOK (store.go:7965; role, lat/lon, last_seen and first_seen are already in it, store.go:7800) + membership snapshot (dagi_membership.go:43) normalizeRole (role_analytics.go), snap.nodes[pk].at, the postnummer-needs-kommune rule (dagi_membership.go:156) Node pass for all areas: 0.35 ms at 2.5K nodes, 3.1 ms at 20K
    Active / degraded / silent ("quiet/stale" = degraded + silent) classifyNodeHealth on last_seen with the configured thresholds (defaults: infra 24 h / 72 h, others 1 h / 24 h, config.go:1476), including observer credit Node snapshot + LoadObserverReports once per cycle classifyNodeHealth (observer_credit.go:111), GetHealthMs (config.go:1515): the Areas tab's and network status's rule In the node pass
    New nodes Visible nodes with first_seen within 7 days, excluding returning keys (an inactive_nodes row) Node snapshot FirstSeen + one bulk inactive_nodes query per cycle The rule inactiveNodeLastSeenSQL (new_nodes.go), so the tab agrees with Tools › New Nodes Node pass + 1 query per cycle
    Observers Distinct visible observers with ≥ 1 observation in the window whose own node position is in the area (an observer's position is its node's GPS, as PacketPathObserver documents at db.go:2303) The transmission pass (tx.Observations) + membership ID lower-cased (observer IDs arrive in any case, identity_visibility.go comment) In the transmission pass
    Packets per hour, heard Distinct transmissions in the window with ≥ 1 observation by a visible observer in the area, in 24 hourly buckets; the table shows the 24 h total s.packets (sorted by first_seen, store.go:247) Deduped per transmission per area, so a packet heard by 3 Aarhus observers counts once for Aarhus, Østjylland and Midtjylland The transmission pass: 23 ms in total with the next two rows
    Packets per hour, relayed Distinct transmissions with ≥ 1 resolved relay hop on a visible node in the area resolvedPubkeyReverse txID → pubkey hashes (store.go:535) The same source as distinctRelayCount (relay_airtime_share.go:120); hash → node via resolvedPubkeyHash (resolved_index.go:266) In the transmission pass
    Busiest repeaters The top 5 visible repeaters in the area by distinct transmissions relayed in the window As above Per-node counter, then top-K per area Negligible after the pass
    Average hops Mean path length (1 decimal) of the heard transmissions that have a path The cached display path txGetParsedPath (longest observation) The avgHopsOf rule (store.go:10841), but unrounded In the transmission pass
    Repeaters per 100 km² Repeaters ÷ (areaM2 / 10⁸). Kommune, landsdel and region only Asset areaM2 (dagi.go:136) — Trivial
    Coverage gaps Flags per row: no nodes; nodes but no repeater; repeaters but no active observer; nothing heard Derived from the row — Trivial

    What already exists for one area, and why it is not reused for the comparison:

    • computeAnalyticsTopology (store.go:8428) already yields avgHops (store.go:8612) and topRepeaters (store.go:8751) for one node scope. That is how Backlog: place names, DAGI region filter and km² coverage from Klimadatastyrelsen data #740 M3c will make Topology honour a DAGI selection.
    • Its definition is relay-based through prefix resolution: transmissions with ≥ 1 hop resolved to an area node. That is not the observer-based definition above (§9, Q2).
    • Its cost is a full scan with hop resolution: 50.5 ms (kommune 0101) and 54.7 ms (0751) on the same 70K-transmission day [T]. Calling it 720 times would take about 38 s.

    Cheap vs expensive: every node metric is cheap (< 1 ms for all areas). The traffic metrics are the expensive part. Of the measured 23 ms [T]:

    • the observer map lookups (175K observations) take 3.3 ms;
    • the relay reads (286K resolved hops) take 1.0 ms;
    • time.Parse on 70K timestamps takes 2.4 ms. A string compare takes 0.44 ms, and a binary search on the sorted s.packets would replace it.
    • The rest is the per-area dedupe and the counter updates.

    3. Research point 2: semantics

    Node position, observer position or traffic:

    • Nodes (counts, roles, health, new, density) use node position (membership), the same as the DAGI filter on Nodes.
    • Traffic uses observer position as the primary series, because every packet has an observer but only some have resolved relays.
      • The second series, relay position, answers "how busy are the area's repeaters".
      • By sender is rejected for traffic: only ADVERTs name their sender (store.go:4409, as M2 documents), so "packets from Aarhus" would only count adverts.

    Nodes without a position (no GPS, 0/0, NaN or out of range; dagi_membership.go:142):

    • They are in no area row.
    • The tab shows one national line, "N nodes have no position, so no area includes them", counted with unpositionedVisible (dagi_api.go:175). That is the same number and wording family as the M3a notice.
    • They are not estimated from neighbours. Estimated positions belong to the configured Areas tab and its own feature flag.

    Positioned but outside every kommune (abroad, at sea):

    • A second national count, outsideDenmark.
    • They are never rows. Postnummer membership already needs a kommune (dagi_membership.go:156), so a node at sea with "6960" is not counted under 6960.

    Postnummer areas that reach into the sea (#983):

    • Membership is safe, by the rule above.
    • Area is not safe. The postnummer areaM2 values total 147,662 km², against 43,058 km² for kommune, landsdel and region [T].
      • 6960 Hvide Sande is 9,832 km², 6950 Ringkøbing 5,995 km², 6990 Ulfborg 5,738 km² and 3730 Nexø 3,212 km² [T].
      • So no per-km² metric for postnummer (§9, Q4).

    Christiansø (0411, outsideKommune: true, 0.35 km², dagi.go:156):

    • It is shown as a kommune-layer row labelled "Christiansø (outside the kommune division)", as in M3a.
    • It is excluded from the per-100 km² ranking and the choropleth scale: one node there is 286 per 100 km². Its density cell shows "—".
    • It still counts in Region Hovedstaden and landsdel Bornholm.

    Copenhagen street postcodes:

    • One row per group, keyed by the group key (1050, 1550, 1800), with members folded in by dagiGroupStreetPostcodes (dagi.go:317). Labels come from M3a's group label: "1050–1473 København K".
    • The group's area is the sum of its members: 1800 = 2.15 km² [T]. It is unused anyway, since there is no postnummer density.

    Overlapping layers: a node counts once per layer (kommune ⊂ landsdel ⊂ region; postnummer is independent). Layer totals are therefore comparable across layers, but they are never summed across layers.


    4. Research point 3: area-normalised metrics

    • Per 100 km²:
      • Use areaM2 from the asset. It is the source area, exterior minus holes, which M1 also uses for precedence.
      • Ranges [T]:
        • kommune: 0.35 km² (Christiansø), then 8.71 km² (Frederiksberg) to 1,494 km² (Ringkøbing-Skjern), median 357 km²;
        • landsdel: 185 km² (Byen København) to 8,649 km² (Sydjylland);
        • region: 2,572 km² (Hovedstaden) to 13,145 km² (Midtjylland).
      • Proposed metrics: repeaters per 100 km² and observers per 100 km². Nodes per 100 km² is optional.
    • Per inhabitant: not possible without new data.
      • The asset's feature fields are code, name, region, outsideKommune, street, areaM2 and rings (dagi.go:126–142). There is no population.
      • Population would need a second source, such as Danmarks Statistik per kommune, with its own licence and refresh.
      • Left out, as the issue asks.

    5. Research point 4: performance (AGENTS.md rule 0)

    5.1 Data used

    The data is synthetic, built from the CI fixture's shape and scaled to about 2,500 nodes [T]:

    • Fixture: 200 nodes, 31 observers, and 499 transmissions in 2.1 h.
    • Nodes:
      • 2,500 nodes. 60 % are clustered around 16 Danish towns and 40 % are uniform; only points inside a kommune are kept.
      • The fixture's role mix: repeater 82.5 %, room 11.5 %, companion 4.5 %, sensor 1.5 %.
      • 9.5 % have no position (fixture: 19 of 200).
      • 356 are observers (fixture ratio 31/200).
    • Traffic:
      • 70,000 transmissions spread over 24 h: the fixture rate × 12.5.
      • Path lengths are drawn from the fixture's observation histogram, and 80 % of hops are resolved: 286K resolved relay hops in all.
      • 1–4 observers per transmission, 175K observations in all.
    • Also run: 140K transmissions per day, and 20K nodes with 560K transmissions.
    • Area counts: 99 kommuner, 11 landsdele, 5 regioner and 605 postnummer filter areas: 720 slots.

    5.2 Results

    All on local arm64 with Go 1.26.0; best of 5–7 runs [T].

    Case Membership refresh (exists since M2) All 720 areas of which the node pass Alloc per compute
    2,500 nodes / 70K tx 2.7 ms 23.0 ms 0.35 ms 570 KB
    2,500 nodes / 140K tx 2.7 ms 48.6 ms 0.34 ms 570 KB
    20,000 nodes / 560K tx 23.3 ms 233 ms 3.1 ms 3.1 MB

    Rejected alternatives, on the same 2,500-node / 70K-transmission day [T]:

    Approach Cost
    A naive filtered pass over the window, once per area (720 passes) 2.42 s (105× the one-pass cost)
    One computeAnalyticsTopology per area 50.5–54.7 ms each, so ≈ 38 s for 720. The unfiltered call is 77.6 ms

    5.3 Design consequences

    • One pass, cached, refreshed with the analytics cycle:
      • Add a recomputer in StartAnalyticsRecomputers (analytics_recomputer.go:480, default 5 min at line 482, configurable as for the others).
      • Use the StartupLoadDone warm-up gate like RF, Topology and Channels, and honour pauseWhenIdle.
      • Start it only when dagi.enabled and the asset loads.
    • No per-area queries per request: both endpoints index into one immutable snapshot published with atomic.Pointer. A request costs one slot lookup plus JSON encoding.
    • Locks:
      • The node pass runs outside s.mu.
      • The transmission pass needs s.mu.RLock, for s.packets, tx.Observations and resolvedPubkeyReverse: about 20 ms at 70K. That is shorter than the 77.6 ms the unfiltered topology recompute already holds on the same data [T].
      • Nothing is computed under a write lock.
      • The pass starts at sort.Search for the window start, not at the oldest packet.
    • Memory bounds:
      • The result is a fixed 720 rows × 288 B = 202 KB: 24 + 24 hourly buckets and a top-5 per row. Two snapshots live briefly during a swap.
      • The transient maps are bounded by the node count.
      • Nothing grows with traffic or requests, and the slot count is fixed by the asset (§9).
      • analyticsCacheMaxEntries (analytics_cache_bounds.go:28) is unaffected, because no cache keyed by request params is added.
    • Freshness of hidden identities:
      • The snapshot records BlacklistGeneration() and HiddenNamePrefixesGeneration() (config.go:1682, 1820).
      • A request that sees a different generation triggers RecomputeNow and waits for it (~23 ms) before serving, so a newly hidden node is never served from a stale snapshot.

    5.4 Response sizes

    Measured with encoding/json on the synthetic rows [T]:

    • Comparison: kommune is 26 KB raw (99 rows); postnummer is 157 KB raw (605 rows). Hence one layer per request.
    • Overview: about 1 KB.

    6. Research point 5: API shape

    Named structs only, with no map[string]interface{}. The existing AreaDensity.RoleCounts map[string]int (types.go:292) is not copied: roles become fixed fields.

    // GET /api/analytics/dagi-areas?layer=kommune|landsdel|region|postnummer
    type DagiAreaComparisonResponse struct {
        Layer         string        `json:"layer"`         // asset layer name
        Param         string        `json:"param"`         // its filter param (kommune, landsdel, dkregion, postnr)
        GeneratedAt   string        `json:"generatedAt"`
        WindowFrom    string        `json:"windowFrom"`    // max(now-24h, oldestLoaded)
        WindowTo      string        `json:"windowTo"`
        PartialWindow bool          `json:"partialWindow"`
        Credit        string        `json:"credit"`        // the DAGI credit (dagiIndex.credit)
        Totals        DagiAreaTotals `json:"totals"`
        Rows          []DagiAreaRow `json:"rows"`          // every area of the layer, also the empty ones
    }
    
    type DagiAreaTotals struct {
        Nodes          int `json:"nodes"`          // visible nodes
        Unpositioned   int `json:"unpositioned"`   // visible, no usable position
        OutsideDenmark int `json:"outsideDenmark"` // visible, positioned, in no kommune
    }
    
    type DagiAreaRow struct {
        Code           string   `json:"code"`  // filter key (group key for street postcodes)
        Name           string   `json:"name"`
        OutsideKommune bool     `json:"outsideKommune,omitempty"`
        Group          bool     `json:"group,omitempty"`
        AreaKm2        *float64 `json:"areaKm2"` // nil for postnummer
        Nodes          int      `json:"nodes"`
        Repeaters      int      `json:"repeaters"`
        Rooms          int      `json:"rooms"`
        Companions     int      `json:"companions"`
        Sensors        int      `json:"sensors"`
        OtherRoles     int      `json:"otherRoles"`
        Active         int      `json:"active"`
        Degraded       int      `json:"degraded"`
        Silent         int      `json:"silent"`
        New7d          int      `json:"new7d"`
        Observers      int      `json:"observers"`
        Heard          int      `json:"heard"`   // distinct tx in the window
        Relayed        int      `json:"relayed"`
        AvgHops        *float64 `json:"avgHops"` // nil when nothing heard had a path
        RepeatersPer100Km2 *float64 `json:"repeatersPer100Km2"` // nil for postnummer and Christiansø
        ObserversPer100Km2 *float64 `json:"observersPer100Km2"`
        Gaps           []string `json:"gaps,omitempty"` // "no-nodes" | "no-repeater" | "no-observer" | "nothing-heard"
    }
    
    // GET /api/analytics/dagi-area?<one of kommune|landsdel|dkregion|postnr>=<code>
    type DagiAreaOverviewResponse struct {
        Layer          string             `json:"layer"`
        Param          string             `json:"param"`
        GeneratedAt    string             `json:"generatedAt"`
        WindowFrom     string             `json:"windowFrom"`
        WindowTo       string             `json:"windowTo"`
        PartialWindow  bool               `json:"partialWindow"`
        Credit         string             `json:"credit"`
        Parents        DagiPlace          `json:"parents"` // landsdel/region of a kommune etc. (existing type, dagi.go:82)
        Row            DagiAreaRow        `json:"row"`
        HeardPerHour   [24]int            `json:"heardPerHour"`   // oldest hour first
        RelayedPerHour [24]int            `json:"relayedPerHour"`
        BusiestRepeaters []DagiAreaRepeater `json:"busiestRepeaters"` // ≤ 5, never nil
    }
    
    type DagiAreaRepeater struct {
        PublicKey string `json:"publicKey"`
        Name      string `json:"name"`
        Relayed   int    `json:"relayed"`
    }

    Validation reuses parseDagiRequest (dagi_api.go:82) and mirrors analytics today:

    • An unknown code is 400 unknown kommune (etc.), as analyticsScope does (dagi_api.go:306).
    • No DAGI param, or more than one, is 400 one DAGI area param is required. The client already sends exactly one (M3a's most-specific-wins rule).
    • An unknown layer is 400.
    • With DAGI off, both endpoints return 404, like the polygon endpoint.

    Fit with the existing cache keys and nodeScopeKey:

    • The computation is not per scope, so no nodeScopeKey (dagi_api.go:125) and no new cache key is involved. The selected area is just an index into the snapshot, and the snapshot is the analytics cache entry.
    • area (configured polygons) and region (observer IATA) are ignored by these endpoints, and the tab hides those controls (§9, Q10). Supporting them would mean one snapshot per region × area, which is the cardinality StartAnalyticsRecomputers explicitly avoids (its doc comment at analytics_recomputer.go:470).
    • setAnalyticsSnapshotHeaders (analytics_pause_when_idle.go:39) applies unchanged.
    • OpenAPI: both routes are documented, so TestOpenAPICompleteness passes.

    7. Research point 7: privacy

    7.1 What the code does today [K/T]

    Lists exclude hidden identities:

    • /api/nodes drops blacklisted keys and hidden name prefixes (routes.go:1863–1873).
    • M2's hidden count leaves them out (dagi_api.go:175).
    • Per-node views use identityHidden (identity_visibility.go:15), which also covers the observer blacklist.

    Several aggregate analytics count every node row:

    • Configured Areas tab: GetNodesForAreaAnalytics (db.go:4560) reads SELECT … FROM nodes with no filter. Tested: three nodes in one area, one blacklisted and one with a hidden prefix:
      • /api/nodes returns total: 1;
      • /api/analytics/areas returns density[0].total: 3.
      • In a small area, that difference reveals that hidden nodes are there.
    • Roles: computeAnalyticsRoles (role_analytics.go:153) counts the whole node snapshot, but only nationally.
    • New Nodes: computeNewNodes filters IsBlacklisted but not IsNameHidden (new_nodes.go:103).

    7.2 Rules for the new tab (recommended)

    1. Leave every hidden identity out of every number.
      • Apply identityHidden(cfg, pubkey, name) in the node pass. A hidden node is not counted: not in roles, health, new nodes, observers, density or totals.
      • Consequence, asserted by a test: for every area, row.nodes equals /api/nodes?<param>=<code> total.
    2. Hidden observers attribute nothing.
      • An observation by a hidden observer (node or observer blacklist, hidden name) is skipped.
      • A packet heard only by hidden observers in Aarhus does not count for Aarhus. Otherwise a lone hidden observer would show as "Observers 0, heard 1,200".
    3. Hidden relays attribute nothing, and they are never in Busiest repeaters. Names in that list come from the same snapshot as the node list.
    4. No small-count threshold (k-anonymity) [A].
      • After rules 1–3, an area's numbers describe only nodes that are already public, with their positions, on the Nodes page and the Map.
      • Small areas are common: 197 of 468 non-empty postnumre had fewer than 3 nodes in the synthetic data [T]. A threshold would blank most postnummer rows and hide nothing secret.
    5. National totals on the tab come from the tab's own snapshot, not from the Roles or network-status numbers.
      • Showing "network: 2,513 nodes" (Roles, which counts hidden nodes) next to a sum of 2,500 would publish the hidden count.
      • That count is national, not local, and Roles already shows it today.
    6. Generation stamps: no stale snapshot is served after a blacklist or prefix change (§5.3).

    7.3 Out of scope, worth separate issues

    • (a) /api/analytics/areas density, position gaps and probably bridge nodes include hidden identities (tested for density, §7.1).
    • (b) computeNewNodes ignores hidden name prefixes.

    8. Research point 6: UI

    8.1 Placement and deep links

    The tab:

    • A new button data-tab="dagi-areas", "Areas (DAGI)", placed after "Areas" (analytics.js:250), with a case 'dagi-areas' in the render switch (analytics.js:627).
    • It renders only with DAGI enabled: /api/config/dagi enabled true, read through M3a's memoised config. Otherwise the button is hidden.

    The code lives in its own file, public/analytics-dagi-areas.js (an IIFE with pure helpers, testable in vm), so analytics.js (8,033 lines) only gains the button and the case.

    The selection is M3a's DagiFilter:

    • getSelected(), onChange and ready() (dagi-filter.js:766).
    • ?kommune= / ?landsdel= / ?dkregion= / ?postnr= are already synced by the router.

    Tab-only params:

    • layer= (comparison layer) and sort= (metric), registered in TAB_URL_PARAMS (analytics.js:438) so other tabs drop them.
    • Examples:
      • #/analytics?tab=dagi-areas&kommune=0751
      • #/analytics?tab=dagi-areas&layer=postnummer&sort=heard
      • #/analytics?tab=dagi-areas&dkregion=1082&layer=kommune&sort=repeatersPer100Km2

    Defaults:

    • With no selection, the tab shows only the comparison.
    • With a selection, the overview sits above it, and the comparison opens on the layer one level finer: region → landsdel → kommune → postnummer. A postnummer selection compares postnumre.

    Filters:

    • The Area dropdown is already hidden outside AREA_FILTER_TABS (analytics.js:260).
    • The Region pills and the time window get a muted note: "Region and time-window filters do not apply to this tab: the numbers cover the whole network, last 24 h."

    8.2 Desktop (1440×900)

    The numbers in both mock-ups are illustrative, not measured; the areas are real (Aarhus is 471 km² in the asset).

    Mesh Analytics
    [ AAR ][ CPH ][ … ]   [ Kommune: Aarhus  ✕ ▾ ]                  ← RegionFilter, DagiFilter (M3a)
    [Overview][RF / Signal]…[Wardriving][Areas][Areas (DAGI)][Prefix Tool]
     ⓘ Region and time-window filters do not apply here: whole network, last 24 h.
    
    ┌ Aarhus · kommune 0751 · Østjylland · Region Midtjylland ─────────── 471 km² ┐
    │ Nodes 87        Repeaters 71 · Rooms 9 · Companions 5 · Sensors 2          │
    │ Active 64 · Degraded 15 · Silent 8     New (7 days) 3     Observers 12      │
    │ Repeaters / 100 km²  15.1              Avg hops (heard) 4.2                 │
    │                                                                            │
    │ Packets per hour   heard ▁▂▂▃▅▆█▇▆▅▄▃▃▂▂▁▁▁▂▃▄▅▆▇   relayed ▁▁▂▂▃▄▅▅…      │
    │                    −24 h                                         now       │
    │ Busiest repeaters (relayed, 24 h)                                          │
    │  1  AAR-Rptr-01   1,204      2  Risskov-Mast   988      3  …               │
    └────────────────────────────────────────────────────────────────────────────┘
     Compare  [Region] [Landsdel] [Kommune•] [Postnummer]          [ Show map ]  (M3)
    ┌──────────────────┬──────┬──────┬────────────┬────────┬──────────┬────────┬──────┬──────────┐
    │ Kommune        ▲ │Nodes │ Rep. │ Rep/100 km²│ Active │Observers │ Heard  │ Hops │ Gaps     │
    ├──────────────────┼──────┼──────┼────────────┼────────┼──────────┼────────┼──────┼──────────┤
    │ Aabenraa         │   12 │   10 │        1.1 │      9 │        0 │    412 │  5.1 │ no obs.  │
    │ Aalborg          │   64 │   51 │        4.5 │     47 │        6 │  9,870 │  3.8 │          │
    │ Aarhus      ◀    │   87 │   71 │       15.1 │     64 │       12 │ 14,233 │  4.2 │          │
    │ …                                                                    (99 rows)          │
    │ Christiansø (outside the kommune division) │ 1 │ 1 │ — │ …                             │
    └──────────────────────────────────────────────────────────────────────────────────────────┘
     3 nodes have no position, so no area includes them. 2 are outside Denmark.
     Indeholder data fra Klimadatastyrelsen, DAGI, november 2026, CC BY 4.0 — data bearbejdet · Licence · Terms
    

    8.3 Phone (375×560)

    ┌───────────────────────────────────┐
    │ [ Kommune: Aarhus ✕ ▾ ]           │  DagiFilter sheet (M3a)
    │ ‹ Areas  [Areas (DAGI)]  Prefix › │  tab bar scrolls sideways (existing)
    │ ⓘ Whole network, last 24 h        │
    │ ┌ Aarhus · 0751 ──────── 471 km² ┐│
    │ │ Nodes 87   Repeaters 71        ││  2-column stat cards
    │ │ Active 64  Quiet 23            ││  "Quiet" = degraded + silent
    │ │ New 3      Observers 12        ││
    │ │ Rep/100 km² 15.1  Hops 4.2     ││
    │ │ Heard/h ▁▂▃▅▇█▇▅▃▂▁▂▃▅▆▇      ││  one sparkline, toggle heard/relayed
    │ │ Busiest: AAR-Rptr-01 1,204 ›   ││  top 3, "more" expands to 5
    │ └────────────────────────────────┘│
    │ Compare [Kommune ▾]  Sort [Rep/100 km² ▾] │
    │  1  Frederiksberg        41.3 ›   │  one metric column per row,
    │  2  København            22.0 ›   │  tap a row = select that area
    │  3  Aarhus ◀             15.1 ›   │  (DagiFilter pick → URL)
    │  …                                │
    │ [ Show map ]                      │  M3: polygons load only on tap
    │ 3 without position · 2 abroad     │
    │ DAGI © Klimadatastyrelsen, CC BY… │
    └───────────────────────────────────┘
    

    Table behaviour:

    • Sorting on desktop: click a column header.
    • Sorting on a phone: a select, because seven columns do not fit in 375 px.
    • Rendering:
      • Rows are built once per layer.
      • A sort reorders the existing <tr>/<li> nodes (appendChild in the new order), and a refresh patches their cells. There is never a full innerHTML rebuild (rule 0).
      • The largest layer is 605 rows.
    • Text: textContent only, so the XSS gate needs no opt-out.
    • Picking an area: a tap or click on a row calls the DagiFilter pick, so the overview, the URL and the other pages follow.

    8.4 Choropleth (M3) and its phone cost

    Layer Raw / gzip -6 Phone 375×560, CPU 4× throttled Desktop 1440×900, no throttle
    kommune (102 paths) 309,934 B / 129,387 B 83.8 ms 21.7 ms
    postnummer (1,092 paths) 322,937 B / 122,201 B 112.9 ms 28.1 ms
    landsdel 191,365 B / 80,290 B 69.3 ms 18.2 ms
    region 179,504 B / 75,606 B 68.4 ms 18.2 ms
    • Download size: compression.gzip defaults to false (config.example.json:627). Without a gzipping proxy, a phone downloads the raw 180–323 KB once per layer per day, and the browser caches it.
    • Recommendations:
      • The map loads only when "Show map" is tapped (default off on every screen size, and the choice is kept in the URL as map=1).
      • Only the comparison's layer is drawn.
      • Changing the metric restyles the existing polygons (setStyle) and never re-fetches.
      • Colours: 5 quantile buckets from new CSS variables --dagi-choro-1 … 5 (theming rule), with "no data" as --border.
      • Christiansø is excluded from the scale.
      • The Leaflet attribution carries the credit.

    8.5 Credit line

    • Tab footer: the DAGI credit from /api/config/dagi, with Licence and Terms links built by M3a's footer builder (dagi-filter.js:445), exported for reuse rather than copied (DRY).
    • Map: the Leaflet attribution while the choropleth is shown.
    • Data: both endpoints also return credit, so an API consumer gets it too (CC BY 4.0 attribution).

    9. Research point 8: plan

    Each milestone is one PR and needs owner sign-off (rule 5).

    M1: the aggregate, the overview API and the tab (overview only)

    Changes:

    • cmd/server/dagi_area_stats.go:
      • computeDagiAreaStats(nodes, snap, txWindow, cfg, now): a pure function over plain inputs;
      • the dagi-areas recomputer;
      • the generation stamps;
      • GET /api/analytics/dagi-area;
      • the structs from §6;
      • OpenAPI.
    • public/analytics-dagi-areas.js: the overview card, the sparkline, the busiest list, the notices and the credit.
    • analytics.js: the button, the case and TAB_URL_PARAMS.
    • Docs: a section in docs/user-guide/area-filter.md on what the numbers mean.

    Tests:

    Perf proof:

    • BenchmarkDagiAreaStats (2.5K/70K, 2.5K/140K, 20K/560K).
    • TestDagiAreaStatsWithinBudget, best of 5. Proposed budgets (×12 under -race), set from the measured 23 ms and 233 ms:
      • ≤ 150 ms at 2.5K nodes / 70K transmissions;
      • ≤ 1.5 s at 20K / 560K.
    • The RLock hold time, logged.

    Browser validation (rule 2): screenshots at 375×560 and 1440×900, light and dark.

    Customizer (rule 8): none yet. M4 tracks the hardcoded values: the 24 h window, 7 days for "new", top 5, and the default comparison metric.

    M2: the comparison table

    Changes:

    • GET /api/analytics/dagi-areas?layer=.
    • The sortable table (desktop) and the list with a sort select (phone), as in §8.2–8.3.
    • Row tap selects the area.
    • The gap flags.
    • layer= / sort= deep links.

    Tests:

    • Go: shape per layer; every area present including empty ones; 605 postnummer rows with groups; Christiansø density nil; gap flags.
    • Unit: sorting is stable on ties (by name with Danish collation, as M3a does); a reorder keeps the existing row nodes (identity check); layer/sort round-trip through the URL.
    • Playwright: a phone sort change, a row tap that updates the URL and the overview, and the desktop header sort.

    Perf: first render of the 605 postnummer rows and one re-sort at 4× CPU throttling.

    • Proposed budget: ≤ 150 ms and ≤ 50 ms, asserted in E2E.
    • Encoding time for the 157 KB postnummer response.

    Customizer: note the default layer and metric for M4.

    M3: the choropleth

    Changes:

    • "Show map": a lazy polygon fetch for the comparison layer.
    • setStyle on metric change, the quantile legend and the attribution.
    • --dagi-choro-1…5 in style.css, mapped in THEME_CSS_MAP (customize.js).
    • Depends on M3b's decodeRings.

    Tests:

    • Unit: bucket edges, Christiansø excluded, no-data colour.
    • Playwright: no polygon request before the tap; exactly one after; the metric change makes no new request; the attribution is present.

    Perf: decode + draw at 4× throttling.

    • Measured 68–113 ms today; budget ≤ 250 ms.
    • The bytes on the wire, logged with and without compression.gzip.

    Customizer: the colour ramp variables (theming rule).

    M4: the customizer

    A dagi-areas section following the masts/heritage pattern:

    • the window (enum 24 h / 7 d, only if the owner wants 7 d, and only within the in-memory window);
    • "new" age;
    • top-N;
    • the default layer and metric;
    • map on by default.

    An enum-keyed window needs no extra cache cap (#430 exemption, since window is whitelisted).

    Tests: a sandbox test plus an e2e twin, as in 723/724.


    10. Open questions for the owner (each with my recommended default)

    1. Traffic attribution: observer position as the main "heard" series, plus relay position as a second "relayed" series?
      • Default: both, with heard primary.
      • Alternative: relay only, which matches Topology's area filter but gives nothing in areas with few resolved hops.
    2. Average hops: the mean path length of packets heard in the area?
      • Default: yes.
      • Alternative: Topology's relay-based avgHops, which M3c will show for the same selection. The two can differ, so the tab's label says "heard".
    3. Window: a fixed 24 h, with "new" = first seen within 7 days, excluding returning keys?
      • Default: yes.
      • A 7 d window would depend on how much the store keeps in memory.
    4. Postnummer density: omit per-km² for postnummer?
      • Default: omit.
      • Alternative: a land-clipped area computed at build time in scripts/build-dagi.py. That changes the asset and its pinned SHA-256.
    5. Christiansø: listed, with "—" for density and outside the choropleth scale?
      • Default: yes.
    6. Tab name and key: "Areas (DAGI)" with tab=dagi-areas?
      • Default: yes. tab=areas is taken.
      • Alternative: rename the existing tab to "Areas (custom)". That changes existing UI, so it is not recommended.
    7. Order: Analytics: area overview and comparison by DAGI area (kommune, landsdel, region, postnummer) — research first #1002 M1 after Backlog: place names, DAGI region filter and km² coverage from Klimadatastyrelsen data #740 M3c, which puts the DAGI control on Analytics?
      • Default: after M3c.
      • Alternative: M1 mounts the control for this tab only, and M3c extends it.
    8. Out-of-scope privacy gaps (§7.3): the configured Areas tab counts hidden nodes, and New Nodes ignores hidden prefixes.
      • Default: two separate small issues, fixed before or with M1.
    9. Active vs quiet: reuse classifyNodeHealth (active / degraded / silent, with observer credit, the configured thresholds)?
      • Default: yes. The phone shows "Quiet" = degraded + silent.
    10. Region and Area filters on this tab: ignored, with a visible note?
      • Default: yes. The numbers cover the whole network.
      • Region-scoped aggregates would need one snapshot per region and are YAGNI until asked for.
    11. Choropleth: behind a "Show map" button on every screen size?
      • Default: yes. It is up to 323 KB raw when gzip is off.
    12. Small areas: no k-anonymity threshold, since hidden identities are removed entirely and the rest is public?
      • Default: no threshold.

    11. What was not verified

    • Real traffic:
      • The CI fixture has no Danish nodes, so every per-area count above is from synthetic data shaped like the fixture.
      • The 70K transmissions per day is the fixture's rate scaled by node count, not a production figure.
      • Staging and production were not touched.
    • Resolved relay coverage: I assumed that 80 % of hops resolve. With fewer, "relayed" and Busiest repeaters undercount, but the cost goes down.
    • Bridge nodes in the configured Areas tab: the hidden-identity test covered density only, because the test had no neighbour graph. That bridge nodes also leak is inferred from the code.
    • The choropleth timings are headless Chromium with CDP throttling, not a real phone.
    • Go 1.26.0 on arm64 was used locally. CI uses 1.27.1 on amd64, so the budgets in §9 leave a wide margin.
    • Nothing was published: the throw-away measurement tests were not committed.

    🤖 Generated with Claude Code

  2. dborup commented on Nov 28, 2026

    @dborup
    OwnerAuthor

    Owner decisions on the M0 research (2026-11-28)

    These answer the 12 open questions in §10. Where an answer differs from the research's default, the line says "changed".

    1. Traffic: both series. "Heard" (observers in the area) comes first, "relayed" (repeaters in the area) second.
    2. Average hops: changed. Show both: the mean path length of packets heard in the area, and Topology's relay-based avgHops, side by side and labelled "heard" and "relayed".
    3. Window: a fixed 24 h. A node is "new" when it was first seen within 7 days; a returning key is not new.
    4. Postnummer density: changed. Show per 100 km² for postnumre too, using the DAGI areaM2 as is (no land clipping). The UI notes that coastal postnumre include sea, so their density reads low.
    5. Christiansø: listed, with "—" for density, and left out of the choropleth scale.
    6. Tab: "Areas (DAGI)", key tab=dagi-areas. The existing Areas tab is unchanged.
    7. Order: changed. M1 runs in parallel with Backlog: place names, DAGI region filter and km² coverage from Klimadatastyrelsen data #740 M3c. M1 mounts the DAGI control on its own tab only, and M3c later extends it to the other tabs. Keep the shared code in dagi-filter.js so the two do not fork.
    8. Privacy gaps: two separate issues, fixed before M1: Analytics: the Areas tab counts hidden identities #1005 (the Areas tab counts hidden identities) and Analytics: New Nodes ignores hidden name prefixes #1006 (New Nodes ignores hidden name prefixes).
    9. Active vs quiet: reuse classifyNodeHealth. On a phone, "Quiet" covers degraded and silent.
    10. Region and Area filters: ignored on this tab, with a visible note.
    11. Choropleth: behind a "Show map" button on every screen size.
    12. Small areas: no threshold. Hidden identities are left out entirely (§7.2, rules 1–6).

    Next: #1005 and #1006, then M1 (the overview API and the tab).

    🤖 Generated with Claude Code

  3. dborup commented on Nov 29, 2026

    @dborup
    OwnerAuthor

    M1 merged in #1029: the Analytics "Areas (DAGI)" overview of one area. The comparison across areas (M2) is still open.

  4. dborup commented on Nov 30, 2026

    @dborup
    OwnerAuthor

    Owner request (2026-11-30) for M2 (comparison across areas): show repeater density precisely enough to compare areas.

    Today the overview shows "Repeaters / 100 km²" with one decimal, e.g. Sydjylland (landsdel 218542): 83 repeaters on 8,649 km² of land = 0.96 per 100 km², shown as "1.0". Rounded like that, close areas look identical.

    For M2:

    • show the density with two decimals (0.96), or as "1 repeater per X km²" (here: one per 104 km²), or both; pick one convention and use it in the overview, the comparison table and any choropleth legend;
    • say in a tooltip how it is computed: repeaters with a position in the area (active and silent) divided by the DAGI land area in units of 100 km² (cmd/server/dagi_area_stats.go:615);
    • sort and colour the comparison on the unrounded value.
  5. added 2 commits that reference this issue on Dec 2, 2026
  6. dborup commented on Dec 2, 2026

    @dborup
    OwnerAuthor

    M2 (comparison table, #1069, 91eef300) and M3 (choropleth, #1071) are merged. Owner decision on the perf budgets: 250 ms render / 100 ms re-sort at a plain 4× CPU throttle (CI measured ~180 / ~86 ms, so the re-sort has ~14 % headroom). Open review nits: tests/e2e-phone-cpu.js has no user left, and the M2 shard note still states 150 / 50 ms.

  7. added a commit that references this issue on Dec 2, 2026
  8. dborup commented on Dec 2, 2026

    @dborup
    OwnerAuthor

    Owner decision (2026-12-02) on the density columns of the Areas (DAGI) comparison:

    1. Keep "per 100 km²" for kommuner, landsdele and regioner.
    2. Count only active repeaters in repeatersPer100Km2 (not degraded or silent). The total repeater count stays, with the inactive ones shown separately.
    3. Postnumre: no density — show only the counts (most postnumre are < 20 km², so one repeater gives an extreme density). The same applies to observersPer100Km2 for postnumre.

    Follow-up PR to come (server field semantics + OpenAPI text, table/choropleth/overview UI, tests).

  9. added 2 commits that reference this issue on Dec 2, 2026
  10. dborup commented on Dec 2, 2026

    @dborup
    OwnerAuthor

    Merged: #1098 (density counts active repeaters only, none for postnumre — owner decision) and #1091 (choropleth decode + draw in about half the time, same paths; keyboard focus kept).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions