-
Notifications
You must be signed in to change notification settings - Fork 2
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
Improve Handling of Query Limit Issues #13
Comments
The code works this morning for test db. Haven't retried it on prod. Maybe it's related to the recent issues in production db? |
@Nova-Scotia Could be server-related but I think this might also be due to passing too many station_ids to library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(stringr)
library(kiwisR)
#> Warning: package 'kiwisR' was built under R version 3.6.2
# List all stations in swmc hub that match "SNOW-WLF"
mystations <- ki_station_list(
hub = "swmc"
) %>%
filter(
str_sub(station_no, 1, 8) == "SNOW-WLF" &
!station_no %in% c(
"SNOW-WLF-XX",
"SNOW-WLF-TEMP"
)
)
# List all codes that connect the station codes with their available time series.
my_station_ids <- unique(mystations$station_id)
print(length(my_station_ids))
#> [1] 218 Created on 2020-01-28 by the reprex package (v0.3.0) You can get around this by chunking your query (e.g.- by filtering library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(stringr)
library(kiwisR)
#> Warning: package 'kiwisR' was built under R version 3.6.2
library(purrr)
# List all stations in swmc hub that match "SNOW-WLF"
mystations <- ki_station_list(
hub = "swmc"
) %>%
filter(
str_sub(station_no, 1, 8) == "SNOW-WLF" &
!station_no %in% c(
"SNOW-WLF-XX",
"SNOW-WLF-TEMP"
)
)
# List all codes that connect the station codes with their available time series.
my_station_ids <- unique(mystations$station_id)
# Init progress bar
pb <- progress_estimated(length(my_station_ids))
station_ts <- my_station_ids %>%
purrr::map_df(
function(stn_id){
# Add tick to bar
pb$tick()$print()
ki_timeseries_list(
hub = "swmc",
station_id = stn_id
)
}
)
head(station_ts)
#> # A tibble: 6 x 6
#> station_name station_id ts_id ts_name from to
#> <chr> <chr> <chr> <chr> <dttm> <dttm>
#> 1 ALEXANDRIA 967631 12280~ SPG.Av~ NA NA
#> 2 ALEXANDRIA 967631 12156~ SPG.9.P NA NA
#> 3 ALEXANDRIA 967631 12156~ SPG.10~ NA NA
#> 4 ALEXANDRIA 967631 12156~ SPG.5.P NA NA
#> 5 ALEXANDRIA 967631 12156~ SPG.Av~ NA NA
#> 6 ALEXANDRIA 967631 12280~ SPG.Me~ NA NA Created on 2020-01-28 by the reprex package (v0.3.0) Open to suggestions on long-term fixes for the query limit issues. Two potential options:
|
Nice ideas - thanks so much for taking the time to look into this. I'll try out your posted solution and I LOVE progress bars :). The server limit is definitely an annoying barrier. Just wanted to note though - my previous script did work before I updated from an older version of kiwisR to the newer version. Did anything change? Test also has about the same amount of data as prod. |
Also, I like the first option if you're going to add a perma-fix - including the progress bar! |
@Nova-Scotia There are some changes coming down in R 4.0 related to classes/inheritance and I had to adjust some of the internal type checks to reflect this (#11, commit). More information on this here if you're interested in learning more. I'm guessing that we're seeing this message when kiwisR fails to properly present the error message returned by the server upon reaching/surpassing the query limit. As to why you didn't hit the limit before- have no idea tbh. Perhaps the query limit is flexible/linked to how busy the server is 🤷♂ ? |
ki_timeseries_list
after updating kiwisR
: "Error: object of type 'closure' is not subsettable"
Hey Ryan, just a quick FYI - it seems like the behaviour of the server is unpredictable. I just tried a minor variation on the code you supplied and got an error:
I dislike these server limits very much! |
I just updated
kiwisR
to take advantage of some newer functionality (ability to query other fields withki_timeseries_values
- thanks for adding this)!Previously, I could run this code without errors:
Now, when I run the last line of code (list all timeseries associated with each code), I get the error, "Error: object of type 'closure' is not subsettable".
I tried putting the last line in a loop and it works ok - I thought I could find the problem station by doing this here, but I didn't.
Can you reproduce this issue? If so, any idea on how to fix it?
The text was updated successfully, but these errors were encountered: