Skip to content

Commit

Permalink
Merge pull request #6 from cole-brokamp/bbox-bug-fix
Browse files Browse the repository at this point in the history
fix bug with using bbox to query sensors
  • Loading branch information
cole-brokamp authored Oct 8, 2024
2 parents 773d8de + 6545c2a commit 324c236
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 59 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
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
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# PurpleAir (development version)
# PurpleAir 1.0.1

* Fix bug with using bbox coordinates to find sensors

# PurpleAir 1.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
88 changes: 44 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use:

``` r
check_api_key(Sys.getenv("PURPLE_AIR_API_KEY"))
#> ✔ Using valid 'READ' key with version V1.0.14-0.0.57 of the PurpleAir API on 1720549867
#> ✔ Using valid 'READ' key with version V1.0.14-0.0.58 of the PurpleAir API on 1728410515
```

Get the latest data from a single PurpleAir sensor, defined by its
Expand All @@ -72,16 +72,16 @@ key](https://community.purpleair.com/t/sensor-indexes-and-read-keys/4000):
get_sensor_data(sensor_index = 175413,
fields = c("name", "last_seen", "pm2.5_cf_1", "pm2.5_atm"))
#> $last_seen
#> [1] "2024-07-09 14:30:33 EDT"
#> [1] "2024-10-08 13:59:39 EDT"
#>
#> $name
#> [1] "JN-Clifton,OH"
#>
#> $pm2.5_atm
#> [1] 28.3
#> [1] 0.9
#>
#> $pm2.5_cf_1
#> [1] 28.7
#> [1] 0.9
```

Get the latest data from many PurpleAir sensors, defined by their sensor
Expand All @@ -93,8 +93,8 @@ get_sensors_data(x = c(175257, 175413),
#> # A tibble: 2 × 5
#> sensor_index last_seen name pm2.5_atm pm2.5_cf_1
#> <int> <dttm> <chr> <dbl> <dbl>
#> 1 175257 2024-07-09 14:28:53 Lillard 28.2 28.8
#> 2 175413 2024-07-09 14:28:33 JN-Clifton,OH 29.6 30.2
#> 1 175257 2024-10-08 14:00:02 Lillard 1.4 1.4
#> 2 175413 2024-10-08 14:01:39 JN-Clifton,OH 1 1
```

a geographic [bounding box](http://bboxfinder.com),
Expand All @@ -110,40 +110,40 @@ sf::st_bbox(
crs = 4326
) |>
get_sensors_data(fields = c("name"))
#> # A tibble: 45 × 2
#> sensor_index name
#> <int> <chr>
#> 1 30303 아가페_실내
#> 2 30561 lineblock_outside2
#> 3 30571 amlok_inside
#> 4 36325 807d3a616167
#> 5 36681 68c63a8e59a
#> 6 42623 KMI_041
#> 7 49191 BCDDC264D0B1
#> 8 49193 ECFABCB88583
#> 9 49199 ECFABC59A4F4
#> 10 49213 807D3A615D1E
#> # ℹ 35 more rows
#> # A tibble: 56 × 2
#> sensor_index name
#> <int> <chr>
#> 1 35225 Mt. Washington
#> 2 102568 SR32
#> 3 103282 Carolina pines
#> 4 111898 Bridgetown Sanctuary
#> 5 120311 Loveland
#> 6 127885 Meals on Wheels
#> 7 127915 MSD 6
#> 8 127921 Groundwork
#> 9 130719 NKU KY DAQ
#> 10 156117 Tshs 1
#> # ℹ 46 more rows
```

or a date from which sensors must have been modified since.

``` r
get_sensors_data(as.POSIXct(Sys.time()) - 60, fields = "name")
#> # A tibble: 8,815 × 2
#> sensor_index name
#> <int> <chr>
#> 1 77 Sunnyside
#> 2 314 Parker
#> 3 340 Ingram Road
#> 4 387 Monmouth Drive P1
#> 5 459 Flight Park North 2
#> 6 912 The Hub
#> 7 930 Strathcona Terrace
#> 8 934 Glenmohr Drive
#> 9 978 Hillerød f989
#> 10 992 Cosgriff Catholic School
#> # ℹ 8,805 more rows
#> # A tibble: 568 × 2
#> sensor_index name
#> <int> <chr>
#> 1 978 Hillerød f989
#> 2 1294 Roberts Creek
#> 3 1638 Moab
#> 4 2372 SCSB_22
#> 5 2574 Berkeley Park and Coventry, Kensington, CA, USA
#> 6 3088 Howe Neighborhood
#> 7 3277 Shop
#> 8 3497 Olive
#> 9 5538 Hood River Weather
#> 10 6408 Amberwood
#> # ℹ 558 more rows
```

Get historical data from a single PurpleAir sensor:
Expand All @@ -161,16 +161,16 @@ my_history
#> # A tibble: 432 × 5
#> time_stamp pm1.0_cf_1 pm1.0_atm pm2.5_atm pm2.5_cf_1
#> <dttm> <dbl> <dbl> <dbl> <dbl>
#> 1 2024-07-04 21:10:00 2505. 1671. 1672. 2506.
#> 2 2024-07-04 23:30:00 2510. 1676. 1680. 2513.
#> 3 2024-07-04 20:40:00 31.9 25.3 27.9 34.6
#> 4 2024-07-04 20:30:00 16.5 14.2 16.5 18.9
#> 5 2024-07-04 23:50:00 2509. 1675. 1678. 2512.
#> 6 2024-07-04 21:50:00 2513. 1678. 1683. 2517.
#> 7 2024-07-04 20:50:00 386. 262. 265. 390.
#> 8 2024-07-04 22:00:00 2512. 1678. 1682. 2516.
#> 9 2024-07-04 22:40:00 2536. 1690. 1699. 2549.
#> 10 2024-07-04 21:00:00 914. 612. 614. 916.
#> 1 2024-07-03 23:40:00 2503. 1670. 1671. 2505.
#> 2 2024-07-04 06:50:00 2504. 1670. 1671. 2505.
#> 3 2024-07-03 22:10:00 2505. 1672. 1673. 2507.
#> 4 2024-07-04 07:10:00 2503. 1670. 1671. 2504.
#> 5 2024-07-04 09:40:00 2504. 1671. 1672. 2505.
#> 6 2024-07-04 11:30:00 2504. 1671. 1673. 2506.
#> 7 2024-07-04 03:40:00 2501. 1668. 1669. 2502.
#> 8 2024-07-03 22:20:00 2504. 1671. 1673. 2506.
#> 9 2024-07-04 03:00:00 2502. 1669. 1669. 2503.
#> 10 2024-07-04 18:50:00 8.32 8.32 10.1 10.1
#> # ℹ 422 more rows
```

Expand Down
5 changes: 1 addition & 4 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
## Resubmission
* Fixed spellings and single quote `PurpleAir` in Description

## R CMD check results

0 errors | 0 warnings | 0 note

* This is a new release.
* This is a bug fix update.
* R CMD checks passed with above results on:
* R v4.4.1 (macos, windows, and ubuntu)
* R v4.3.3 (ubuntu)
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 324c236

Please sign in to comment.