Skip to content

Commit

Permalink
hotfix(TimetableController): ensure termini stops stay at the end (#2017
Browse files Browse the repository at this point in the history
)
  • Loading branch information
thecristen authored Apr 29, 2024
1 parent 4bbc4a3 commit 915cae3
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/dotcom_web/controllers/schedule/timetable_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,7 @@ defmodule DotcomWeb.ScheduleController.TimetableController do
all_stops =
remove_unused_stops(all_stops, schedules)
|> Enum.sort_by(fn stop ->
{zone_to_sortable(stop.zone, direction_id),
trip_schedule_sequence_for_stop(stop, schedules)}
{zone_to_sortable(stop, direction_id), trip_schedule_sequence_for_stop(stop, schedules)}
end)

%{
Expand All @@ -274,10 +273,22 @@ defmodule DotcomWeb.ScheduleController.TimetableController do
}
end

defp zone_to_sortable("1A", _), do: 0
defp zone_to_sortable(zone, 0) when is_binary(zone), do: String.to_integer(zone)
defp zone_to_sortable(zone, 1) when is_binary(zone), do: -String.to_integer(zone)
defp zone_to_sortable(_, _), do: 0
# Override North and South Station zones from 1A to 0
defp zone_to_sortable(%Stops.Stop{id: stop_id}, _direction_id)
when stop_id in ["place-sstat", "place-north"],
do: 0.0

defp zone_to_sortable(%Stops.Stop{zone: nil}, _direction_id), do: 0.0

defp zone_to_sortable(%Stops.Stop{zone: "1A"}, direction_id),
do: zone_to_sortable("0.5", direction_id)

defp zone_to_sortable(%Stops.Stop{zone: zone}, direction_id),
do: zone_to_sortable("#{zone}.0", direction_id)

defp zone_to_sortable(zone, 0) when is_binary(zone), do: String.to_float(zone)
defp zone_to_sortable(zone, 1) when is_binary(zone), do: -String.to_float(zone)
defp zone_to_sortable(_, _), do: 0.0

# translate each stop into a general stop_sequence value. a given stop will
# have a different value for stop_sequence depending on the other stops in the
Expand Down

0 comments on commit 915cae3

Please sign in to comment.