Skip to content

Commit

Permalink
StatsHandler : gère cas nil pour vehicle_types en GBFS (#4316)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAugusti authored Nov 15, 2024
1 parent d81beb7 commit 05967ff
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion apps/transport/lib/transport/stats_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,12 @@ defmodule Transport.StatsHandler do
@doc """
iex> gbfs_vehicle_types_stats([%{"vehicle_types" => ["bicycle", "scooter"]}, %{"vehicle_types" => ["bicycle"]}])
%{gbfs_vehicle_type_bicycle_count: 2, gbfs_vehicle_type_scooter_count: 1}
iex> gbfs_vehicle_types_stats([%{"vehicle_types" => ["bicycle"]}, %{"vehicle_types" => nil}])
%{gbfs_vehicle_type_bicycle_count: 1}
"""
def gbfs_vehicle_types_stats(rows) do
rows
|> Enum.flat_map(& &1["vehicle_types"])
|> Enum.flat_map(&(&1["vehicle_types"] || []))
|> Enum.frequencies()
|> Map.new(fn {k, v} -> {String.to_atom("gbfs_vehicle_type_#{k}_count"), v} end)
end
Expand Down

0 comments on commit 05967ff

Please sign in to comment.