-
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
Feature quick daily flows from graphql #105
Conversation
CMD check is happy, the new function is covered with tests and has as many fail checks on arguments as I could think of. I aim to cover the rest of the user facing functions with similar checks in a separate branch and I think we are ready to submit to CRAN. |
…g dplyr:: before relocate
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.
👍
@@ -33,6 +33,7 @@ Imports: | |||
fs, | |||
glue, | |||
here, | |||
httr2, |
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.
👍 to using this.
spod_quick_get_od <- function( | ||
date = NA, | ||
min_trips = 100, | ||
distances = c("500m-2km", "2-10km", "10-50km", "50+km"), |
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.
Great we can select which distances of most relevance.
response <- httr2::request(graphql_endpoint) |> | ||
httr2::req_headers( | ||
"Content-Type" = "application/json", | ||
"User-Agent" = "spanishoddata R package, https://github.com/rOpenSpain/spanishoddata/" |
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.
Fantastic.
@@ -46,6 +47,11 @@ reference: | |||
- spod_convert | |||
- spod_connect | |||
- spod_disconnect | |||
- title: "Analysing up to 1 day of trips with no extra variables" | |||
desc: > | |||
Quickly get a single day of flows between municipalities (without hourly data or any other attributes) for 2022 and onwards |
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.
This is so cool.
".*Invalid municipality IDs detected.*" | ||
) | ||
|
||
expect_error( |
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.
Good to see the checks. Excellent work!
@@ -0,0 +1,252 @@ | |||
--- | |||
title: "Quicky get daily data" |
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.
👍 to the vignette.
vignettes/quick-get.qmd
Outdated
|
||
# Introduction {#intro} | ||
|
||
This vignette demonstrates how to get minimal daily aggregated data on the number of trips between municipalities using the `spod_quick_get_od()` function. With this function, you only get total trips for a single day, and no additional variables that are available in the full [v2 (2022 onwards) data set](v2-2022-onwards-mitma-data-codebook.html). The advantage of this function is that it is much faster than downloading the full data from source CSV files using `spod_get()`, as each CSV file for a single day is about 200 MB in size. |
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.
And uses less memory. But that's kind of self-explanatory. Great intro.
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.
@Robinlovelace Actually, it may not be obvious to everyone, so I will add this in. Great idea!
Co-authored-by: Robin Lovelace <[email protected]>
added a few bits about memory, cpu and amount of data transferred to both function docs and the vignette. merging now. |
This PR adds a new way to get daily aggregated data for 2022 onwards with only trip counts via the new GraphQL API endpoint provided by https://mapas-movilidad.transportes.gob.es/. The default minimum number of trips filter is set only get flows with at least 100 trips to ease the load on the API when users don't change the default.
See the new vignette (included with the PR) on how to use this new function.