Skip to content

Commit

Permalink
remove fallback parsing of uncertainty if update_type not present
Browse files Browse the repository at this point in the history
  • Loading branch information
bfauble committed Apr 5, 2024
1 parent 282e28e commit 0d56d09
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 4 additions & 6 deletions lib/concentrate/parser/gtfs_realtime_enhanced.ex
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,12 @@ defmodule Concentrate.Parser.GTFSRealtimeEnhanced do

defp time_from_event(nil, _), do: {nil, nil}

defp time_from_event(%{"time" => time} = map, %{"update_type" => update_type}) do
case update_type do
nil -> {time, Map.get(map, "uncertainty", nil)}
update_type -> {time, calculate_uncertainty(update_type)}
end
defp time_from_event(%{"time" => time}, %{"update_type" => update_type})
when not is_nil(update_type) do
{time, calculate_uncertainty(update_type)}
end

defp time_from_event(%{"time" => time} = map, _), do: {time, Map.get(map, "uncertainty", nil)}
defp time_from_event(%{"time" => time}, _), do: {time, nil}

defp calculate_uncertainty("mid_trip"), do: 60
defp calculate_uncertainty("at_terminal"), do: 120
Expand Down
4 changes: 2 additions & 2 deletions test/concentrate/parser/gtfs_realtime_enhanced_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ defmodule Concentrate.Parser.GTFSRealtimeEnhancedTest do
assert TripDescriptor.revenue(td) == true
end

test "uses arrival/departure uncertainty values if update_type is not present" do
test "update_type is nil if update_type is not present" do
update = %{
"trip" => %{
"trip_id" => "trip",
Expand All @@ -387,7 +387,7 @@ defmodule Concentrate.Parser.GTFSRealtimeEnhancedTest do
}

[_td, stu] = decode_trip_update(update, %Options{})
assert stu.uncertainty == 500
assert stu.uncertainty == nil
end

test "decodes mid_trip update_type to determine uncertainty value" do
Expand Down

0 comments on commit 0d56d09

Please sign in to comment.