|
| 1 | +#' Prepare stations data for weather download |
| 2 | +#' |
| 3 | +#' Filters stations by station IDs and interval, converts start/end to dates. |
| 4 | +#' |
| 5 | +#' @param station_ids Character/Numeric vector. Station IDs to prepare |
| 6 | +#' @param interval Character. "hour", "day", or "month" |
| 7 | +#' |
| 8 | +#' @returns Tibble of prepared stations data with date ranges |
| 9 | +#' |
| 10 | +#' @noRd |
| 11 | + |
1 | 12 | prep_stations <- function(station_ids, interval) { |
2 | 13 | stn <- stations_read() |> |
3 | 14 | dplyr::filter( |
@@ -25,6 +36,21 @@ prep_stations <- function(station_ids, interval) { |
25 | 36 | stn |
26 | 37 | } |
27 | 38 |
|
| 39 | +#' Prepare start and end dates for weather download |
| 40 | +#' |
| 41 | +#' Processes start and end dates for each station, handling NULL values, |
| 42 | +#' date limits, and detecting invalid date ranges. |
| 43 | +#' |
| 44 | +#' @param stn Data frame. Prepared stations data |
| 45 | +#' @param start Date. Requested start date for download or NULL for earliest |
| 46 | +#' available |
| 47 | +#' @param end Date. Requested end date for download or NULL for today |
| 48 | +#' |
| 49 | +#' @returns Tibble of stations data with start_use, end_use, and labels for |
| 50 | +#' later messages |
| 51 | +#' |
| 52 | +#' @noRd |
| 53 | + |
28 | 54 | prep_start_end <- function(stn, start, end) { |
29 | 55 | # Check start/ends |
30 | 56 | min_dt <- as.Date("1840-01-01") # Earliest date API will return |
@@ -52,6 +78,18 @@ prep_start_end <- function(stn, start, end) { |
52 | 78 | stn |
53 | 79 | } |
54 | 80 |
|
| 81 | +#' Prepare pagination for weather download |
| 82 | +#' |
| 83 | +#' Creates sequences of dates for paginated API requests based on interval |
| 84 | +#' (hourly by month, daily by year, monthly downloads full dataset). |
| 85 | +#' |
| 86 | +#' @param stn Data frame. Stations data with start_use and end_use dates |
| 87 | +#' @param months Numeric vector. Optional months to filter for hourly data |
| 88 | +#' |
| 89 | +#' @returns Tibble of stations data with pages column containing date sequences |
| 90 | +#' |
| 91 | +#' @noRd |
| 92 | + |
55 | 93 | prep_paging <- function(stn, months) { |
56 | 94 | stn |> |
57 | 95 | dplyr::mutate( |
|
0 commit comments