Skip to content

Commit

Permalink
alter detection of ships so it actually works- real world data doesn'…
Browse files Browse the repository at this point in the history
…t completely follow the schema.

Also add 'metro' to long name for underground & Tyne&Wear metro services
  • Loading branch information
oweno-tfwm committed Sep 20, 2023
1 parent 83a4441 commit 1b6e515
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
18 changes: 12 additions & 6 deletions R/atoc_export.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,18 @@ longnames <- function(routes, stop_times, stops) {
routes <- dplyr::left_join(routes, stop_times_sub,
by = c("rowID" = "schedule"))


routes[`Train Category` == "SS", route_long_name := paste("Ship",route_long_name)]
routes[`Train Category` %in% c("BS", "BR"), route_long_name := paste("Bus",route_long_name)]
routes[!(`Train Category` %in% c("SS", "BS", "BR")), route_long_name := paste("Train",route_long_name)]
#TODO reflect the London Transport services being set to metro/underground in this naming code

#you'd expect to only have to look at category to tell if it's a ship, but in practice the category for
#ships is NA, so we have to look at 'Train Status' too.
routes["SS" ==`Train Category` | "S"==`Train Status` | "4"==`Train Status`,
route_long_name := paste("Ship",route_long_name)]
routes[`Train Category` %in% c("BS", "BR"),
route_long_name := paste("Bus",route_long_name)]

#Tyne & Wear metro is "OL" in data OL="London Underground/Metro Service"
routes[`Train Category` %in% c("EL", "OL"),
route_long_name := paste("Metro",route_long_name)]
routes[!(`Train Category` %in% c("SS", "BS", "BR", "EL", "OL") | "S"==`Train Status` | "4"==`Train Status`),
route_long_name := paste("Train",route_long_name)]
return(routes)
}

Expand Down
9 changes: 5 additions & 4 deletions R/atoc_main.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,17 @@ schedule2routes <- function(stop_times, stops, schedule, silent = TRUE, ncores =
trips <- dplyr::left_join(trips, train_status, by = c("Train Status" = "train_status"))
rm(train_status)

trips$route_type[trips$`Train Category` %in% c("EL", "OL") & trips$route_type == 2 ] <- 1
# London Underground is Metro (unless already identified as a bus/ship etc)
# "OL" is also used for Tyne & Wear metro

routes <- trips

routes <- dplyr::group_by(routes, `ATOC Code`, route_long_name, `Train Category`, route_type )
routes <- dplyr::summarise(routes)
routes$route_id <- 1:nrow(routes)

#join route_id back into trip table
trips <- dplyr::left_join(trips, routes, by = c("ATOC Code", "route_long_name", "Train Category", "route_type"))

routes <- routes[, c("route_id", "route_type", "ATOC Code", "route_long_name", "Train Category" )]
Expand All @@ -141,10 +146,6 @@ schedule2routes <- function(stop_times, stops, schedule, silent = TRUE, ncores =
# IDs are not meaningful, just leave out
routes$route_short_name <- "" # was: routes$route_id

routes$route_type[routes$agency_id == "LT" & routes$route_type == 2 ] <- 1
# London Underground is Metro (unless already identified as a bus/ship etc)
#TODO look at what this causes LizPurpCrossRailElizabethLine to be categorised as.
#TODO move to longnames()

### Section 6: #######################################################
# Final Checks
Expand Down

0 comments on commit 1b6e515

Please sign in to comment.