Skip to content

Commit

Permalink
fix(StopController): remove some route patterns
Browse files Browse the repository at this point in the history
- remove route patterns associated to a service that is not running today
- except when it's a canonical service... let that route pattern through anyway
  • Loading branch information
thecristen committed Oct 3, 2023
1 parent 9ac9ef1 commit 93e8209
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions apps/site/lib/site_web/controllers/stop_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule SiteWeb.StopController do
alias Site.JsonHelpers
alias Routes.{Group, Route}
alias RoutePatterns.RoutePattern
alias Services.Service
alias Site.TransitNearMe
alias SiteWeb.AlertView
alias SiteWeb.PartialView.HeaderTab
Expand Down Expand Up @@ -189,13 +190,28 @@ defmodule SiteWeb.StopController do
defp route_patterns_by_route_and_headsign(stop_id) do
stop_id
|> RoutePatterns.Repo.by_stop_id()
|> Enum.reject(&not_serving_today?/1)
|> Enum.reject(&ends_at?(&1, stop_id))
|> Enum.map(&add_polyline/1)
|> Enum.group_by(& &1.route_id)
|> Enum.map(fn {k, v} -> {k, Enum.group_by(v, & &1.headsign)} end)
|> Map.new()
end

@spec not_serving_today?(RoutePattern.t()) :: boolean()
defp not_serving_today?(%RoutePattern{service_id: service_id})
when is_binary(service_id) and service_id != "canonical" do
case Services.Repo.by_id(service_id) do
%Service{} = service ->
not Service.serves_date?(service, Timex.today())

_ ->
false
end
end

defp not_serving_today?(_), do: false

defp ends_at?(%RoutePattern{stop_ids: stop_ids}, stop_id) when is_list(stop_ids) do
with last_stop_id <- List.last(stop_ids),
%Stop{child_ids: child_ids} <- Stops.Repo.get(stop_id) do
Expand Down

0 comments on commit 93e8209

Please sign in to comment.