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

Merge changes from TfWM #58

Open
wants to merge 87 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
1a7c832
fix failure to merge BODS and NR gtfs files because data type of join…
oweno-tfwm Aug 15, 2023
b31dfb7
trip id is a varchar in BODS data - remove assumption that it's an int
oweno-tfwm Aug 24, 2023
074826c
exception_type is an int - tests failing after tightening up data typ…
oweno-tfwm Aug 24, 2023
8d4c2d8
code was assuming a set of tables, and hence dumping tables like 'fre…
oweno-tfwm Aug 24, 2023
ccd451e
merge was expecting a fixed set of tables and columns and throwing aw…
oweno-tfwm Aug 24, 2023
c9f7cce
added FOC YG + MV (appearing in NR timetable extracts)
oweno-tfwm Aug 24, 2023
0033338
fix null columns being inserted in calendar_dates key field when a ca…
oweno-tfwm Aug 25, 2023
bf8f460
correct comment - column is a 3 valued enum, not bool
oweno-tfwm Aug 25, 2023
f04ae8b
pass 'silent' value down the call stack and give some level of warnin…
oweno-tfwm Aug 25, 2023
b4b5651
format frequencies table columns correctly
oweno-tfwm Aug 25, 2023
4048f27
exercise more code paths with test by producing more verbose output
oweno-tfwm Aug 25, 2023
bb1220d
Merge branch 'oo-tfwm-performance' of ssh://github.com/oweno-tfwm/UK2…
oweno-tfwm Aug 25, 2023
772e072
Merge pull request #2 from ITSLeeds/master
oweno-tfwm Aug 25, 2023
5cb490c
Merge branch 'master' into oo-tfwm-performance
oweno-tfwm Aug 25, 2023
c199bb4
Merge pull request #3 from oweno-tfwm/oo-tfwm-performance
oweno-tfwm Aug 25, 2023
8391315
stop errors in merge() being swallowed silently, with the only clue t…
oweno-tfwm Aug 29, 2023
baf5346
add additional combinations of activity codes arising from reading en…
oweno-tfwm Aug 29, 2023
8742c56
fix activity not being read from LO
oweno-tfwm Aug 29, 2023
77aa421
rebuild documentation
oweno-tfwm Aug 29, 2023
1c55584
workround roxygen bug
oweno-tfwm Aug 29, 2023
3078c81
add unit test for overlay code
oweno-tfwm Aug 29, 2023
d0218c7
add unit test - the test currently passes - but the results look all …
oweno-tfwm Aug 29, 2023
618ffa6
performance improvement - do evaluation outside data.table then inser…
oweno-tfwm Sep 4, 2023
8b6990d
make code more compact so more of function can be seen on one screen
oweno-tfwm Sep 4, 2023
14c2d45
move formatting to helper function which generically processes all ta…
oweno-tfwm Sep 4, 2023
79a175e
major overhaul to fix issues in timetable overlay rule processing - h…
oweno-tfwm Sep 4, 2023
2c7cd1f
move basic unit tests to their own file - add large number of unit te…
oweno-tfwm Sep 4, 2023
47def4b
rename write_gtfs to gtfs_write so it's consistent with other files
oweno-tfwm Sep 4, 2023
fa0e8c0
split atoc_export up because it's now far too long and my finger ache…
oweno-tfwm Sep 4, 2023
a40c02a
add file split from atoc_export
oweno-tfwm Sep 4, 2023
b6ff79d
up-rev version number, add author comment, fix warning in unit test
oweno-tfwm Sep 4, 2023
1b5110d
spelling mistake
oweno-tfwm Sep 4, 2023
1841b45
Merge branch 'master' of ssh://github.com/oweno-tfwm/UK2GTFS
oweno-tfwm Sep 4, 2023
d56d912
spelling
oweno-tfwm Sep 5, 2023
9b67120
spelling
oweno-tfwm Sep 5, 2023
07bce70
spelling
oweno-tfwm Sep 5, 2023
73727ec
spelling
oweno-tfwm Sep 5, 2023
ba4074f
fix bug contributed by my cat.
oweno-tfwm Sep 5, 2023
ac957d7
spelling
oweno-tfwm Sep 5, 2023
8a3315f
1) bug fix for duplicated schedule ID
oweno-tfwm Sep 5, 2023
8554bd5
tidy up logging messages
oweno-tfwm Sep 5, 2023
92818e8
updated comment after documentation build
oweno-tfwm Sep 5, 2023
14af9d9
fix warnings during tests
oweno-tfwm Sep 5, 2023
adffc4d
Merge branch 'master' of github.com:ITSLeeds/UK2GTFS into ITSLeeds-ma…
oweno-tfwm Sep 5, 2023
8a7b27f
don't think this should be under version control ?
oweno-tfwm Sep 5, 2023
67ba10a
update to read TIPLOC file in either lat/lon csv format or geometry file
oweno-tfwm Sep 5, 2023
43d4766
reduce double space to single space
oweno-tfwm Sep 6, 2023
a548652
swap lat and long round when reading from .rda file (was getting swap…
oweno-tfwm Sep 6, 2023
77a7e3d
stop update code blowing up as thread loads
oweno-tfwm Sep 6, 2023
8cc04fa
remove older style function and merge functionality to reduce number …
oweno-tfwm Sep 6, 2023
e6111fd
fix broken tests after merge of externalisation of data - remove comm…
oweno-tfwm Sep 7, 2023
ab1871a
bit more error checking - that we have stops before starting next par…
oweno-tfwm Sep 7, 2023
32b09e8
performance tuning
oweno-tfwm Sep 7, 2023
a4bf856
1) further performance, treat dates as int while building timetables
oweno-tfwm Sep 7, 2023
0f5daf9
make process dates as int work in child processes
oweno-tfwm Sep 7, 2023
7d3191b
comment update after investigating hand when >1 thread used
oweno-tfwm Sep 7, 2023
6354966
remove test code
oweno-tfwm Sep 8, 2023
69622fd
fix warning message typo
oweno-tfwm Sep 8, 2023
8c60dd3
more informative warning message about bad data
oweno-tfwm Sep 8, 2023
0c47eb7
tidy up exception handling
oweno-tfwm Sep 8, 2023
87210d6
1) decrease sensitivity of update check to only look at date instead …
oweno-tfwm Sep 8, 2023
f8ef3d4
documentation update
oweno-tfwm Sep 8, 2023
d02c8f4
added public_only and WTT flags to atco import consistent with NR import
oweno-tfwm Sep 8, 2023
344ed3e
rebuilt documentation after adding 2 parameters
oweno-tfwm Sep 8, 2023
db3781b
added missing dependency
oweno-tfwm Sep 8, 2023
c39bccc
reduce build warning about undeclared variables in data.table joins
oweno-tfwm Sep 8, 2023
3d57ad8
performance- create data.table in place instead of by copy, more heav…
oweno-tfwm Sep 8, 2023
8b47e7a
final performance optimisation
oweno-tfwm Sep 8, 2023
8d74249
typo
oweno-tfwm Sep 8, 2023
b7a3795
bug fix for strange data.table / Period memory allocation problem
oweno-tfwm Sep 9, 2023
db1a439
bring in seconds from WTT instead of throwing them away
oweno-tfwm Sep 9, 2023
5270ebf
further information on bug workaround
oweno-tfwm Sep 10, 2023
b074b8f
performance optimisation when copying row data
oweno-tfwm Sep 10, 2023
951da04
performance optimisations while reading input file
oweno-tfwm Sep 10, 2023
5d28d76
small performance improvement
oweno-tfwm Sep 10, 2023
745653b
documentation update
oweno-tfwm Sep 10, 2023
e7dcbbe
fix build warning about missing import
oweno-tfwm Sep 10, 2023
07995f8
add 'frequencies' to cleaning - otherwise resulting GTFS file can't b…
oweno-tfwm Sep 11, 2023
7f45b96
code tidy - mark everything as integer
oweno-tfwm Sep 18, 2023
5df39a9
explanatory comment why data is mangled
oweno-tfwm Sep 19, 2023
f32d620
better mapping of additional field onto field defined in GTFS standard
oweno-tfwm Sep 19, 2023
0ee68ea
add support for getting rail data from NAPTAN xml file since that has…
oweno-tfwm Sep 19, 2023
62f83cd
further little code tidy adding L decoration to numbers
oweno-tfwm Sep 19, 2023
83a4441
stop null easting/northing leaking out as invalid lat/long and ensure…
oweno-tfwm Sep 20, 2023
1b6e515
alter detection of ships so it actually works- real world data doesn'…
oweno-tfwm Sep 20, 2023
d889ee5
if stop doesn't exist in TIPLOC file - put tiploc code name into rout…
oweno-tfwm Sep 22, 2023
a148e70
1) when no public arrival time available fall back to WTT time then p…
oweno-tfwm Sep 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
Package: UK2GTFS
Type: Package
Title: Converts UK transport timetable datasets to GTFS format
Version: 0.2.1
Version: 1.0
Authors@R: c(
person("Malcolm", "Morgan", email = "[email protected]", role = c("aut","cre"),
comment = c(ORCID = "0000-0002-9488-9183")),
person("Adrian", "Schönig", role = c("ctb")),
person("Owen", "O'Neill", role = c("ctb"))
person("Owen", "O'Neill", email = "[email protected]", role = c("aut"),
comment = c(ORCID = "0009-0008-0595-3042"))
)
Maintainer: Malcolm Morgan <[email protected]>
Description: The UK uses a range of odd formats to store timetable data, this package converts them to the nice GTFS format.
Expand All @@ -30,14 +31,16 @@ Imports:
geodist,
httr,
iotools,
stringr,
sf,
parallel,
lubridate,
parallel,
purrr (>= 1.0),
pbapply,
readr (>= 2.0),
RcppSimdJson,
readr (>= 2.0),
sf,
stats,
stringi,
stringr,
xml2,
zip,
Suggests:
Expand Down
8 changes: 8 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# Generated by roxygen2: do not edit by hand

export(ATOC_shapes)
export(UK2GTFS_option_stopProcessingAtUid)
export(UK2GTFS_option_treatDatesAsInt)
export(UK2GTFS_option_updateCachedDataOnLibaryLoad)
export(as_data_table_naptan_stop_area)
export(as_data_table_naptan_stop_point)
export(atoc2gtfs)
export(dl_example_file)
export(get_bank_holidays)
export(get_naptan)
export(get_naptan_xml_doc)
export(gtfs_clean)
export(gtfs_clip)
export(gtfs_compress)
Expand Down Expand Up @@ -33,3 +39,5 @@ export(station2stops)
export(transxchange2gtfs)
export(transxchange_import)
export(update_data)
import(data.table)
importFrom(data.table,":=")
104 changes: 37 additions & 67 deletions R/atoc.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#' @param agency where to get agency.txt (see details)
#' @param shapes Logical, should shapes.txt be generated (default FALSE)
#' @param transfers Logical, should transfers.txt be generated (default TRUE)
#' @param missing_tiplocs Logical, if locations = tiplocs, then will check for
#' @param missing_tiplocs Logical, if true will check for
#' any missing tiplocs against the main file and add them.(default TRUE)
#' @param working_timetable Logical, should WTT times be used instead of public times (default FALSE)
#' @param public_only Logical, only return calls/services that are for public passenger pickup/set down (default TRUE)
#' @family main
#'
#' @details Locations
Expand Down Expand Up @@ -44,22 +46,9 @@ atoc2gtfs <- function(path_in,
agency = "atoc_agency",
shapes = FALSE,
transfers = TRUE,
missing_tiplocs = TRUE) {

if(inherits(locations,"character")){
if(locations == "tiplocs"){
load_data("tiplocs")
locations = tiplocs
}
}

if(inherits(agency,"character")){
if(agency == "atoc_agency"){
load_data("atoc_agency")
agency = atoc_agency
}
}

missing_tiplocs = TRUE,
working_timetable = FALSE,
public_only = TRUE) {
# Checkmates
checkmate::assert_character(path_in, len = 1)
checkmate::assert_file_exists(path_in)
Expand All @@ -73,6 +62,14 @@ atoc2gtfs <- function(path_in,
" This will take some time, make sure you use 'ncores' to enable multi-core processing"
))
}

agency = getCachedAgencyData( agency )

if ( !inherits(locations, "character") || "file"!=locations )
{
stops_sf = getCachedLocationData( locations )
}

# Is input a zip or a folder
if (grepl(".zip", path_in)) {
# Unzip
Expand Down Expand Up @@ -110,61 +107,29 @@ atoc2gtfs <- function(path_in,
file = files[grepl(".mca", files)],
silent = silent,
ncores = 1,
full_import = TRUE
full_import = TRUE,
working_timetable = working_timetable,
public_only = public_only
)


# Get the Station Locations
# Are locations provided?
if ("sf" %in% class(locations)) {
stops_sf <- cbind(locations, sf::st_coordinates(locations))
stops_sf <- as.data.frame(stops_sf)
stops_sf <- stops_sf[, c(
"stop_id", "stop_code", "stop_name",
"Y", "X"
)]
names(stops_sf) <- c(
"stop_id", "stop_code", "stop_name",
"stop_lat", "stop_lon"
)
stops_sf$stop_lat <- round(stops_sf$stop_lat, 5)
stops_sf$stop_lon <- round(stops_sf$stop_lon, 5)
}

# Should the file be checked
check_file <- FALSE
if("sf" %in% class(locations) & missing_tiplocs){
check_file <- TRUE
}

if ("character" %in% class(locations)) {
if(locations == "file"){
check_file <- TRUE
}
}

if (check_file) {
if ( TRUE==missing_tiplocs ||
( inherits(locations, "character") && "file"==locations ) )
{
msn <- importMSN(files[grepl(".msn", files)], silent = silent)
station <- msn[[1]]
TI <- mca[["TI"]]
stops.list <- station2stops(station = station, TI = TI)
stops_file <- stops.list[["stops"]]
rm(msn,TI,stops.list)
}

# Was a csv provided
if ("character" %in% class(locations)) {
if(locations != "file"){
checkmate::check_file_exists(locations)
stops_csv <- utils::read.csv(locations, stringsAsFactors = FALSE)
if( FALSE==missing_tiplocs || !exists("stops_sf") )
{
stops <- stops_file
}
}

# Chose Correct stops
if(exists("stops_csv")){
stops <- stops_csv
} else if(exists("stops_sf")){
if(missing_tiplocs == TRUE){
else
{
# Combine
stops_missing <- stops_file[!stops_file$stop_id %in% stops_sf$stop_id,]
if(nrow(stops_missing) > 0){
Expand All @@ -173,12 +138,11 @@ atoc2gtfs <- function(path_in,
} else {
stops <- stops_sf
}

} else {
stops <- stops_sf
}
} else if(exists("stops_file")){
stops <- stops_file
}
else
{
stops <- stops_sf
}


Expand All @@ -203,17 +167,23 @@ atoc2gtfs <- function(path_in,
# remove any unused stops
stops <- stops[stops$stop_id %in% stop_times$stop_id, ]

if ( nrow(stops)<=0 )
{
stop("Could not match any stops in input data to stop database.")
}


# Main Timetable Build
timetables <- schedule2routes(
stop_times = stop_times,
stops = stops,
schedule = schedule,
silent = silent,
ncores = ncores
ncores = ncores,
public_only = public_only
)
rm(schedule)
gc()
# load("data/atoc_agency.RData")

# TODO: check for stop_times that are not valid stops

Expand Down
Loading
Loading