Skip to content

Commit

Permalink
Merge branch 'main' into pk/crowding-read-loop-selection
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulJKim committed Aug 31, 2023
2 parents 3b5e949 + 72220b4 commit 9346ac7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 87 deletions.
20 changes: 9 additions & 11 deletions lib/engine/locations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,19 @@ defmodule Engine.Locations do
trip_id: location["vehicle"]["trip"]["trip_id"],
consist: location["vehicle"]["vehicle"]["consist"],
multi_carriage_details:
location["vehicle"]["multi_carriage_details"] &&
Enum.map(
location["vehicle"]["multi_carriage_details"],
&parse_carriage_details/1
)
parse_carriage_details(location["vehicle"]["multi_carriage_details"] || [])
}
end

defp parse_carriage_details(multi_carriage_details) do
%Locations.CarriageDetails{
label: multi_carriage_details["label"],
occupancy_status: occupancy_status_to_atom(multi_carriage_details["occupancy_status"]),
occupancy_percentage: multi_carriage_details["occupancy_percentage"],
carriage_sequence: multi_carriage_details["carriage_sequence"]
}
Enum.map(multi_carriage_details, fn carriage_details ->
%Locations.CarriageDetails{
label: carriage_details["label"],
occupancy_status: occupancy_status_to_atom(carriage_details["occupancy_status"]),
occupancy_percentage: carriage_details["occupancy_percentage"],
carriage_sequence: carriage_details["carriage_sequence"]
}
end)
end

defp occupancy_status_to_atom(status) do
Expand Down
13 changes: 4 additions & 9 deletions lib/predictions/predictions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,11 @@ defmodule Predictions.Predictions do
end

@spec sufficient_certainty?(map(), String.t()) :: boolean()
defp sufficient_certainty?(_stop_time_event, route_id)
when route_id in ["Mattapan", "Green-B", "Green-C", "Green-D", "Green-E"] do
true
defp sufficient_certainty?(stop_time_event, route_id) when route_id in ["Red"] do
is_nil(stop_time_event["uncertainty"]) or stop_time_event["uncertainty"] < 120
end

defp sufficient_certainty?(stop_time_event, _route_id) do
if Application.get_env(:realtime_signs, :filter_uncertain_predictions?) do
is_nil(stop_time_event["uncertainty"]) or stop_time_event["uncertainty"] <= 300
else
true
end
defp sufficient_certainty?(_stop_time_event, _route_id) do
true
end
end
68 changes: 1 addition & 67 deletions test/predictions/predictions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ defmodule Predictions.PredictionsTest do
"timestamp" => nil,
"trip" => %{
"direction_id" => 0,
"route_id" => "Blue",
"route_id" => "Red",
"schedule_relationship" => "SCHEDULED",
"start_date" => "20170329",
"start_time" => nil,
Expand All @@ -909,72 +909,6 @@ defmodule Predictions.PredictionsTest do
assert predictions_map == %{}
end

test "doesn't filter predictions with high uncertainty when feature is off" do
reassign_env(:filter_uncertain_predictions?, false)

feed_message = %{
"entity" => [
%{
"alert" => nil,
"id" => "1490783458_32568935",
"is_deleted" => false,
"trip_update" => %{
"delay" => nil,
"stop_time_update" => [
%{
"arrival" => %{
"delay" => nil,
"time" => 1_491_570_110,
"uncertainty" => 360
},
"departure" => %{
"delay" => nil,
"time" => 1_491_570_120,
"uncertainty" => 360
},
"schedule_relationship" => "SCHEDULED",
"stop_id" => "70063",
"stop_sequence" => 1,
"stops_away" => 1,
"stopped?" => true,
"boarding_status" => "Stopped 1 stop away"
}
],
"timestamp" => nil,
"trip" => %{
"direction_id" => 0,
"route_id" => "Red",
"schedule_relationship" => "SCHEDULED",
"start_date" => "20170329",
"start_time" => nil,
"trip_id" => "32568935"
},
"vehicle" => %{
"id" => "R-54639F6C",
"label" => "1631",
"license_plate" => nil
}
},
"vehicle" => nil
}
],
"header" => %{
"gtfs_realtime_version" => "1.0",
"incrementality" => "FULL_DATASET",
"timestamp" => 1_490_783_458
}
}

assert {%{
{"70063", 0} => [
%Predictions.Prediction{
seconds_until_arrival: 110,
seconds_until_departure: 120
}
]
}, _} = get_all(feed_message, @current_time)
end

test "doesn't filter out uncertain light rail predictions" do
reassign_env(:filter_uncertain_predictions?, true)

Expand Down

0 comments on commit 9346ac7

Please sign in to comment.