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

feat: cancel trips with a boarding status of Canceled #364

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading