Skip to content

Commit

Permalink
fix bug with using bbox to query sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
cole-brokamp committed Oct 8, 2024
1 parent 773d8de commit 857b36d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Package: PurpleAir
Title: Query the 'PurpleAir' Application Programming Interface
Version: 1.0.0.9000
Version: 1.0.1.9000
Authors@R:
person("Cole", "Brokamp", , "[email protected]", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0002-0289-3151"))
Description: Send requests to the 'PurpleAir' Application Programming Interface (API; <https://community.purpleair.com/c/data/api/18>). Check a 'PurpleAir' API key and get information about the related organization. Download real-time data from a single 'PurpleAir' sensor or many sensors by sensor identifier, geographical bounding box, or time since modified. Download historical data from a single sensor.
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)
Expand Down
8 changes: 4 additions & 4 deletions R/get_sensors_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-get_organization_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
9 changes: 6 additions & 3 deletions tests/testthat/test-get_sensors_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand Down

0 comments on commit 857b36d

Please sign in to comment.