Skip to content

fix(analytics): density counts active repeaters only, none for postnumre (#1002) - #1098

Merged
dborup merged 1 commit into
masterfrom
fix/1002-density-active-only
Dec 2, 2026
Merged

dborup merged 1 commit into
masterfrom
fix/1002-density-active-only

Conversation

@dborup

@dborup dborup commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Relates to #1002

Follow-up to the owner decision of 2026-12-02 on the density columns of the Areas (DAGI) comparison.

Plan

  1. Server: repeatersPer100Km2 counts only active repeaters, using activeRepeaters, which the same background pass already counts for the area card. The pass and its cost are unchanged. Rows gain activeRepeaters. Both densities are null for every postnummer row, the street-postcode groups included. Kommuner, landsdele and regioner keep per 100 km². Christiansø still has no density.

  2. UI: the Repeaters cell shows the total with the inactive ones, e.g. 12 (3 inactive). Sorting still uses the total. On the postnummer layer:

    • the density column is hidden by one data-layer attribute plus a CSS rule, so there is no per-row work;
    • the phone sort select does not offer density;
    • the map colours by the repeater count;
    • a sort=repeatersPer100Km2 link falls back to Repeaters;
    • the overview has no density card;
    • the note says why.

    The tooltips say "active repeaters".

  3. Docs: the OpenAPI text for GET /api/analytics/dagi-area(s) and docs/user-guide/area-filter.md are updated. docs/api-spec.md does not describe these fields.

Choices

  • Fallback for a postnummer density sort: Repeaters. It is the closest count and keeps the user's intent. A link that asks for the density sort is shown sorted by Repeaters, and the hash is left alone: the tab never rewrites a link's params. A layer switch by the user writes sort=repeaters.
  • "Inactive" means degraded + silent (classifyNodeHealth), the same buckets as the Quiet card.
  • The column is hidden with CSS instead of being removed from the DOM. The row cells stay index-aligned (fillRow), and switching layers costs one attribute write.

Tests

  • Go: TestDagiAreaComparisonDensity (rewritten) checks:

    • active-only density on kommune, landsdel and region;
    • null for all 605 postnummer rows, the groups included, while the counts stay;
    • Christiansø unchanged;
    • null and activeRepeaters in the JSON body.

    TestDagiAreaNodeCounts checks Aarhus: 4 of 5 repeaters active, so the density is 4/area, and postnummer 8200 has no density. TestDagiAreaComparisonPostnummerGroups checks that the 1050 group has no density.

  • UI unit tests (test-analytics-dagi-areas-compare.js, -map.js): the inactive cell and card, no density card for a postnummer, the column, option and note for the postnummer layer, the sort fallback, the map metric, the CSS rule, and the URL round-trip.

  • New E2E test-issue-1002-density-e2e.js (shard 2): the real API shape, then 1440×900 and 375×560 with real taps.

  • M2 E2E: the tooltip text is updated. The perf step now re-sorts postnumre by Repeaters, because density no longer exists there. It is the same numeric re-sort over the same 605 rows, against the same budgets.

Perf

  • Server: the same background pass. Only row() reads a different counter that already exists, plus one layer compare.
  • Frontend: M2 perf step, 375×560 at 4× CPU throttle, best of 3, same server and fixture:
render to frame re-sort to frame
master 64.9 ms 26.6 ms
this PR 63.4 ms 26.1 ms

🤖 Generated with Claude Code

…mre (#1002)

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

- repeatersPer100Km2 counts only active repeaters (classifyNodeHealth);
  rows gain activeRepeaters (already counted in the same pass), and the
  UI shows the total with the inactive ones: "12 (3 inactive)".
- Postnumre have no density: repeatersPer100Km2 and observersPer100Km2
  are null for every postnummer row, the street-postcode groups too. The
  table hides the density column for that layer, the sort select and the
  map do not offer it (a density sort falls back to Repeaters), the
  overview drops the density card, and the note says why.
- Kommuner, landsdele and regioner keep per 100 km²; Christiansø keeps
  no density.

OpenAPI text and the user guide follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dborup

dborup commented Dec 2, 2026

Copy link
Copy Markdown
Owner Author

Rapport — CS-Minimax PR#1098 #1002 — head 33ed10b

Status: Done locally, all green. Every point has a red→green test and killed mutants. CI has not run: GitHub created no workflow run for this PR, and a manual dispatch was not allowed in this session, so CI still needs a trigger.

Evidence key: [T] test run in this session, [A] API response checked with curl or in the E2E, [K] code read.

Requirements

# Requirement Test (red before → green after) Mutant(s), all killed
1 Keep "per 100 km²" for kommune, landsdel and region; Christiansø unchanged TestDagiAreaComparisonDensity checks the kommune, landsdel and region rows; Christiansø stays null, with activeRepeaters 1 [T]. The E2E step "the real API" covers it too [A]. M4: Christiansø gets a density → TestDagiAreaComparisonDensity, TestDagiAreaSemantics [T]
2a repeatersPer100Km2 counts only active repeaters TestDagiAreaNodeCounts: Aarhus has 4 of 5 repeaters active (the stale one is degraded), so the density is 4/area. Before the fix it was 5/area, which made the test red [T]. M1: density over all repeaters; M5: activeRepeaters = total [T]
2b The row keeps the total and shows the inactive ones separately, using existing counts New field activeRepeaters, from the c.activeRepeaters that the same pass already counts [K]. Unit tests: the cell reads 22 (3 inactive) or a plain 4, sorting uses the total, the overview card says "11 inactive", and the tooltip counts active repeaters [T]. E2E at 1440×900 and 375×560: N (M inactive) fits inside 375 px on one line [T]. M6: cell has no inactive part; M7: inactive count can go negative; M15: tooltip counts all repeaters; M16: card has no inactive part [T]
3a Postnumre: both densities null, the street-postcode groups included TestDagiAreaComparisonDensity checks all 605 rows; TestDagiAreaComparisonPostnummerGroups checks the 1050 group; TestDagiAreaNodeCounts checks postnummer 8200; the body is checked for null [T]. The real API in E2E: 605 rows, 3 groups, all null [A]. M2: postnumre get a density; M3: observer density 0 instead of null [T]
3b The table hides the density columns for postnumre Unit tests check data-layer and the CSS rule. E2E at 1440×900 checks the computed display: none on the header and the cells, and that the header and rows have the same number of visible cells [T]. M17: CSS rule removed → killed in the unit test and in the E2E [T]
3c The choropleth offers no density metric for postnumre Unit tests: mapMetric(name|density, 'postnummer') = repeaters, and the legend reads "Repeaters". E2E at 375×560 with map=1 checks the legend [T]. M11: the map ignores the layer [T]
3d Sorting and notes still work Unit tests and E2E check that the density sort falls back to Repeaters (and the URL says so after a layer switch), that the Heard sort works, that the phone select hides density on postnumre and offers it again on kommuner, that the note says "Postnumre have no density", and that the overview has no density card for a postnummer [T]. M8: hasDensity always true; M9: option shown; M10: no sort fallback; M12: overview card shown; M13: header sorts by density; M14: note not switched [T]
4 OpenAPI text and docs openapi.go (both endpoints) and docs/user-guide/area-filter.md are updated. docs/api-spec.md does not describe these fields [K]. —

The mutants ran by script on a scratch snapshot, with the #1002 Go tests and the three UI unit suites: 17 of 17 killed [T].

Runs

Check Result
cd cmd/server && go test ./... ok (161 s) [T]
node test-frontend-helpers.js 746 passed, 0 failed [T]
#1002 unit suites (test-analytics-dagi-areas.js, -compare.js, -map.js) 14, 31 and 18 passed [T]
#1002 E2E (M1, M2, M3, and the new density suite) against a local Go server with e2e-fixture.db prepared as in CI 9, 6, 9 and 5 passed [T]
node scripts/run-go-server-shard.js --validate ok [T]
node scripts/run-e2e-shard.js --validate ok, 319 suites [T]
sh test-all.sh 408 passed, 0 failed [T]
scripts/check-xss-sinks.sh --diff origin/master clean; it scanned public/analytics-dagi-areas.js [T]
Invariants No new map[string]interface{} in cmd/server (0 added). cmd/server stays read-only (only response shaping changed). No hardcoded colours. Fork guards unchanged: 9 in deploy.yml, 1 in release-fast-path.yml, and .github/ is not touched [T][K]

Perf

  • Server: the same background pass. row() only reads an existing counter and compares the layer [K].
  • Frontend: M2 perf step, 375×560 at a plain 4× CPU throttle, best of 3, same server and fixture [T]:
Render to frame Re-sort to frame
master 64.9 ms 26.6 ms
This PR 63.4 ms 26.1 ms

CI per job

Not run. The API shows no workflow run for fix/1002-density-active-only more than 10 minutes after the PR was opened, although other PRs' runs started normally [A]. A manual workflow_dispatch was not permitted in this session. Pushing a new commit or triggering the workflow by hand should start it. Flaky #271 does not apply yet.

Remaining items

  • CI: still has to run (see above).
  • Changed M2 E2E: the tooltip text is updated, and the perf step re-sorts postnumre by Repeaters instead of density, because density no longer exists for them. It is the same 605-row numeric sort against the same budgets.
  • Choice: a link that asks for a postnummer density sort is shown sorted by Repeaters, and the hash is left as it is (the tab never rewrites a link's params). A layer switch by the user writes sort=repeaters.
  • Synthetic numbers: the M2 and M3 E2E fill their own numbers and do not set activeRepeaters, so their cells show N (N inactive). Those suites do not assert on it.

🤖 Generated with Claude Code

@dborup

dborup commented Dec 2, 2026

Copy link
Copy Markdown
Owner Author

Review — CS-MacBook PR#1098 — head 33ed10b

Dom: APPROVE med nits. The code is correct and does what the owner decided. One condition before merge: E2E shard 2/3 must be rerun and come back green. It is red on a perf flake that this PR does not cause, but fail-fast stopped the shard before the new density suite ran in CI.

Evidence key: [T] test or script run by me in this review, [A] API response checked against a local Go server, [K] code or log read.

Findings

# Severity Finding Evidence
1 CI (not a code defect) E2E 2/3 failed in test-issue-1002-m3-dagi-choropleth-e2e.js → perf: decode + draw … ≤ 250 ms: postnummer: 276.6 ms > 250 ms (runs 276.6, 289.2, 310.3). This is not caused by the PR. The unrelated run for fix/1065-skaermkort-smoke-and-tap (18:24, before this PR) failed the same step at 266.0 ms. Ten recent runs on other branches and master range from 145.5 to 266.0 ms. A local A/B with the identical M3 suite against master and head, 3 rounds each, measured base 109.9/112.1/109.7 ms and head 110.9/111.8/109.5 ms. The PR's only touch on that path is mapMetric(sort, layer), a string compare per draw. This flake is not one of the known ones (#256, #267), so it is worth tracking separately. Consequence: test-issue-1002-density-e2e.js comes right after M3 in shard 2, so it never ran in CI. Rerun shard 2 before merge. [K] CI logs, [T] local A/B
2 Nit The fallback sticks. On Kommune sorted by density, a tap on Postnummer moves to Repeaters and writes sort=repeaters. A tap back on Kommune stays on Repeaters, so the user's density choice is gone. The PR names this choice. I'd accept it, but keeping the requested sort in state and resolving it per layer would round-trip better. [T] phone flow
3 Nit A stale hash parameter. A deep link with layer=postnummer&sort=repeatersPer100Km2 sorts by Repeaters but keeps sort=repeatersPer100Km2 in the hash until the next user action. This is documented ("the tab never rewrites a link's params"). Harmless. [K]
4 Nit The docs example is now invented. area-filter.md changes "Sydjylland: 83 repeaters on 8,649 km²" (a real total) to "83 active repeaters on 8,649 km² is 0.96" without naming Sydjylland. As written it is a made-up example. Either say so or use a real active count. [K]
5 Info The M2 and M3 E2E fill their own numbers without activeRepeaters, so the synthetic cells read N (N inactive). They do not assert on it. Cosmetic, only in tests. [K]

No blocking code defect found.

Answers to the points

  • Server semantics [K][T][A]: in dagiAreaStats.row, repeatersPer100Km2 = activeRepeaters / (areaM2/1e8). activeRepeaters is the existing counter from the same pass, where health == "active" comes from classifyNodeHealthAt. It is the same counter area_card.go already uses for active/total. The guard is sl.layer != DagiPostnummer && !sl.outsideKommune && sl.areaM2 > 0, so both densities are nil for every postnummer slot. That includes the grouped street-postcode slots, which carry layer postnummer. Against a local server: postnummer has 605 rows with 0 non-null densities; the groups 1050, 1550 and 1800 have null; every row has activeRepeaters. Christiansø (0411, outsideKommune) has null. Kommune, landsdel and region keep per 100 km². The fixture has no Danish nodes, so I verified the numbers through the Go tests, not the API.
  • Per 100 km² kept for kommune, landsdel and region [T]: TestDagiAreaComparisonDensity loops over all three layers and checks the value equals active/area.
  • Postnummer: no density [T]:
    • API: null for both densities.
    • Table: the column is hidden by data-layer="postnummer" plus one CSS rule. The header and the rows keep the same number of visible cells.
    • Phone: the sort select hides and disables the option.
    • Choropleth: sorted by name, it colours by Repeaters. Legend: "Colour: Repeaters (quantile classes)". The class ranges are plain integers, with no "inactive" text, because metricFormat passes only the key.
    • Overview: no density card for a postnummer. The density note explains why.
  • The row keeps the total, with the inactive ones separately [T]: the cell shows 17 (2 inactive) and sorting uses the total. The overview's Repeaters card has the subline "N inactive". The tooltip reads "N active repeaters ÷ … (M inactive not counted)".
  • OpenAPI and docs [K]: both endpoint descriptions list activeRepeaters and the new semantics, including the groups and Christiansø. area-filter.md is updated (nit 4).
  • Street-postcode groups and Christiansø [T][A]: TestDagiAreaComparisonPostnummerGroups checks that 1050 has no density and keeps its counts, and the API confirms it. Christiansø is unchanged: null, the last in a density sort, and grey on the map.
  • No extra pass, perf unchanged [K][T]:
    • Server: row() reads an existing counter and does one layer compare. No new loop, no new pass.
    • Frontend: one attribute write per markHeaders, and no per-row work.
    • CI M2 perf (shard 3): 605 rows render in 120.5 ms and re-sort in 41.7 ms to the frame, against the 250 / 100 ms budgets. The M3 locally: master and head are equal (finding 1).
  • No behaviour change beyond the goal [K]: the diff touches only the DAGI row, its OpenAPI text, analytics-dagi-areas.js, one CSS rule, the docs and the tests. Sort, keys, the URL and the map for the other layers are unchanged. The M2 E2E edits are the tooltip text and the postnummer re-sort key (Repeaters instead of density), the same 605-row numeric sort.
  • Invariants [T][K]:

Phone user flow (cold start, real taps) [T]

375×560 and 360×640, touch, both from the cold home page /:

  1. More → Analytics → Areas (DAGI).
  2. Kommune list (99 rows). Sort select → Repeaters: cells read 17 (2 inactive).
  3. Sort → density, then tap Postnummer. 605 rows. The select has no density option and shows Repeaters. The URL reads sort=repeaters. The note says postnumre have no density. Nothing scrolls sideways.
  4. Tap Show map. Legend: "Colour: Repeaters". Tap a visible postnummer on the map (6880 Tarm at 375, 4200 Slagelse at 360). The overview follows, the Repeaters card reads "3 inactive", and there is no density card.
  5. Tap Kommune. The density option is back. Select density: the legend reads "Repeaters / 100 km²".
  6. Tap a row. The kommune overview has its density card (10.53).

No console errors. No step was impossible.

One note: when a control is scrolled to the bottom edge of the viewport, the fixed bottom nav covers it, so a tap lands on the nav. That is pre-existing layout and has nothing to do with this PR. A user scrolls the control into view first.

The numbers in this flow are synthetic, routed in the server's shape as the PR's E2E does, because the fixture has no Danish nodes. Desktop at 1440×900 (PR suite screenshot): the postnummer table has no density column, the cells read 8 (1 inactive), and the Heard sort works.

Tests (head = merged tree)

Head 33ed10ba is directly on origin/master b7db1738, so git merge-tree --write-tree yields head's own tree a7f936d6.

Check Result
cd cmd/server && go test ./... ok (142 s) [T]
node test-frontend-helpers.js 746 passed, 0 failed [T]
test-analytics-dagi-areas.js / -compare.js / -map.js 14 / 31 / 18 passed [T]
E2E against a local Go server with e2e-fixture.db prepared as in CI (freshen, seed SQL, corescope-migrate, seeds 2073, 199, 245 and 122): density / M1 / M2 / M3 5 / 9 / 6 / 9 passed [T]
node scripts/run-e2e-shard.js --validate ok, 319 suites [T]
node scripts/run-go-server-shard.js --validate ok [T]
sh test-all.sh (in a real git checkout of head) 408 passed, 0 failed [T]. In a git archive copy, the 628 and 715 suites fail only because they need .git.
scripts/check-xss-sinks.sh --diff origin/master exit 0 [T]

Red before, green after [T]. The PR's tests, run against master's code:

  • Go: the build fails on the new ActiveRepeaters field. Semantically, mutants R1 and R2 below show red.
  • -compare.js: 9 failed.
  • -map.js: 1 failed.
  • test-issue-1002-density-e2e.js against a master server: 4 of 5 failed. They cover the real-API nulls, the inactive cell and the hidden column, the phone density option, and the map legend.

All acceptance criteria are covered: active-only density, per 100 km² kept, postnummer nulls (groups included), no column/option/map metric/card, and the total with the inactive ones separately.

My own mutants: 13 of 13 killed [T]

Mutant Killed by
R1: density over all repeaters TestDagiAreaComparisonDensity, TestDagiAreaNodeCounts
R2: postnummer guard removed …PostnummerGroups, …Density, …NodeCounts
R3: only the repeater density nulled; observer density kept for postnumre the same three
R4: the activeRepeaters field not set …Density, …NodeCounts
F1: hasDensity always true compare: overview density card
F2: sortBy guard removed compare: postnummer layer
F3: parseView without fallback compare: URL round-trip
F4: cmp.show without fallback compare: postnummer layer
F5: no data-layer attribute compare: postnummer layer
F6: tooltip counts all repeaters compare: density tooltip
F7: a missing activeRepeaters treated as 0 active test-analytics-dagi-areas.js: card numbers
C1: the CSS rule removed (served by a mutant server) density E2E, 1440×900
C2: the cell without "(M inactive)" density E2E, 1440×900 and 375×560

The tree was restored afterwards, and the density E2E is green again (5/5).

CI per job (run 46946573390, pull_request, head 33ed10b) [K]

Result Jobs
Success Go Build & Test, Go Server 1/3 to 3/3, Go Ingestor, Go Libraries & CLI, JS Unit & Lint, Script & Container Unit Checks, Verify Go Test Assignments, Validate Docker Image, E2E 1/3, E2E 3/3 (M1 and M2 pass, M2 perf in budget)
Failure E2E 2/3: the M3 postnummer perf flake, finding 1
Failure, follow-on Verify E2E Shards & Coverage, Build & Publish Docker Image: both only require every E2E shard to succeed
Skipped Release Artifacts, Publish Badges, Deploy Staging

The workflow started late, at 19:02Z, about an hour after the PR was opened, probably because of the GitHub Actions delays. Neither known flaky test (#256, #267) is involved.

Not verified

  • The density E2E in CI: it never ran (finding 1). Locally it is 5/5.
  • Real Danish data: the fixture has no Danish nodes, so the API check was shape and nulls only. The numbers come from the Go tests and from synthetic UI data.
  • Perf under CI: the M3 flake is judged from CI history plus a local A/B, not from a CI rerun.
  • Real devices: no real iOS or Safari device. I used Chromium with touch emulation only.
  • Staging and prod: not checked (out of scope).

🤖 Generated with Claude Code

@dborup
dborup marked this pull request as ready for review December 2, 2026 20:51
@dborup
dborup merged commit 32c33cd into master Dec 2, 2026
33 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant