-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
date_range_begin not filtering results #444
Comments
Thanks @svenhalvorson for thoroughly explaining the problem and including an example. Unfortunately I can't reproduce the difference between the approaches. I'm wondering what's different between our clients and servers. The thing about +5 hours makes me wonder if UTC is involved somewhere? The only difference between the RCurl & REDCapR code is the I like your demonstration code. I've adjusted it to include more comparisons. What do you get when you run my exact code (that uses my server's example dataset)? What do you use your token (on your project & server)?
+5 hours for I don't think it should matter, but use the most recent GitHub version with # Run this first line once to reset the values for the `dateRangeBegin` filter.
# REDCapR:::clean_start_simple(batch = FALSE, verbose = TRUE)
credential <- REDCapR:::retrieve_credential_testing(213L)
col_types <- readr::cols(.default = readr::col_character())
rcurl <- function(offset_hours) {
RCurl::postForm(
uri = credential$redcap_uri,
token = credential$token,
content = 'record',
format = 'csv',
type = 'flat',
rawOrLabel = 'raw',
rawOrLabelHeaders = 'raw',
exportCheckboxLabel = 'false',
exportSurveyFields = 'false',
exportDataAccessGroups = 'false',
returnFormat = 'json',
dateRangeBegin = strftime(Sys.time() + lubridate::hours(offset_hours), "%Y-%m-%d %H:%M:%S")
) |>
readr::read_csv(col_types = col_types) |>
nrow()
}
httr <- function(offset_hours) {
post_body <- list(
token = credential$token,
content = "record",
format = "csv",
type = "flat",
dateRangeBegin = strftime(Sys.time() + lubridate::hours(offset_hours), "%Y-%m-%d %H:%M:%S")
)
credential$redcap_uri |>
httr::POST(body = post_body) |>
httr::content(as = "text") |>
readr::read_csv(col_types = col_types) |>
nrow()
}
redcapr_batch <- function(offset_hours) {
REDCapR::redcap_read(
redcap_uri = credential$redcap_uri,
token = credential$token,
col_types = col_types,
datetime_range_begin = Sys.time() + lubridate::hours(offset_hours)
)$data |>
nrow()
}
redcapr_oneshot <- function(offset_hours) {
REDCapR::redcap_read_oneshot(
redcap_uri = credential$redcap_uri,
token = credential$token,
col_types = col_types,
datetime_range_begin = Sys.time() + lubridate::hours(offset_hours)
)$data |>
nrow()
}
hour_records <- tibble::tibble(
hours = seq.int(from = -2L, to = 2L, by = 1L),
rcurl = purrr::map_int(.x = hours, .f = rcurl),
httr = purrr::map_int(.x = hours, .f = httr),
batch = purrr::map_int(.x = hours, .f = redcapr_batch),
oneshot = purrr::map_int(.x = hours, .f = redcapr_oneshot)
)
hour_records
# A tibble: 5 × 5
hours rcurl httr batch oneshot
<int> <int> <int> <int> <int>
1 -2 5 5 5 5
2 -1 5 5 5 5
3 0 0 0 0 0
4 1 0 0 0 0
5 2 0 0 0 0 |
Thank you @wibeasley for the detailed response. I figured out that the server is set on UTC (action tags @NOW-SERVER and @NOW-UTC give the same value). The When I run it with your credentials I get the same output as you do. Using my own credentials and adjusting the hours, I get this: I edited two records today (about 4 hours ago) and these are the two that Might be some difference between my server and yours? Not really sure what to do from here. |
Where are you located in the world? What is the locale of your client? Maybe there's a relevant REDCap setting too? I'm stumped. I can imagine how our servers are set up differently. I don't understand how the httr and oneshot versions are different. The oneshot uses the same REDCapR/R/redcap-read-oneshot.R Line 238 in c934a8f
...and passes it to the same element of REDCapR/R/redcap-read-oneshot.R Line 254 in c934a8f
What is the right answer? 2 records in the past 8 hours? If you extended the timeline forwards & backwards, when does |
I'm on the west coast (PST). Updating a record and testing this gives me the 7 hours offset I would expect when using RCurl and httr. I think the example I gave in the original issue had modifications that were few hours old which is why they stopped being downloaded at +5. The correct answer is 2 records in the past 8 hours. I tried running this from -2000 to +200 and the |
|
Alright, I learned something! I went through
Then counted the rows returned and got this: Which lead me to understand that the problem is omitting This solves my immediate problem -- I can specify Thank you for your suggestions and patience! |
Yeah, I'm glad that helped. Thanks for using it to figure this out. That explains why the approaches were acting differently on the same server. I think the remaining problem will be solved when your server upgraded. This is from the release notes for REDCap v9.7.4. Although it's not exactly the behavior you're describing, it's close enough that I'm guessing your problem was solved at the same time. My site has a newer version of REDCap, so I think that explains our differences.
It sounds like you have a good workaround for your current server (ie, by passing an explicit value to both boundaries). If this workaround is still required after your site upgrades REDCap, please start a new REDCapR issue and refer to this one. Note to future self: I considered adding a non-blank default value to the date range parameters, but decided against it because:
|
Thanks for this package ya'll. I'm having trouble with reading in data from a specific datetime range:
redcap_read
-- it doesn't seem to care about thedatetime_range_begin
parameter. I am working on a project (still in design phase) that I know no one else is manipulating. I edited two records today but it seems likeredcap_read
downloads the whole data set regardless of what start time is supplied. For comparison purposes, I tried just using RCurl and it does work but is off by a few hours (time zone differences I assume). Example:The version with
RCurl
gives the correct number of records and eventually zero records at +5 hours. The version withREDCapR
gives all the records for each time offset.I tried to run this through the debugger and suspect it's something going wrong in
httr::POST
but I'm not positive.Thanks!
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: