Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 40 additions & 13 deletions cmd/server/dagi_area_comparison_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,19 @@ func TestDagiAreaComparisonPostnummerGroups(t *testing.T) {
if rowByCode(rows, "1051") != nil || rowByCode(rows, "1801") != nil {
t.Error("a street-postcode member is its own row")
}
if g := rowByCode(rows, "1050"); g == nil || g.Nodes != 1 || g.RepeatersPer100Km2 == nil {
t.Errorf("1050 group %+v, want Kbh K counted, with a density", g)
// No density for postnumre (owner, 2026-12-02), the groups included.
if g := rowByCode(rows, "1050"); g == nil || g.Nodes != 1 || g.Repeaters != 1 || g.RepeatersPer100Km2 != nil || g.ObserversPer100Km2 != nil {
t.Errorf("1050 group %+v, want Kbh K counted, with no density", g)
}
}

// Christiansø is a row with no density (nil, "—" in the UI); every other
// area has one, postnumre included (#1032: their areaM2 is land).
// Density (owner, 2026-12-02): kommuner, landsdele and regioner have
// repeaters per 100 km² over the active repeaters only, and observers per
// 100 km²; Christiansø has none (nil, "—" in the UI); postnumre have none
// at all, the street-postcode groups included, though their counts stay.
func TestDagiAreaComparisonDensity(t *testing.T) {
w := newWorld1002(t, cfg1002())
for _, layer := range []string{"kommune", "landsdel", "region", "postnummer"} {
for _, layer := range []string{"kommune", "landsdel", "region"} {
for _, r := range w.comparison(layer).Rows {
if r.OutsideKommune {
continue
Expand All @@ -119,26 +122,50 @@ func TestDagiAreaComparisonDensity(t *testing.T) {
t.Errorf("%s %s: density nil", layer, r.Code)
continue
}
if want := float64(r.Repeaters) / (r.AreaKm2 / 100); math.Abs(*r.RepeatersPer100Km2-want) > 1e-9 {
t.Errorf("%s %s: repeaters/100 km² %v, want %v (unrounded)", layer, r.Code, *r.RepeatersPer100Km2, want)
if r.ActiveRepeaters > r.Repeaters || r.ActiveRepeaters < 0 {
t.Errorf("%s %s: %d active of %d repeaters", layer, r.Code, r.ActiveRepeaters, r.Repeaters)
}
if want := float64(r.ActiveRepeaters) / (r.AreaKm2 / 100); math.Abs(*r.RepeatersPer100Km2-want) > 1e-9 {
t.Errorf("%s %s: repeaters/100 km² %v, want %v (active only, unrounded)", layer, r.Code, *r.RepeatersPer100Km2, want)
}
if want := float64(r.Observers) / (r.AreaKm2 / 100); math.Abs(*r.ObserversPer100Km2-want) > 1e-9 {
t.Errorf("%s %s: observers/100 km² %v, want %v", layer, r.Code, *r.ObserversPer100Km2, want)
}
}
}
counted := 0
for _, r := range w.comparison("postnummer").Rows {
if r.RepeatersPer100Km2 != nil || r.ObserversPer100Km2 != nil {
t.Errorf("postnummer %s (group %v): density %v / %v, want none", r.Code, r.Group, r.RepeatersPer100Km2, r.ObserversPer100Km2)
}
counted += r.Repeaters
if r.ActiveRepeaters > r.Repeaters {
t.Errorf("postnummer %s: %d active of %d repeaters", r.Code, r.ActiveRepeaters, r.Repeaters)
}
}
if counted == 0 {
t.Error("postnumre count no repeater: the counts must stay")
}
chr := rowByCode(w.comparison("kommune").Rows, "0411")
if chr == nil || !chr.OutsideKommune || chr.Nodes != 1 || chr.RepeatersPer100Km2 != nil || chr.ObserversPer100Km2 != nil {
if chr == nil || !chr.OutsideKommune || chr.Nodes != 1 || chr.Repeaters != 1 || chr.ActiveRepeaters != 1 || chr.RepeatersPer100Km2 != nil || chr.ObserversPer100Km2 != nil {
t.Errorf("Christiansø %+v", chr)
}
body := w.get("/api/analytics/dagi-areas?layer=kommune").Body.String()
i := strings.Index(body, `"code":"0411"`)
if i < 0 || !strings.Contains(body[i:i+800], `"repeatersPer100Km2":null`) || !strings.Contains(body[i:i+800], `"observersPer100Km2":null`) {
t.Errorf("Christiansø densities are not null in the body")
for _, layer := range []string{"kommune", "postnummer"} {
body := w.get("/api/analytics/dagi-areas?layer=" + layer).Body.String()
if strings.Contains(body, `"repeatersPer100Km2":0`) && layer == "postnummer" {
t.Errorf("postnummer body has a zero density, want null")
}
code := map[string]string{"kommune": `"code":"0411"`, "postnummer": `"code":"8200"`}[layer]
i := strings.Index(body, code)
if i < 0 || !strings.Contains(body[i:i+800], `"repeatersPer100Km2":null`) || !strings.Contains(body[i:i+800], `"observersPer100Km2":null`) {
t.Errorf("%s %s: densities are not null in the body", layer, code)
}
if !strings.Contains(body[i:i+800], `"activeRepeaters":`) {
t.Errorf("%s %s: no activeRepeaters in the body", layer, code)
}
}
}

// The gap flags, from a row's numbers (research §2 "Coverage gaps").
func TestDagiAreaGaps(t *testing.T) {
for _, c := range []struct {
name string
Expand Down
34 changes: 20 additions & 14 deletions cmd/server/dagi_area_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,16 @@ type DagiAreaRow struct {
OutsideKommune bool `json:"outsideKommune,omitempty"`
Group bool `json:"group,omitempty"`
// AreaKm2 is the asset's areaM2: land only, postnumre too (#1032).
AreaKm2 float64 `json:"areaKm2"`
Nodes int `json:"nodes"`
Repeaters int `json:"repeaters"`
Rooms int `json:"rooms"`
Companions int `json:"companions"`
Sensors int `json:"sensors"`
OtherRoles int `json:"otherRoles"`
AreaKm2 float64 `json:"areaKm2"`
Nodes int `json:"nodes"`
Repeaters int `json:"repeaters"`
// ActiveRepeaters is how many of Repeaters are active
// (classifyNodeHealth); the rest are degraded or silent.
ActiveRepeaters int `json:"activeRepeaters"`
Rooms int `json:"rooms"`
Companions int `json:"companions"`
Sensors int `json:"sensors"`
OtherRoles int `json:"otherRoles"`
// Active, Degraded and Silent are classifyNodeHealth's buckets.
Active int `json:"active"`
Degraded int `json:"degraded"`
Expand All @@ -188,10 +191,11 @@ type DagiAreaRow struct {
// relay-based definition Topology uses). nil: no such transmission.
AvgHopsHeard *float64 `json:"avgHopsHeard"`
AvgHopsRelayed *float64 `json:"avgHopsRelayed"`
// RepeatersPer100Km2 is every repeater with a position in the area
// (active, degraded or silent) divided by AreaKm2 in units of 100 km²,
// unrounded; ObserversPer100Km2 the same for Observers (#1002 M2). Both
// nil for Christiansø (outside the kommune division, 0.35 km²).
// RepeatersPer100Km2 is the active repeaters with a position in the
// area (ActiveRepeaters: not degraded or silent) divided by AreaKm2 in
// units of 100 km², unrounded; ObserversPer100Km2 the same for
// Observers (#1002 M2; owner, 2026-12-02). Both nil for Christiansø
// (outside the kommune division, 0.35 km²) and for every postnummer.
RepeatersPer100Km2 *float64 `json:"repeatersPer100Km2"`
ObserversPer100Km2 *float64 `json:"observersPer100Km2"`
// Gaps flags missing coverage (#1002 M2, dagiAreaGaps): "no-nodes",
Expand Down Expand Up @@ -631,7 +635,7 @@ func (st *dagiAreaStats) row(si int32) DagiAreaRow {
sl := &st.table.slots[si]
c := &st.rows[si]
r := DagiAreaRow{Code: sl.key, Name: sl.name, OutsideKommune: sl.outsideKommune, Group: sl.grouped,
AreaKm2: sl.areaM2 / 1e6, Nodes: c.nodes, Repeaters: c.repeaters, Rooms: c.rooms, Companions: c.companions,
AreaKm2: sl.areaM2 / 1e6, Nodes: c.nodes, Repeaters: c.repeaters, ActiveRepeaters: c.activeRepeaters, Rooms: c.rooms, Companions: c.companions,
Sensors: c.sensors, OtherRoles: c.otherRoles, Active: c.active, Degraded: c.degraded, Silent: c.silent,
New7d: c.new7d, Observers: c.observers, Heard: c.heard, Relayed: c.relayed}
if c.heardHopN > 0 {
Expand All @@ -642,9 +646,11 @@ func (st *dagiAreaStats) row(si int32) DagiAreaRow {
v := float64(c.relayedHopSum) / float64(c.relayedHopN)
r.AvgHopsRelayed = &v
}
if !sl.outsideKommune && sl.areaM2 > 0 {
// No density for postnumre (owner, 2026-12-02): most are < 20 km², so
// one repeater gives an extreme value. Their counts stay.
if sl.layer != DagiPostnummer && !sl.outsideKommune && sl.areaM2 > 0 {
per100 := sl.areaM2 / 1e8 // m² → units of 100 km²
rep, obs := float64(c.repeaters)/per100, float64(c.observers)/per100
rep, obs := float64(c.activeRepeaters)/per100, float64(c.observers)/per100
r.RepeatersPer100Km2, r.ObserversPer100Km2 = &rep, &obs
}
r.Gaps = dagiAreaGaps(c)
Expand Down
13 changes: 11 additions & 2 deletions cmd/server/dagi_area_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,17 @@ func TestDagiAreaNodeCounts(t *testing.T) {
if ov.Region == nil || ov.Region.Code != "1082" {
t.Errorf("Aarhus region %+v, want 1082", ov.Region)
}
if r.AreaKm2 < 400 || r.AreaKm2 > 550 || r.RepeatersPer100Km2 == nil || math.Abs(*r.RepeatersPer100Km2-5/(r.AreaKm2/100)) > 1e-9 {
t.Errorf("Aarhus area %v km², density %v", r.AreaKm2, r.RepeatersPer100Km2)
// Density counts the active repeaters only (owner, 2026-12-02): Aarhus
// stale is degraded, so 4 of the 5; the row keeps the 5.
if r.ActiveRepeaters != 4 {
t.Errorf("Aarhus active repeaters %d, want 4 (stale is degraded)", r.ActiveRepeaters)
}
if r.AreaKm2 < 400 || r.AreaKm2 > 550 || r.RepeatersPer100Km2 == nil || math.Abs(*r.RepeatersPer100Km2-4/(r.AreaKm2/100)) > 1e-9 {
t.Errorf("Aarhus area %v km², density %v, want 4 active / area", r.AreaKm2, r.RepeatersPer100Km2)
}
// A postnummer has counts and no density, the overview too.
if p := w.overview("postnr=8200").Row; p.Repeaters != 1 || p.ActiveRepeaters != 1 || p.RepeatersPer100Km2 != nil || p.ObserversPer100Km2 != nil {
t.Errorf("8200 %+v, want 1 repeater, 1 active, no density", p)
}
// Midtjylland: Aarhus 7 and Hvide Sande (Ringkøbing-Skjern); the node at
// sea is in no kommune and so in no region.
Expand Down
4 changes: 2 additions & 2 deletions cmd/server/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func routeDescriptions() map[string]routeMeta {
{Status: "404", Description: "An unknown code, or DAGI is off (dagi.enabled false)."},
}},

"GET /api/analytics/dagi-area": {Summary: "Overview of one DAGI area (kommune, landsdel, region, postnummer)", Description: "#1002 M1: the Areas (DAGI) tab's numbers for one area, from one background pass over every area per analytics cycle (no per-request compute). {layer, param, generatedAt, windowFrom, windowTo, partialWindow, coveredHours, credit, region? (a kommune's region), row: {code, name, outsideKommune?, group?, areaKm2, nodes, repeaters, rooms, companions, sensors, otherRoles, active, degraded, silent, new7d, observers, heard, relayed, avgHopsHeard, avgHopsRelayed, repeatersPer100Km2, observersPer100Km2, gaps?}, heardPerHour[24], relayedPerHour[24], busiestRepeaters: [{publicKey, name, relayed}] (at most 5), totals: {nodes, unpositioned, outsideDenmark}}. Nodes count by their own position through the DAGI filter's membership, so row.nodes equals /api/nodes' total for the same param. Traffic covers the last 24 h: heard counts a transmission once per area with an observation by an observer whose node is in the area; relayed once per area with a resolved relay hop on a node in the area. Hidden identities (nodeBlacklist, hiddenNamePrefixes, and for observers and relays also the observer blacklist) are left out of every count and list; a blacklist or hidden-prefix change is never served from an older pass. region, area and window do not apply. areaKm2 is the land area (postnumre are clipped to the coast, #1032). repeatersPer100Km2 and observersPer100Km2 are unrounded and null for Christiansø; gaps as in GET /api/analytics/dagi-areas.", Tag: "analytics",
"GET /api/analytics/dagi-area": {Summary: "Overview of one DAGI area (kommune, landsdel, region, postnummer)", Description: "#1002 M1: the Areas (DAGI) tab's numbers for one area, from one background pass over every area per analytics cycle (no per-request compute). {layer, param, generatedAt, windowFrom, windowTo, partialWindow, coveredHours, credit, region? (a kommune's region), row: {code, name, outsideKommune?, group?, areaKm2, nodes, repeaters, activeRepeaters, rooms, companions, sensors, otherRoles, active, degraded, silent, new7d, observers, heard, relayed, avgHopsHeard, avgHopsRelayed, repeatersPer100Km2, observersPer100Km2, gaps?}, heardPerHour[24], relayedPerHour[24], busiestRepeaters: [{publicKey, name, relayed}] (at most 5), totals: {nodes, unpositioned, outsideDenmark}}. Nodes count by their own position through the DAGI filter's membership, so row.nodes equals /api/nodes' total for the same param. Traffic covers the last 24 h: heard counts a transmission once per area with an observation by an observer whose node is in the area; relayed once per area with a resolved relay hop on a node in the area. Hidden identities (nodeBlacklist, hiddenNamePrefixes, and for observers and relays also the observer blacklist) are left out of every count and list; a blacklist or hidden-prefix change is never served from an older pass. region, area and window do not apply. areaKm2 is the land area (postnumre are clipped to the coast, #1032). activeRepeaters is how many of repeaters are active (the rest are degraded or silent). repeatersPer100Km2 (active repeaters only) and observersPer100Km2 are unrounded and null for Christiansø and for every postnummer; gaps as in GET /api/analytics/dagi-areas.", Tag: "analytics",
QueryParams: []paramMeta{
{Name: "kommune", Description: "A kommunekode, e.g. 0751. Exactly one of kommune, landsdel, dkregion and postnr.", Type: "string"},
{Name: "landsdel", Description: "A landsdel id_lokalid.", Type: "string"},
Expand All @@ -91,7 +91,7 @@ func routeDescriptions() map[string]routeMeta {
{Status: "400", Description: "None or more than one DAGI param, or an unknown code (unknown kommune, ...)."},
{Status: "404", Description: "DAGI is off (dagi.enabled false, or the asset does not load)."},
}},
"GET /api/analytics/dagi-areas": {Summary: "Comparison of every DAGI area of one layer", Description: "#1002 M2: the Areas (DAGI) tab's comparison table, from the same background pass as GET /api/analytics/dagi-area (no per-request compute). {layer, param, generatedAt, windowFrom, windowTo, partialWindow, coveredHours, credit, totals: {nodes, unpositioned, outsideDenmark}, rows: [row]}, where row is dagi-area's row: {code, name, outsideKommune?, group?, areaKm2, nodes, repeaters, rooms, companions, sensors, otherRoles, active, degraded, silent, new7d, observers, heard, relayed, avgHopsHeard, avgHopsRelayed, repeatersPer100Km2, observersPer100Km2, gaps?}. Every area of the layer is a row, the empty ones too (kommune 99, landsdel 11, region 5, postnummer 605 with the three street-postcode groups as one row each, keyed by the group key), in /api/config/dagi's order (by code). repeatersPer100Km2 is every repeater with a position in the area (active, degraded or silent) divided by areaKm2 (DAGI land area) in units of 100 km², unrounded; observersPer100Km2 the same for observers; both null for Christiansø. gaps lists no-nodes, no-repeater (nodes, none a repeater), no-observer (repeaters, but no observer in the area heard anything in 24 h) and nothing-heard (nodes, but nothing heard or relayed in the area in 24 h); absent when none. Hidden identities are left out as in dagi-area. A DAGI selection, region, area and window do not apply.", Tag: "analytics",
"GET /api/analytics/dagi-areas": {Summary: "Comparison of every DAGI area of one layer", Description: "#1002 M2: the Areas (DAGI) tab's comparison table, from the same background pass as GET /api/analytics/dagi-area (no per-request compute). {layer, param, generatedAt, windowFrom, windowTo, partialWindow, coveredHours, credit, totals: {nodes, unpositioned, outsideDenmark}, rows: [row]}, where row is dagi-area's row: {code, name, outsideKommune?, group?, areaKm2, nodes, repeaters, activeRepeaters, rooms, companions, sensors, otherRoles, active, degraded, silent, new7d, observers, heard, relayed, avgHopsHeard, avgHopsRelayed, repeatersPer100Km2, observersPer100Km2, gaps?}. Every area of the layer is a row, the empty ones too (kommune 99, landsdel 11, region 5, postnummer 605 with the three street-postcode groups as one row each, keyed by the group key), in /api/config/dagi's order (by code). activeRepeaters is how many of repeaters are active (the rest are degraded or silent). repeatersPer100Km2 is the active repeaters with a position in the area (not degraded or silent) divided by areaKm2 (DAGI land area) in units of 100 km², unrounded; observersPer100Km2 the same for observers; both null for Christiansø and for every postnummer row, the street-postcode groups included (most postnumre are under 20 km², so one repeater would give an extreme value); the counts stay. gaps lists no-nodes, no-repeater (nodes, none a repeater), no-observer (repeaters, but no observer in the area heard anything in 24 h) and nothing-heard (nodes, but nothing heard or relayed in the area in 24 h); absent when none. Hidden identities are left out as in dagi-area. A DAGI selection, region, area and window do not apply.", Tag: "analytics",
QueryParams: []paramMeta{
{Name: "layer", Description: "The layer to compare.", Type: "string", Required: true, Enum: []string{"kommune", "landsdel", "region", "postnummer"}},
},
Expand Down
Loading
Loading