Skip to content
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

Merged
merged 11 commits into from
Dec 2, 2024

Conversation

e-kotov
Copy link
Member

@e-kotov e-kotov commented Nov 23, 2024

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.

@e-kotov
Copy link
Member Author

e-kotov commented Nov 23, 2024

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.

Copy link
Collaborator

@Robinlovelace Robinlovelace left a 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,
Copy link
Collaborator

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"),
Copy link
Collaborator

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/"
Copy link
Collaborator

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
Copy link
Collaborator

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(
Copy link
Collaborator

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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 to the vignette.


# 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.
Copy link
Collaborator

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.

Copy link
Member Author

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!

vignettes/quick-get.qmd Outdated Show resolved Hide resolved
@e-kotov
Copy link
Member Author

e-kotov commented Dec 2, 2024

added a few bits about memory, cpu and amount of data transferred to both function docs and the vignette. merging now.

@e-kotov e-kotov merged commit 13c0506 into main Dec 2, 2024
1 check passed
@e-kotov e-kotov deleted the feature-quick-daily-flows-from-graphql branch December 2, 2024 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants