Skip to content

Commit

Permalink
feat: new maximum date ranges in pat_create()
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathancallahan committed May 31, 2024
1 parent 02f87bc commit b751236
Show file tree
Hide file tree
Showing 88 changed files with 182 additions and 100 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Type: Package
Package: AirSensor2
Version: 0.5.0
Version: 0.5.1
Title: Process and Display Data from Air Quality Sensors
Authors@R: c(
person("Jonathan", "Callahan", email="[email protected]", role=c("aut","cre"))
Expand All @@ -27,7 +27,7 @@ Imports:
magrittr,
MazamaLocationUtils (>= 0.4.3),
MazamaSpatialUtils (>= 0.8.6),
MazamaTimeSeries (>= 0.2.16),
MazamaTimeSeries (>= 0.3.0),
readr,
rlang,
sf,
Expand All @@ -44,4 +44,4 @@ Language: en-US
LazyData: true
Repository: CRAN
VignetteBuilder: knitr
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
14 changes: 14 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# AirSensor2 0.5.1

Updated the of data that can be requested in a single call in `pat_create()` to
match updates to the PurpleAir API:

| Average Period | Previous Limit | New Limit |
| -------------- | -------------- | --------- |
| Real-Time | 2 Days | 30 Days |
| 10 Minutes | 3 Days | 60 Days |
| 30 Minutes | 7 Days | 90 Days |
| 1 Hour | 14 Days | 180 Days |
| 6 Hours | 90 Days | 1 Year |
| 1 Day | 1 Year | 2 Years |

# AirSensor2 0.5.0

Version 0.5 introduces changes in the default parameters that are requested
Expand Down
30 changes: 25 additions & 5 deletions R/pat_create.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
#' @return A PurpleAir Timeseries \emph{pat} object.
#'
#' @description Create a \code{pat} object for a specific \code{sensor_index}.
#' This function splits up the requested time range into 2-day intervals (the
#' maximum allowed by the PurpleAir API) and makes repeated calls to
#' This function splits up the requested time range into multi-day intervals (as
#' required by the PurpleAir API) and makes repeated calls to
#' \code{pat_downloadParseRawData()}. The \code{sleep} parameter waits a small
#' amount of time between API requests.
#'
Expand Down Expand Up @@ -154,6 +154,7 @@ pat_create <- function(

# Create a valid dateRange
if ( !is.null(startdate) && !is.null(enddate) ) {

# Don't require day boundaries
dateRange <- MazamaCoreUtils::timeRange(
starttime = startdate,
Expand All @@ -163,7 +164,9 @@ pat_create <- function(
ceilingStart = FALSE,
ceilingEnd = FALSE
)

} else {

# Default to 2 days with day boundaries
dateRange <- MazamaCoreUtils::dateRange(
startdate = startdate,
Expand All @@ -174,10 +177,27 @@ pat_create <- function(
ceilingEnd = FALSE,
days = 2
)

}

# NOTE: On 2024-05-03, PurpleAir announced expanded time limits for
# NOTE: historical data requests as reflected here:

# raw data ( average == 0 )
dayCount <- 30

if ( average == 10 ) {
dayCount <- 60
} else if ( average == 30 ) {
dayCount <- 90
} else if ( average == 60 ) {
dayCount <- 180
} else {
dayCount <- 365
}

# Create a sequence of every-2-days POSIXct times
dateSequence <- seq(dateRange[1], dateRange[2], by = lubridate::ddays(2))
# Create a sequence of every-dayCount-days POSIXct times
dateSequence <- seq(dateRange[1], dateRange[2], by = lubridate::ddays(dayCount))

# Tack on the final data if needed
if ( dateRange[2] > utils::tail(dateSequence, 1) ) {
Expand Down Expand Up @@ -338,7 +358,7 @@ if ( FALSE ) {
pas = example_pas_metadata
sensor_index = "95189"
startdate = "2024-01-01"
enddate = "2024-01-03"
enddate = "2024-01-15"
timezone = "America/Los_Angeles"
average = 0
fields = PurpleAir_PAT_QC_FIELDS
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/LICENSE-text.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/AirSensor2.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/Citations.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/Developer_Style_Guide.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/Working_with_PurpleAir_API_Keys.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions docs/authors.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion docs/news/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ articles:
Developer_Style_Guide: Developer_Style_Guide.html
Citations: Citations.html
Working_with_PurpleAir_API_Keys: Working_with_PurpleAir_API_Keys.html
last_built: 2024-03-13T23:37Z
last_built: 2024-05-31T21:08Z

2 changes: 1 addition & 1 deletion docs/reference/APIKeys.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion docs/reference/AirSensor2.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/Clarity_createAllOpenMonitors.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/Clarity_createOpenMonitor.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/Clarity_createOpenSynoptic.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/Clarity_enhanceRawSynopticData.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/Clarity_getAllOpenHourly.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/Clarity_getAllOpenIndvidual.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/Clarity_getOpenHourly.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/Clarity_getOpenIndividual.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/Clarity_updateAllOpenMonitors.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/PurpleAir_PAList_PM25_FIELDS.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/PurpleAir_PAS_AVG_PM25_FIELDS.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/PurpleAir_PAS_METADATA_FIELDS.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b751236

Please sign in to comment.