Skip to content

Commit

Permalink
dont use mapset
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyshull committed Jul 9, 2024
1 parent c6e8f83 commit 78dff58
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 23 deletions.
4 changes: 2 additions & 2 deletions lib/alerts/alert.ex
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ defmodule Alerts.Alert do
defp set_direction_id(%InformedEntity{} = entity) do
stop = Stops.Repo.get(entity.stop)

if entity.direction_id == MapSet.new() && stop.child_ids == [] do
if entity.direction_id == nil && stop.child_ids == [] do
direction_id =
stop.id
|> RoutePatterns.Repo.by_stop_id()
|> Enum.filter(&(&1.route_id == entity.route))
|> Enum.map(& &1.direction_id)
|> MapSet.new()
|> List.first()

%InformedEntity{entity | direction_id: direction_id}
else
Expand Down
4 changes: 2 additions & 2 deletions lib/alerts/informed_entity.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ defmodule Alerts.InformedEntity do
route_type: nil,
stop: nil,
trip: nil,
direction_id: MapSet.new(),
direction_id: nil,
facility: nil,
activities: @empty_activities

@type t :: %Alerts.InformedEntity{
activities: MapSet.t(activity),
direction_id: MapSet.t(integer()),
direction_id: 0 | 1 | nil,
facility: String.t() | nil,
route: String.t() | nil,
route_type: String.t() | nil,
Expand Down
5 changes: 0 additions & 5 deletions lib/alerts/informed_entity_set.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ defmodule Alerts.InformedEntitySet do
Map.put(set, :activities, map_set)
end

defp add_entity_field_to_set({:direction_id, %MapSet{} = value}, set) do
map_set = MapSet.union(set.direction_id, MapSet.new(value))
Map.put(set, :direction_id, map_set)
end

defp add_entity_field_to_set({key, value}, set) do
map_set = Map.get(set, key)
map_set = MapSet.put(map_set, value)
Expand Down
10 changes: 1 addition & 9 deletions lib/alerts/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,12 @@ defmodule Alerts.Parser do
route: entity["route"],
stop: entity["stop"],
trip: entity["trip"],
direction_id: do_direction_id(entity["direction_id"]),
direction_id: entity["direction_id"],
facility: entity["facility"],
activities: MapSet.new(Enum.map(entity["activities"], &do_activity/1))
}
end

defp do_direction_id(nil) do
MapSet.new()
end

defp do_direction_id(direction_id) do
MapSet.new([direction_id])
end

@spec do_activity(String.t()) :: Alerts.InformedEntity.activity_type()
defp do_activity("BOARD"), do: :board
defp do_activity("EXIT"), do: :exit
Expand Down
5 changes: 0 additions & 5 deletions lib/route_patterns/repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ defmodule RoutePatterns.Repo do
|> api_all()
end

def by_route_and_stop_id(route_id, stop_id) do
[route: route_id, stop: stop_id]
|> api_all()
end

@decorate cacheable(cache: @cache, on_error: :nothing, opts: [ttl: @ttl])
defp api_all(opts) do
case RoutePatternsApi.all(opts) do
Expand Down

0 comments on commit 78dff58

Please sign in to comment.