-
Notifications
You must be signed in to change notification settings - Fork 94
Add statistics functions #836
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
base: develop
Are you sure you want to change the base?
Conversation
R/read_waterdata_stats_datatable.R
Outdated
| "site_type", "site_type_code", | ||
| "country_code", "state_code", "county_code", | ||
| "geometry") | ||
| data.table::setcolorder(combined, col_order) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make sure combined gets returned as a data frame. There are some subtle differences that users won't expect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intention here was to return something similar to what's returned by the other read_waterdata functions, hence the wrapping in sf::st_as_sf. Do we want the result to be a "pure" data.frame instead? Oh, you probably mean converting from a data.table. Nvm, I'll change that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I just meant not a data.table, it can still be sf
R/read_waterdata_stats.R
Outdated
| #' | ||
| #' @export | ||
| #' | ||
| #' @param approval_status asdf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you get to this part, don't re-invent the wheel, just copy/paste the text from the API documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was leaving this in case we wanted to expand the get_params and related functions to pull from the /statistics Swagger docs. I've not scraped Swagger documentation before, so I'm not sure how easy that would be to generalize. I can just copy + paste the API docs for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The OGC service has a schema service that provides descriptions and whatnot via an API (I swooned 🤩 when I saw it). I wouldn't scrape Swagger though, more technical debt than what's saved.
|
|
||
| base_request <- construct_statistics_request(service = service, version = 0) | ||
|
|
||
| # TODO?: arg type checking here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In many arguments in dataRetrieval, the user can enter a number, character, vector, a date - and the code will convert it all to a character. So, you can check if it makes sense for a particular argument, but (a) don't let that code get ridiculously big trying to do everything and (b) see if the natural errors make sense as-is. If not, maybe try to clean up that error message. Usually (I don't know about here specifically), if a user puts in something really out of left field, the query will fail with a message that does imply their request was bad. That being said, the "waterdata" functions all have a similar input, at some point we can explore if a argument checker function could be written in a way that's more helpful.
R/read_waterdata_stats_datatable.R
Outdated
| combined <- data.table::rbindlist(combined_list) | ||
| combined <- combined[return_list, on = "rid"] | ||
|
|
||
| col_order <- c("parent_time_series_id", "monitoring_location_id", "monitoring_location_name", "parameter_code", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we can figure out a way to not write these out by hand. On the off-chance they add some columns or change the function will start to fail. (and yes, similar hard-coding has caused some headaches in the past with dataRetrieval). We added some logic (I think just in the current PR that removes max_results) to move all "id" columns to the far right (because users don't want to see those big ol'hashes first) UNLESS they are special like monitoring_location_id.
…responses, fix data.table joining.


Still to-do:
get_params,get_description, andbase_urlfunctions to pull the docs for /statistics too?get_statistics_datainto separate functions to match other read_waterdata patternsread_ogc_datahelpers are needed:return_list <- do.call(rbind, return_list_tmp)as it's a slight bottleneck.And there's Laura's list of to-dos here: https://code.usgs.gov/water/dataRetrieval/-/issues/450