Skip to content

Instantly share code, notes, and snippets.

@idshklein
Created April 27, 2022 20:40
Show Gist options
  • Save idshklein/69e8ccbc59e05c01244ff07a5b43a611 to your computer and use it in GitHub Desktop.
Save idshklein/69e8ccbc59e05c01244ff07a5b43a611 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(jsonlite)
library(lubridate)
library(sf)
res3 <- map(0:12,function(x){
print(x)
res2 <- read_json(paste0("https://open-bus-stride-api.hasadna.org.il/siri_vehicle_locations/list?lon__greater_or_equal=35.1998&lon__lower_or_equal=35.201&lat__greater_or_equal=31.754&lat__lower_or_equal=31.7558&offset=",1+x*100,"&recorded_at_time_from=2022-03-09T00:00:00.000Z&recorded_at_time_to=2022-03-20T00:00:00.000Z"))
df2 <- map_df(1:length(res2),~res2[[.x]])
df2
})
res3 %>% bind_rows() %>%
st_as_sf(coords = c("lon","lat"),crs = 4326) %>%
mutate(dt = as_datetime(recorded_at_time,tz = "Israel"),
h= hour(dt),
date = as_date(dt)) %>%
ggplot(aes(x= velocity)) +
geom_histogram() +
facet_grid(date~h)
res3 %>% bind_rows() %>%
st_as_sf(coords = c("lon","lat"),crs = 4326) %>%
mutate(dt = as_datetime(recorded_at_time,tz = "Israel"),
h= hour(dt),
date = as_date(dt)) %>%
ggplot(aes(color= velocity)) +
geom_sf()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment