There are multiple functions in PWDGSI that modify the start and end dates of date ranges different. For example, marsFetchRainfallData and marsFetchRainEventData both add a single day to the end date when querying the database:
|
event_query <- paste(paste0("SELECT * FROM ", rainparams$eventtable), |
|
"WHERE", rainparams$uidvar, "= CAST('", rainsource, "' as int)", |
|
"AND eventdatastart >= Date('", start_date, "')", |
|
"AND eventdataend <= Date('", end_date + lubridate::days(1), "');") |
|
|
|
events <- DBI::dbGetQuery(con, event_query) |
marsFetchLevelData on the other hand adds a day before and a day after:
|
# Add buffer to requested dates based on DB time zone |
|
start_date <- lubridate::round_date(start_date) - lubridate::days(1) |
|
end_date <- lubridate::round_date(end_date) + lubridate::days(1) |
While this gives unexpected results (returns a range outside of the requested amount without notification), it is exasperated by functions that join the data or add their own changes to the date range. For example, the marsEventCombinedPlot adds an extra day before and after, which is then passed to marsFetchMonitoringData, which then is passed to marsFetchRainEventData and MarsFetchRainfallData.
|
#check for one day on either side of the event date |
|
event_date %<>% as.POSIXct(format = '%Y-%m-%d') |
|
start_date <- event_date - 86400 |
|
end_date <- event_date + 86400 |
This leads to unexpected results when with marsEventCombinedPlot. The following arguments returns an event for 2024-04-01 even though there was no rain on 3/31:
new_mars <- marsEventCombinedPlot(con = conn_sand,
event_date = "2024-03-31",
source = "gage",
smp_id = "1267-2-1",
ow_suffix = "CS2")
But the following shows no rain or event even though there was a rain event on 2024-03-27:
new_mars <- marsEventCombinedPlot(con = conn_sand,
event_date = "2024-03-26",
source = "gage",
smp_id = "1267-2-1",
ow_suffix = "CS2")
There are multiple functions in PWDGSI that modify the start and end dates of date ranges different. For example,
marsFetchRainfallDataandmarsFetchRainEventDataboth add a single day to the end date when querying the database:pwdgsi/R/mars_data_fetch_write_functions.R
Lines 753 to 758 in 63bc69b
marsFetchLevelDataon the other hand adds a day before and a day after:pwdgsi/R/mars_data_fetch_write_functions.R
Lines 682 to 684 in 63bc69b
While this gives unexpected results (returns a range outside of the requested amount without notification), it is exasperated by functions that join the data or add their own changes to the date range. For example, the
marsEventCombinedPlotadds an extra day before and after, which is then passed tomarsFetchMonitoringData, which then is passed tomarsFetchRainEventDataandMarsFetchRainfallData.pwdgsi/R/mars_plotting_functions.R
Lines 876 to 879 in 63bc69b
This leads to unexpected results when with
marsEventCombinedPlot. The following arguments returns an event for 2024-04-01 even though there was no rain on 3/31:But the following shows no rain or event even though there was a rain event on 2024-03-27: