Skip to content

Commit

Permalink
Merge pull request #497 from mrc-ide/mrc-5074
Browse files Browse the repository at this point in the history
mrc-5074: Handle geojson data where display property is missing
  • Loading branch information
r-ash authored Apr 5, 2024
2 parents 3188e07 + e9d4439 commit 6fd4008
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 2 deletions.
3 changes: 2 additions & 1 deletion R/filters.R
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,10 @@ get_year_filters <- function(data) {

get_level_labels <- function(json) {
labels <- lapply(json$features, function(feature) {
display <- feature$properties$display %||% TRUE
list(id = scalar(feature$properties$area_level),
area_level_label = scalar(feature$properties$area_level_label),
display = scalar(as.logical(feature$properties$display)))
display = scalar(as.logical(display)))
})
unique(labels)
}
Expand Down
2 changes: 1 addition & 1 deletion R/validate_inputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ do_validate_shape <- function(shape) {
json <- hintr_geojson_read(shape)
assert_single_parent_region(json)
assert_single_country(json, "shape")
assert_properties_exist(json, "area_id")
assert_properties_exist(json, c("area_id", "area_level_label", "area_level"))
## TODO: Add region code validation see mrc-1305
# Then we have to *reread* the file now that we know that it is
# valid, but but this is not too slow, especially as the file is now
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-validate-inputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ test_that("do_validate_shape validates shape and returns geojson as list", {
expect_equal(json$filters$regions$children[[3]]$label, scalar("Southern"))
})

test_that("do_validate_shape returns if display property is missing", {
shape <- file_object(file.path("testdata", "malawi_missing_display.geojson"))
json <- do_validate_shape(shape)
expect_s3_class(json$data, "json")
expect_equal(json$filters$level_labels[[1]]$display, scalar(TRUE))
})

test_that("do_validate_population validates population file", {
population <- file_object(file.path("testdata", "population.csv"))
pop <- do_validate_population(population)
Expand Down
76 changes: 76 additions & 0 deletions tests/testthat/testdata/malawi_missing_display.geojson

Large diffs are not rendered by default.

0 comments on commit 6fd4008

Please sign in to comment.