Skip to content

Instantly share code, notes, and snippets.

@idshklein
Created August 14, 2022 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idshklein/c9a952d5964dd0a13261f592dd50424f to your computer and use it in GitHub Desktop.
Save idshklein/c9a952d5964dd0a13261f592dd50424f to your computer and use it in GitHub Desktop.
pacman::p_load(tidyverse,jsonlite,httr)
buses <- read_json("https://data.gov.il/api/3/action/datastore_search?resource_id=91d298ed-a260-4f93-9d50-d5e3c5b82ce1&limit=20000")
buses1 <- buses$result$records %>% map_df(~.x)
rishui <- read_json("https://data.gov.il/api/3/action/datastore_search?resource_id=8fd3aa6c-a64f-4c91-818e-fd35017cd19b&&filters={%22rishui_date%22:%222022-08-09T00:00:00%22}&limit=20000")
rishui1 <- rishui$result$records%>% map_df(~.x)
GET("https://open-bus-stride-api.hasadna.org.il/siri_rides/list?get_count=false&scheduled_start_time_from=2022-08-09T00%3A00%3A00%2B02%3A00&scheduled_start_time_to=2022-08-09T23%3A59%3A59%2B02%3A00&order_by=siri_route_id%20asc%2Cvehicle_ref%20desc&limit=200000",write_disk(siri <- tempfile(fileext = ".json")))
siri1 <- read_json(siri)%>% map_df(~.x)
rishui1$trips_count %>% sum()
GET("https://open-bus-stride-api.hasadna.org.il/gtfs_rides/list?get_count=false&limit=100000",write_disk(rides1 <- tempfile(fileext = ".json")))
GET("https://open-bus-stride-api.hasadna.org.il/gtfs_rides/list?get_count=false&limit=100000&offset=100000",write_disk(rides2 <- tempfile(fileext = ".json")))
GET("https://open-bus-stride-api.hasadna.org.il/gtfs_rides/list?get_count=false&limit=100000&offset=200000",write_disk(rides3 <- tempfile(fileext = ".json")))
GET("https://open-bus-stride-api.hasadna.org.il/gtfs_rides/list?get_count=false&limit=100000&offset=300000",write_disk(rides4 <- tempfile(fileext = ".json")))
GET("https://open-bus-stride-api.hasadna.org.il/gtfs_rides/list?get_count=false&limit=100000&offset=400000",write_disk(rides5 <- tempfile(fileext = ".json")))
rides <- map_df(c(rides1,rides2,rides3,rides4,rides5),~read_json(.x))
GET("https://open-bus-stride-api.hasadna.org.il/gtfs_routes/list?get_count=false&date_from=2022-08-09&date_to=2022-08-09&limit=6000",write_disk(routes <- tempfile(fileext = ".json")))
routes1 <- read_json(routes)%>% map_df(~.x)
siri1 %>%
mutate(vehicle_ref=as.integer(vehicle_ref)) %>%
left_join(buses1, by = c("vehicle_ref"="bus_license_id")) %>%
left_join(rides, by=c("route_gtfs_ride_id"="id")) %>%
left_join(routes1,by=c("gtfs_route_id"="id")) %>%
mutate(route_mkt=as.integer(route_mkt)) %>%
left_join(rishui1 %>% select(office_line_id,VehicleSize_nm) %>% distinct(),by = c("route_mkt"="office_line_id")) %>%
count(VehicleSize_nm,BusSize_nm) %>% View()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment