Skip to content

Commit

Permalink
ignore stop_timezone when calculating arrivals/departures πŸ›βœ…
Browse files Browse the repository at this point in the history
Apparently, stop_timezone was only ever intended for displaying local date+time.
The current operating practice has been clarified in google/transit#322.
  • Loading branch information
derhuerst committed Aug 2, 2023
1 parent e03a6dd commit 7615102
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
16 changes: 6 additions & 10 deletions lib/stop_times.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ WITH stop_times_based AS NOT MATERIALIZED (
drop_off_type,
shape_dist_traveled,
timepoint,
coalesce(stations.stop_timezone, stops.stop_timezone, agency.agency_timezone) as tz,
agency.agency_timezone as tz,
arrival_time,
(
make_timestamptz(
date_part('year', "date")::int,
date_part('month', "date")::int,
date_part('day', "date")::int,
12, 0, 0,
coalesce(stations.stop_timezone, stops.stop_timezone, agency.agency_timezone)
agency.agency_timezone
)
- INTERVAL '12 hours'
+ arrival_time
Expand All @@ -199,7 +199,7 @@ WITH stop_times_based AS NOT MATERIALIZED (
date_part('month', "date")::int,
date_part('day', "date")::int,
12, 0, 0,
coalesce(stations.stop_timezone, stops.stop_timezone, agency.agency_timezone)
agency.agency_timezone
)
- INTERVAL '12 hours'
+ departure_time
Expand Down Expand Up @@ -365,7 +365,7 @@ WITH stop_times_based AS NOT MATERIALIZED (
date_part('month'::text, "date")::integer,
date_part('day'::text, "date")::integer,
12, 0, 0::double precision,
coalesce(from_station_tz, from_stop_tz, agency_timezone)
agency_timezone
) - '12:00:00'::interval + departure_time AS t_departure,
departure_time,
from_stop_sequence,
Expand All @@ -380,7 +380,7 @@ WITH stop_times_based AS NOT MATERIALIZED (
date_part('month'::text, "date")::integer,
date_part('day'::text, "date")::integer,
12, 0, 0::double precision,
coalesce(to_station_tz, to_stop_tz, agency_timezone)
agency_timezone
) - '12:00:00'::interval + arrival_time AS t_arrival,
arrival_time,
to_drop_off_type,
Expand All @@ -404,10 +404,8 @@ WITH stop_times_based AS NOT MATERIALIZED (
from_stops.stop_id as from_stop_id,
from_stops.stop_name as from_stop_name,
from_stops.stop_timezone as from_stop_tz,
from_stations.stop_id as from_station_id,
from_stations.stop_name as from_station_name,
from_stations.stop_timezone as from_station_tz,
stop_times.stop_headsign as from_stop_headsign,
stop_times.pickup_type as from_pickup_type,
stop_times.departure_time as departure_time,
Expand All @@ -423,10 +421,8 @@ WITH stop_times_based AS NOT MATERIALIZED (
to_stop_times.stop_headsign as to_stop_headsign,
to_stop_times.stop_id as to_stop_id,
to_stops.stop_name as to_stop_name,
to_stops.stop_timezone as to_stop_tz,
to_stations.stop_id as to_station_id,
to_stations.stop_name as to_station_name,
to_stations.stop_timezone as to_station_tz
to_stations.stop_name as to_station_name
FROM "${opt.schema}".trips
LEFT JOIN "${opt.schema}".routes ON trips.route_id = routes.route_id
LEFT JOIN "${opt.schema}".agency ON (
Expand Down
14 changes: 7 additions & 7 deletions test/amtrak-gtfs-2021-10-06.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ and date = '2021-11-26'
order by t_arrival
EOF)
# 2021-11-26T15:15:00-06:00
# 2021-11-26T15:15:00-05:00
arr1=$(psql --csv -t -c "$query" | head -n 1)
if [[ "$arr1" != "1637961300" ]]; then
if [[ "$arr1" != "1637957700" ]]; then
echo "invalid 1st t_arrival: $arr1" 1>&2
exit 1
fi
# 2021-11-27T13:45:00-06:00
# 2021-11-27T13:45:00-05:00
arrN=$(psql --csv -t -c "$query" | tail -n 1)
if [[ "$arrN" != "1638042300" ]]; then
if [[ "$arrN" != "1638038700" ]]; then
echo "invalid 2nd t_arrival: $arrN" 1>&2
exit 1
fi
Expand Down Expand Up @@ -86,14 +86,14 @@ SELECT nr_of_active_trips
FROM amtrak.stats_active_trips_by_hour
WHERE "hour" = '2021-11-26T04:00-05'
EOF)
# Note: I'm not sure if 146 is correct, but it is in the right ballpark. πŸ™ˆ
# The following query yields 175 connections, and it doesn't contain those who depart earlier and arrive later.
# Note: I'm not sure if 127 is correct, but it is in the right ballpark. πŸ™ˆ
# The following query yields 150 connections, and it doesn't contain those who depart earlier and arrive later.
# SELECT DISTINCT ON (trip_id) *
# FROM amtrak.connections
# WHERE t_departure >= '2021-11-26T02:00-05'
# AND t_arrival <= '2021-11-26T06:00-05'
nrOfActiveTrips=$(psql --csv -t -c "$nrOfActiveTripsQuery" | tail -n 1)
if [[ "$nrOfActiveTrips" != "146" ]]; then
if [[ "$nrOfActiveTrips" != "127" ]]; then
echo "unexpected no. of active trips at 2021-11-26T04:00-05: $nrOfActiveTrips" 1>&2
exit 1
fi

0 comments on commit 7615102

Please sign in to comment.