-
Notifications
You must be signed in to change notification settings - Fork 0
local implementation #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bmaitner
wants to merge
8
commits into
master
Choose a base branch
from
local-implementation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0479b92
local implementation
bmaitner 88c5d0c
Address PR review: packaging, resolver bugs, and the WCVP source name
bmaitner 6f30047
Second review pass: link guard, GADM hierarchy, and build error handling
bmaitner 8dd0562
Decide extinct records at query time, not at build time
bmaitner 73a4ace
Answer from division names by default; compare coordinates, never poo…
bmaitner 531b872
addressing copilot stuff
bmaitner 54b791c
Third review pass: R 4.0 guard, cache schema, and four row/set diverg…
bmaitner 5cebff5
Decline the service's higher-rank rule, and say why
bmaitner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| # =========================================================================== | ||
| # Divisions that belong to another division system | ||
| # | ||
| # A large part of the record stream declares a state that is not a GADM division: | ||
| # Swedish landskap and lappmarker, Watsonian vice-counties, Norwegian counties from | ||
| # after the 2018 and 2020 reforms. GNRS records these as units in their own right | ||
| # and, where it knows which GADM units they cover, writes that extent to the shared | ||
| # cache (altdiv-*). NSR reads those tables the same way it reads the GNRS reference: | ||
| # straight from the cache, without depending on the package. | ||
| # | ||
| # Only a unit whose extent is known is of any use here: it turns a declared name | ||
| # that matched nothing into the set of divisions the question is really about, so | ||
| # native status can be answered below country level. A unit with no extent yet adds | ||
| # no regions, which leaves the query where it was - answered at country level. | ||
| # =========================================================================== | ||
|
|
||
| #' The alternative divisions whose extent is known, keyed by country and name | ||
| #' | ||
| #' Internal. NULL when the component has not been built. Cached per directory | ||
| #' for the session, like the other reference tables. | ||
| #' @keywords internal | ||
| #' @noRd | ||
| nsr_altdiv <- function(dir) { | ||
| key <- paste0("altdiv:", dir) | ||
| if (!is.null(nsr_session[[key]])) return(nsr_session[[key]]) | ||
| f <- function(x) file.path(dir, paste0("altdiv-", x, ".gz.parquet")) | ||
| if (!all(file.exists(f(c("units", "names", "extent"))))) return(NULL) | ||
| units <- as.data.frame(nanoparquet::read_parquet(f("units"))) | ||
| names_ <- as.data.frame(nanoparquet::read_parquet(f("names"))) | ||
| extent <- as.data.frame(nanoparquet::read_parquet(f("extent"))) | ||
| # only exact names, and only units that have an extent: a regex system (the | ||
| # vice-counties) has none yet, and a unit without one adds no regions | ||
| names_ <- names_[names_$match == "exact" & names_$entity_key %in% extent$entity_key, , drop = FALSE] | ||
| iso <- units$country_iso[match(names_$entity_key, units$entity_key)] | ||
| out <- list( | ||
| key = paste(toupper(iso), tolower(trimws(names_$name)), sep = "\u001f"), | ||
| entity = names_$entity_key, | ||
| extent = split(extent$gid, extent$entity_key), | ||
| level = vapply(split(extent$level, extent$entity_key), function(x) as.integer(x[1]), integer(1)) | ||
| ) | ||
| nsr_session[[key]] <- out | ||
| out | ||
| } | ||
|
|
||
| #' Region keys for a declared division that belongs to another system | ||
| #' | ||
| #' Internal. Vectorised over rows; returns a list of character vectors, empty | ||
| #' where the declared name is not such a division or its extent is unknown. | ||
| #' @keywords internal | ||
| #' @noRd | ||
| nsr_altdiv_keys <- function(country_iso, name, dir) { | ||
| n <- length(name) | ||
| out <- vector("list", n) | ||
| for (i in seq_len(n)) out[[i]] <- character(0) | ||
| a <- nsr_altdiv(dir) | ||
| if (is.null(a)) return(out) | ||
| nm <- tolower(trimws(ifelse(is.na(name), "", name))) | ||
| cc <- toupper(ifelse(is.na(country_iso), "", country_iso)) | ||
| hit <- match(paste(cc, nm, sep = "\u001f"), a$key) | ||
| for (i in which(!is.na(hit))) { | ||
| k <- a$entity[hit[i]] | ||
| gid <- a$extent[[k]] | ||
| # NSR's regions are countries and states; a county-level extent has nothing to map | ||
| # onto yet, so it is skipped rather than answered at the wrong level | ||
| if (!length(gid) || a$level[[k]] != 1L) next | ||
| out[[i]] <- paste0("gadm1:", gid) | ||
| } | ||
| out | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.