Skip to content

Commit 1b21018

Browse files
committed
fix 'gtfs_next_intervals' when stops in feed has duplicated ids
1 parent 1a775ec commit 1b21018

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: m4ra
22
Title: Many-to-Many Multi-Modal Routing Aggregator
3-
Version: 0.1.1.051
3+
Version: 0.1.1.052
44
Authors@R:
55
person(given = "Mark",
66
family = "Padgham",

R/gtfs.R

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ m4ra_gtfs_traveltimes <- function (gtfs,
122122
res_i [res_i == .Machine$integer.max] <- NA_integer_
123123

124124
rownames (res_i) <- stops
125-
colnames (res_i) <- gtfs$stops$stop_id
125+
colnames (res_i) <- gtfs$stop_ids$stop_id
126126

127127
# diag (res_i) <- 0L # diagonals set in "prepare-data" routines
128128

@@ -140,6 +140,13 @@ m4ra_gtfs_traveltimes <- function (gtfs,
140140

141141
#' Main function to calculate intervals to next fastest connection, called from
142142
#' `m4ra_gtfs_traveltimes()` if `next_interval = TRUE`.
143+
#'
144+
#' @param res Result of rcpp_traveltimes as a list of matrices (n, 3), where n
145+
#' is the number of "stop_id" values in gtfs$stops. The 'gtfs_next_start_times'
146+
#' routine returns a matrix with number of rows equal to 'nrow(gtfs$stop_ids)',
147+
#' which is generally less, because that is unique IDs only. The two have to
148+
#' reconciled below.
149+
#'
143150
#' @noRd
144151
gtfs_next_intervals <- function (gtfs, stops, res, start_time_limits) {
145152

@@ -173,6 +180,10 @@ gtfs_next_intervals <- function (gtfs, stops, res, start_time_limits) {
173180
)
174181
next_starts [next_starts <= 0] <- NA_integer_
175182

183+
# reduce dimension to only unique stops:
184+
index <- match (gtfs$stop_ids$stop_ids, gtfs$stops$stop_id)
185+
next_starts <- next_starts [, index]
186+
176187
first_starts <- lapply (res, function (i) as.vector (i [, 1]))
177188
first_starts <- do.call (rbind, first_starts)
178189
first_starts [first_starts == .Machine$integer.max | first_starts <= 0] <- NA_integer_
@@ -182,7 +193,7 @@ gtfs_next_intervals <- function (gtfs, stops, res, start_time_limits) {
182193
# diag (next_interval) <- NA_integer_
183194

184195
rownames (next_interval) <- stops
185-
colnames (next_interval) <- gtfs$stops$stop_id
196+
colnames (next_interval) <- gtfs$stop_ids$stop_id
186197

187198
return (next_interval)
188199
}

codemeta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"codeRepository": "https://github.com/UrbanAnalyst/m4ra",
88
"issueTracker": "https://github.com/UrbanAnalyst/m4ra/issues",
99
"license": "https://spdx.org/licenses/GPL-3.0",
10-
"version": "0.1.1.051",
10+
"version": "0.1.1.052",
1111
"programmingLanguage": {
1212
"@type": "ComputerLanguage",
1313
"name": "R",

0 commit comments

Comments
 (0)