Skip to content

Commit

Permalink
clear out arrival and departure times from enhanced feed if passthrou…
Browse files Browse the repository at this point in the history
…gh_time is present
  • Loading branch information
bfauble committed Oct 9, 2024
1 parent 987cd6b commit 1fcb904
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/concentrate/encoder/trip_updates_enhanced.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,22 @@ defmodule Concentrate.Encoder.TripUpdatesEnhanced do
drop_nil_values(%{
stop_id: StopTimeUpdate.stop_id(update),
stop_sequence: StopTimeUpdate.stop_sequence(update),
arrival:
stop_time_event(StopTimeUpdate.arrival_time(update), StopTimeUpdate.uncertainty(update)),
departure:
stop_time_event(StopTimeUpdate.departure_time(update), StopTimeUpdate.uncertainty(update)),
arrival: determine_arrival_value(update),
departure: determine_departure_value(update),
passthrough_time: StopTimeUpdate.passthrough_time(update),
schedule_relationship: schedule_relationship(StopTimeUpdate.schedule_relationship(update)),
boarding_status: StopTimeUpdate.status(update),
platform_id: StopTimeUpdate.platform_id(update)
})
end

defp determine_arrival_value(%{passthrough_time: nil} = update),
do: stop_time_event(StopTimeUpdate.arrival_time(update), StopTimeUpdate.uncertainty(update))

defp determine_arrival_value(_), do: nil

defp determine_departure_value(%{passthrough_time: nil} = update),
do: stop_time_event(StopTimeUpdate.departure_time(update), StopTimeUpdate.uncertainty(update))

defp determine_departure_value(_), do: nil
end
75 changes: 75 additions & 0 deletions test/concentrate/encoder/trip_updates_enhanced_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,80 @@ defmodule Concentrate.Encoder.TripUpdatesEnhancedTest do
trip = get_in(encoded, ["entity", Access.at(0), "trip_update", "trip"])
refute trip["update_type"]
end

test "includes passthrough_time" do
parsed = [
TripDescriptor.new(
trip_id: "trip",
route_id: "route",
direction_id: 0,
schedule_relationship: :ADDED,
revenue: true
),
StopTimeUpdate.new(
trip_id: "trip",
stop_id: "stop_1",
schedule_relationship: :SKIPPED,
departure_time: 100,
passthrough_time: 100
),
StopTimeUpdate.new(
trip_id: "trip",
stop_id: "stop_2",
schedule_relationship: :SKIPPED,
arrival_time: 200,
departure_time: 250,
passthrough_time: 200
),
StopTimeUpdate.new(
trip_id: "trip",
stop_id: "stop_3",
arrival_time: 300,
departure_time: 400
)
]

encoded = Jason.decode!(encode_groups(group(parsed)))

assert %{
"entity" => [
%{
"id" => "trip",
"trip_update" => %{
"trip" => %{
"direction_id" => 0,
"revenue" => true,
"route_id" => "route",
"trip_id" => "trip",
"last_trip" => false
},
"stop_time_update" => [
%{
"arrival" => %{"time" => 300},
"departure" => %{"time" => 400},
"stop_id" => "stop_3"
} = stu_3,
%{
"passthrough_time" => 200,
"schedule_relationship" => "SKIPPED",
"stop_id" => "stop_2"
} = stu_2,
%{
"passthrough_time" => 100,
"schedule_relationship" => "SKIPPED",
"stop_id" => "stop_1"
} = stu_1
]
}
}
]
} = encoded

refute Map.get(stu_1, "arrival")
refute Map.get(stu_1, "departure")
refute Map.get(stu_2, "arrival")
refute Map.get(stu_2, "departure")
refute Map.get(stu_3, "passthrough_time")
end
end
end

0 comments on commit 1fcb904

Please sign in to comment.