feat(stats): filter scope counts by IATA and region - #142
Open
n30nex wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
/stats/scopes?iata=YVRcurrently returns global totals. Addiatas/iata,regionIdandregionfiltering through the handler, Reader, Store, SQL and cache. Aggregate matching observations once for distinct packet/observer counts in each transport scope, separately from node IATA memberships, so overlapping regions do not inflate counts. Unfiltered totals and scope ordering remain unchanged.Closes #95. A known empty region returns
[], unknown/invalid regions return 400, and scopes with zero matching counts remain listed. The existing web chart explicitly requests global totals; connecting its region selector is a separate client follow-up.Type of change
Checklist
go build ./...passesgofmt -l .is emptygo vet ./...passesgo test ./...passesdocs/updatedTesting notes
The original endpoint fails the new invalid-region regression (200 instead of 400). Handler tests cover aliases, normalization, region ID/slug precedence, unions, empty regions and errors. Cache tests prove isolation and reuse across reordered/duplicate IATAs without mutating the caller's slice.
Native Pi PostgreSQL tests cover shared packets, several observers, cross-scope traffic, overlapping node memberships, global/empty filters and an empty roster. Local build/vet/tests and focused race checks pass. Both standalone and combined builds pass the full native Go suite with PostgreSQL enabled. GitHub Actions CI and CodeQL pass.
On a private Pi fixture with 20,000 packets, 80,000 observations and 20,000 nodes, final custom-plan queries took 0.2–25 ms; forced generic-plan queries took 22–55 ms. Unfiltered custom-plan execution was 16.6 ms versus 17.0 ms for the original query. These are synthetic measurements, not production timing claims.
The Canadaverse preview runs combined server
2a1db146with the four previous server candidates and unchanged webb85bc19a. Source & changes offers matching source. Public parameter/error checks and both live feeds pass. The live preview has no configured transport scopes or regions, so positive filtered counts and region expansion are validated with isolated PostgreSQL fixtures and handler tests rather than claimed from live data.AI assistance was used for implementation and verification under the author's ongoing contribution workflow.