Skip to content

Commit

Permalink
feat: update schedule relationship of Cancelled STUs
Browse files Browse the repository at this point in the history
  • Loading branch information
lemald committed Jan 10, 2025
1 parent 8548c96 commit 2ca6045
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/concentrate/parser/gtfs_realtime_enhanced.ex
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,19 @@ defmodule Concentrate.Parser.GTFSRealtimeEnhanced do

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

schedule_relationship =
if boarding_status == "Cancelled" do
:SKIPPED
else
schedule_relationship(Map.get(stu, "schedule_relationship"))
end

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")),
schedule_relationship: schedule_relationship,
arrival_time: arrival_time,
departure_time: departure_time,
passthrough_time: Map.get(stu, "passthrough_time"),
Expand Down
14 changes: 14 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,20 @@ 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"
}
]
}

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

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

0 comments on commit 2ca6045

Please sign in to comment.