From 93e8209db8ad2f6da8247a32954edf794e7ff892 Mon Sep 17 00:00:00 2001 From: Cristen Jones Date: Tue, 3 Oct 2023 16:33:22 -0400 Subject: [PATCH] fix(StopController): remove some route patterns - 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 --- .../lib/site_web/controllers/stop_controller.ex | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/apps/site/lib/site_web/controllers/stop_controller.ex b/apps/site/lib/site_web/controllers/stop_controller.ex index 2c74614b98..5ddeb0dbb4 100644 --- a/apps/site/lib/site_web/controllers/stop_controller.ex +++ b/apps/site/lib/site_web/controllers/stop_controller.ex @@ -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 @@ -189,6 +190,7 @@ defmodule SiteWeb.StopController do defp route_patterns_by_route_and_headsign(stop_id) do stop_id |> RoutePatterns.Repo.by_stop_id() + |> Enum.reject(¬_serving_today?/1) |> Enum.reject(&ends_at?(&1, stop_id)) |> Enum.map(&add_polyline/1) |> Enum.group_by(& &1.route_id) @@ -196,6 +198,20 @@ defmodule SiteWeb.StopController do |> 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