Skip to content

Commit

Permalink
preserve site.code order in sensor data, for predictable TZ
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanbeaudette committed Sep 18, 2024
1 parent 56847d3 commit 7822889
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 1 addition & 3 deletions R/fetchSCAN.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,9 @@ fetchSCAN <- function(site.code = NULL, year = NULL, report = 'SCAN', timeseries
res <- list()

# add metadata from cached table in soilDB
# note row-order may not match ordering in site.code
m <- SCAN_site_metadata(site.code)

# why do this?
site.code <- m$Site

# all possible combinations of site codes and year | single report and timeseries type
g <- expand.grid(s = site.code, y = year, r = report, dt = timeseries)

Expand Down
19 changes: 17 additions & 2 deletions tests/testthat/test-fetchSCAN.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ test_that("fetchSCAN() works", {
# completely empty request for valid site (bogus year)
y <<- fetchSCAN(site.code = 2072, year = 1800)

# multiple sites / years
z <<- fetchSCAN(site.code = c(356, 2072), year = c(2015, 2016))
# multiple sites / years / time zones (GMT-8, GMT-5)
z <<- fetchSCAN(site.code = c(2218, 2005), year = c(2015, 2016))

})

Expand Down Expand Up @@ -53,3 +53,18 @@ test_that("fetchSCAN() returns the right kind of data", {
expect_true(inherits(y$SMS, 'data.frame'))
expect_true(ncol(y$SMS) == 9)
})

test_that("timezone check", {

skip_if_offline()

skip_on_cran()

# skip on error
# skip on error
skip_if(inherits(x, 'try-error') || is.null(x))

# should be GMT-8, that of the first station (2218)
.tz <- table(format(z$SMS$datetime, format = '%Z'))
expect_true(names(.tz) == '-08')
})

0 comments on commit 7822889

Please sign in to comment.