Skip to content

Commit

Permalink
feat: cancel trips with a boarding status of Canceled (#364)
Browse files Browse the repository at this point in the history
* feat: cancel trips with a boarding status of Canceled

* Revert "feat: cancel trips with a boarding status of Canceled"

This reverts commit fb1c3e4.

* feat: update schedule relationship of Cancelled STUs

* fix: skip STU in the same way we do for other modes
  • Loading branch information
lemald authored Jan 29, 2025
1 parent f4c8a43 commit 88d5104
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
36 changes: 23 additions & 13 deletions lib/concentrate/parser/gtfs_realtime_enhanced.ex
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,29 @@ defmodule Concentrate.Parser.GTFSRealtimeEnhanced do

boarding_status = decode_boarding_status(Map.get(stu, "boarding_status"))

StopTimeUpdate.new(
trip_id:
if(descriptor = Map.get(trip_update, "trip"), do: Map.get(descriptor, "trip_id")),
stop_id: Map.get(stu, "stop_id"),
stop_sequence: Map.get(stu, "stop_sequence"),
schedule_relationship: schedule_relationship(Map.get(stu, "schedule_relationship")),
arrival_time: arrival_time,
departure_time: departure_time,
passthrough_time: Map.get(stu, "passthrough_time"),
uncertainty: arrival_uncertainty || departure_uncertainty,
status: boarding_status,
platform_id: Map.get(stu, "platform_id")
)
stop_time_update =
StopTimeUpdate.new(
trip_id:
if(descriptor = Map.get(trip_update, "trip"),
do: Map.get(descriptor, "trip_id")
),
stop_id: Map.get(stu, "stop_id"),
stop_sequence: Map.get(stu, "stop_sequence"),
schedule_relationship:
schedule_relationship(Map.get(stu, "schedule_relationship")),
arrival_time: arrival_time,
departure_time: departure_time,
passthrough_time: Map.get(stu, "passthrough_time"),
uncertainty: arrival_uncertainty || departure_uncertainty,
status: boarding_status,
platform_id: Map.get(stu, "platform_id")
)

if boarding_status == "Cancelled" do
StopTimeUpdate.skip(stop_time_update)
else
stop_time_update
end
end

td ++ stop_updates
Expand Down
2 changes: 1 addition & 1 deletion lib/concentrate/stop_time_update.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule Concentrate.StopTimeUpdate do
@doc """
Marks the update as skipped (when the stop is closed, for example).
"""
@spec skip(%__MODULE__{}) :: t
@spec skip(%__MODULE__{} | t) :: t
def skip(%__MODULE__{} = stu) do
%{stu | schedule_relationship: :SKIPPED, arrival_time: nil, departure_time: nil, status: nil}
end
Expand Down
18 changes: 18 additions & 0 deletions test/concentrate/parser/gtfs_realtime_enhanced_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,24 @@ defmodule Concentrate.Parser.GTFSRealtimeEnhancedTest do
assert StopTimeUpdate.status(stop_update) == "UNIQUE STATUS"
end

test "handles cancelled status" do
update = %{
"trip" => %{},
"stop_time_update" => [
%{
"boarding_status" => "CANCELLED",
"arrival" => nil,
"departure" => %{"time" => 1234}
}
]
}

[_td, stop_update] = decode_trip_update(update, %Options{})
assert StopTimeUpdate.schedule_relationship(stop_update) == :SKIPPED
assert stop_update |> StopTimeUpdate.arrival_time() |> is_nil()
assert stop_update |> StopTimeUpdate.departure_time() |> is_nil()
end

test "can handle platform id information" do
update = %{
"trip" => %{},
Expand Down

0 comments on commit 88d5104

Please sign in to comment.