From 7265fc5bfbfc6f9708ae7647204f3a1c2bafb28d Mon Sep 17 00:00:00 2001 From: Chris Jaekl Date: Tue, 14 Feb 2023 17:21:22 -0500 Subject: [PATCH] When counting trips, only count the trip for that route from the stop where it originates, to avoid double-counting trips. --- lib/gtfs.rb | 8 ++++---- lib/stats.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/gtfs.rb b/lib/gtfs.rb index 053f482..17cfc27 100644 --- a/lib/gtfs.rb +++ b/lib/gtfs.rb @@ -85,12 +85,12 @@ class Gtfs private - def trips_for_stop_code(stop_code:, date_hash:) + def trips_for_stop_code(stop_code:, date_hash:, originating_only: false) stop_ids = @db.query("SELECT stop_id FROM stops WHERE stop_code=?", stop_code).to_a.map do |row| row.first end - trips_for_stop_ids(stop_ids: stop_ids, date_hash: date_hash) + trips_for_stop_ids(stop_ids: stop_ids, date_hash: date_hash, originating_only: originating_only) end def trips_for_stop_ids(stop_ids:, date_hash:, originating_only: false) @@ -148,7 +148,7 @@ class Gtfs end.to_h end - def trips_for_stop_name(stop_name:, date_hash:) + def trips_for_stop_name(stop_name:, date_hash:, originating_only: false) result = {} base_name = stop_name.upcase @@ -163,7 +163,7 @@ class Gtfs row.first end - trips_for_stop_ids(stop_ids: stop_ids, date_hash: date_hash) + trips_for_stop_ids(stop_ids: stop_ids, date_hash: date_hash, originating_only: originating_only) end def calendar diff --git a/lib/stats.rb b/lib/stats.rb index 5811fe7..a67b57e 100644 --- a/lib/stats.rb +++ b/lib/stats.rb @@ -66,7 +66,7 @@ class Stats print "." $stdout.flush - route_trips = @gtfs.trips(stop_id: stop_id, date_hash: date_hash).map do |k, v| + route_trips = @gtfs.trips(stop_id: stop_id, date_hash: date_hash, originating_only: true).map do |k, v| [ k.first, v.map do |x| -- 2.39.2