From 0d56d09cb928a3fc4cfbf3e88545ea11a2c74585 Mon Sep 17 00:00:00 2001 From: Brian Fauble Date: Fri, 5 Apr 2024 14:01:47 -0600 Subject: [PATCH] remove fallback parsing of uncertainty if update_type not present --- lib/concentrate/parser/gtfs_realtime_enhanced.ex | 10 ++++------ .../concentrate/parser/gtfs_realtime_enhanced_test.exs | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/concentrate/parser/gtfs_realtime_enhanced.ex b/lib/concentrate/parser/gtfs_realtime_enhanced.ex index b6b7efd4..d45c790d 100644 --- a/lib/concentrate/parser/gtfs_realtime_enhanced.ex +++ b/lib/concentrate/parser/gtfs_realtime_enhanced.ex @@ -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 diff --git a/test/concentrate/parser/gtfs_realtime_enhanced_test.exs b/test/concentrate/parser/gtfs_realtime_enhanced_test.exs index 882d494e..7ca27ab0 100644 --- a/test/concentrate/parser/gtfs_realtime_enhanced_test.exs +++ b/test/concentrate/parser/gtfs_realtime_enhanced_test.exs @@ -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", @@ -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