Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion R/read_waterdata_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
#' supplied then statistics will be supplied for the entire period of record.
#' @param end_date End Date Query Parameter. The logic is inclusive i.e., it will
#' also return records that match the date.
#' @param normal_type Normal Type Query Parameter. If unspecified, all matching data
#' will be returned. Otherwise, it will filter the results to one of the following
#' normals: day-of-year, month-of-year. Available values: "DOY", "MOY".
#' @param interval_type Interval Type Query Parameter. If unspecified, all matching
#' data will be returned. Otherwise, it will filter the results to one or more of
#' the following intervals: month, calendar year, water year.
#' Available values: "M", "CY", "WY".
#' @param monitoring_location_id Each monitoring location has been assigned a
#' unique station number that places them in downstream order. Accepts
#' multiple values in a character vector.
Expand Down Expand Up @@ -69,6 +76,12 @@
#' monitoring_location_id = c("USGS-02319394", "USGS-02171500")
#' )
#'
#' # Request only month-of-year statistics using normal_type arg
#' x1 <- read_waterdata_stats_por(
#' monitoring_location_id = c("USGS-02319394", "USGS-02171500"),
#' normal_type = "MOY"
#' )
#'
#' # Request temperature percentiles for specific month-day range
#' # Returns:
#' # - Day-of-year temperature percentiles for each day between June 1 through June 15.
Expand All @@ -88,6 +101,12 @@
#' monitoring_location_id = c("USGS-02319394", "USGS-02171500")
#' )
#'
#' # Request only calendar year statistics
#' x3 <- read_waterdata_stats_daterange(
#' monitoring_location_id = c("USGS-02319394", "USGS-02171500"),
#' interval_type = "CY"
#' )
#'
#' # Request specific gage height and discharge summaries for a limited date range
#' # Returns:
#' # - calendar month summaries for each month between January, 2010 through December, 2011
Expand All @@ -112,6 +131,7 @@ read_waterdata_stats_por <- function(
county_code = NA_character_,
start_date = NA_character_,
end_date = NA_character_,
normal_type = NA_character_,
monitoring_location_id = NA_character_,
parent_time_series_id = NA_character_,
site_type_code = NA_character_,
Expand All @@ -134,6 +154,7 @@ read_waterdata_stats_daterange <- function(
county_code = NA_character_,
start_date = NA_character_,
end_date = NA_character_,
interval_type = NA_character_,
monitoring_location_id = NA_character_,
parent_time_series_id = NA_character_,
site_type_code = NA_character_,
Expand Down Expand Up @@ -333,11 +354,12 @@ deal_with_empty_stats <- function(
"parameter_code",
"unit_of_measure",
"parent_time_series_id",
"parent_statistics_id",
"parent_statistics_name",
"value",
"percentile",
"start_date",
"end_date",
"interval_type",
"sample_count",
"approval_status",
"computation_id",
Expand Down
23 changes: 23 additions & 0 deletions man/read_waterdata_stats.Rd

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

29 changes: 29 additions & 0 deletions tests/testthat/test_waterdata_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,24 @@ test_that("read_waterdata_stats_por returns data", {
expect_true(nrow(out) > 0)
})

test_that("normal_type arg works in read_waterdata_stats_por", {
skip_on_cran()
skip_if_offline()

out <- read_waterdata_stats_por(
monitoring_location_id = "USGS-01646500",
parameter_code = "00060",
computation_type = "median",
page_size = 5,
normal_type = "MOY"
)

expect_s3_class(out, "sf")
expect_true(nrow(out) > 0)
# time_of_year should have 12 months of data
expect_true(length(out$time_of_year) == 12)
})

test_that("read_waterdata_stats_daterange returns data", {
skip_on_cran()
skip_if_offline()
Expand All @@ -297,4 +315,15 @@ test_that("read_waterdata_stats_daterange returns data", {

expect_s3_class(out, "sf")
expect_true(nrow(out) > 0)

# setting interval_type arg returns fewer rows than unset
out1 <- read_waterdata_stats_daterange(
monitoring_location_id = "USGS-01646500",
parameter_code = "00060",
computation_type = "maximum",
interval_type = "CY",
page_size = 5
)

expect_true(nrow(out1) < nrow(out))
})
Loading
Loading