From 857b36dbc95ba78bdc2108f88f3ce606acf06da4 Mon Sep 17 00:00:00 2001 From: Cole Brokamp Date: Tue, 8 Oct 2024 12:36:02 -0400 Subject: [PATCH] fix bug with using bbox to query sensors --- DESCRIPTION | 4 ++-- R/get_sensors_data.R | 8 ++++---- tests/testthat/test-get_organization_data.R | 3 ++- tests/testthat/test-get_sensors_data.R | 9 ++++++--- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 46bd875..1fcbd79 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: PurpleAir Title: Query the 'PurpleAir' Application Programming Interface -Version: 1.0.0.9000 +Version: 1.0.1.9000 Authors@R: person("Cole", "Brokamp", , "cole@colebrokamp.com", role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0002-0289-3151")) @@ -8,7 +8,7 @@ Description: Send requests to the 'PurpleAir' Application Programming Interface License: MIT + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Suggests: sf, testthat (>= 3.0.0) diff --git a/R/get_sensors_data.R b/R/get_sensors_data.R index 4e3b17d..5610b4f 100644 --- a/R/get_sensors_data.R +++ b/R/get_sensors_data.R @@ -73,10 +73,10 @@ get_sensors_data <- function(x, purple_air_request( max_age = max_age, location_type = location_type, - nwlat = as.numeric(x[1]), - nwlng = as.numeric(x[2]), - selat = as.numeric(x[3]), - selng = as.numeric(x[4]), + nwlat = as.numeric(x[4]), + nwlng = as.numeric(x[1]), + selat = as.numeric(x[2]), + selng = as.numeric(x[3]), resource = "sensors", success_code = as.integer(200), fields = fields, diff --git a/tests/testthat/test-get_organization_data.R b/tests/testthat/test-get_organization_data.R index c02caaa..c6e7f30 100644 --- a/tests/testthat/test-get_organization_data.R +++ b/tests/testthat/test-get_organization_data.R @@ -4,5 +4,6 @@ test_that("get_organization_data works", { testthat::skip_if(Sys.getenv("PURPLE_AIR_API_KEY") == "", "no PurpleAir API key present") skip_on_cran() od <- get_organization_data() - expect_equal(od$organization_name, "Organization Cole Brokamp C8A17F7C") + expect_equal(length(od$organization_name), 1) + expect_true(is.character(od$organization_id)) }) diff --git a/tests/testthat/test-get_sensors_data.R b/tests/testthat/test-get_sensors_data.R index ab054a2..19c040b 100644 --- a/tests/testthat/test-get_sensors_data.R +++ b/tests/testthat/test-get_sensors_data.R @@ -10,7 +10,9 @@ test_that("get_sensors_data works", { name = c("Lillard", "JN-Clifton,OH") ) ) - sf::st_bbox( + + d_bb <- + sf::st_bbox( c( "xmin" = -84.82030, "ymin" = 39.02153, @@ -19,9 +21,10 @@ test_that("get_sensors_data works", { ), crs = 4326 ) |> - get_sensors_data(fields = c("name")) |> - expect_s3_class("tbl_df") + get_sensors_data(fields = c("name")) + expect_true("woolper" %in% d_bb$name) + # sensors modified in the last 60 seconds get_sensors_data(as.POSIXct(Sys.time()) - 60, fields = "name") |> expect_s3_class("tbl_df")