Skip to content

Commit

Permalink
GBFSMetadata : retire les stations avec données irréalistes (#4317)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAugusti authored Nov 18, 2024
1 parent 05967ff commit cf5337a
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 50 deletions.
20 changes: 19 additions & 1 deletion apps/shared/lib/gbfs_metadata.ex
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ defmodule Transport.Shared.GBFSMetadata do
with {:feed_exists, true} <- {:feed_exists, not is_nil(feed_url)},
{:ok, %HTTPoison.Response{status_code: 200, body: body}} <- http_client().get(feed_url),
{:ok, json} <- Jason.decode(body) do
stations = json["data"]["stations"]
stations = Enum.reject(json["data"]["stations"], &unrealistic_station_data?/1)

%{
nb_stations: Enum.count(stations),
Expand Down Expand Up @@ -231,6 +231,24 @@ defmodule Transport.Shared.GBFSMetadata do
end
end

@doc """
Is the number of docks or vehicles unrealistic for this station? (more than 500 docks or vehicles).
If yes, used to ignore this station to maintain relevant statistics.
iex> unrealistic_station_data?(%{"num_vehicles_available" => 1_000})
true
iex> unrealistic_station_data?(%{"num_docks_available" => 1_000})
true
iex> unrealistic_station_data?(%{"num_docks_available" => 20, "num_vehicles_available" => 10})
false
"""
def unrealistic_station_data?(%{} = data) do
data
|> Map.take(["num_vehicles_available", "num_bikes_available", "num_docks_available"])
|> Map.values()
|> Enum.any?(&(&1 >= 500))
end

# As of 3.0
defp vehicles_available(%{"num_vehicles_available" => num_vehicles_available}), do: num_vehicles_available
# Before 3.0
Expand Down
128 changes: 79 additions & 49 deletions apps/shared/test/fixtures/gbfs/station_status.2.2.json
Original file line number Diff line number Diff line change
@@ -1,54 +1,84 @@
{
"last_updated": 1609866247,
"ttl": 0,
"version": "2.2",
"data": {
"stations": [
"last_updated":1609866247,
"ttl":0,
"version":"2.2",
"data":{
"stations":[
{
"station_id": "station 1",
"is_installed": true,
"is_renting": true,
"is_returning": true,
"last_reported": 1609866125,
"num_docks_available": 3,
"vehicle_docks_available": [{
"vehicle_type_ids": ["abc123"],
"count": 2
}, {
"vehicle_type_ids": ["def456"],
"count": 1
}],
"num_bikes_available": 1,
"vehicle_types_available": [{
"vehicle_type_id": "abc123",
"count": 1
}, {
"vehicle_type_id": "def456",
"count": 0
}]
}, {
"station_id": "station 2",
"is_installed": true,
"is_renting": true,
"is_returning": true,
"last_reported": 1609866106,
"num_docks_available": 8,
"num_docks_disabled": 1,
"vehicle_docks_available": [{
"vehicle_type_ids": ["abc123"],
"count": 6
}, {
"vehicle_type_ids": ["def456"],
"count": 2
}],
"num_bikes_available": 6,
"vehicle_types_available": [{
"vehicle_type_id": "abc123",
"count": 2
}, {
"vehicle_type_id": "def456",
"count": 4
}]
"station_id":"station 1",
"is_installed":true,
"is_renting":true,
"is_returning":true,
"last_reported":1609866125,
"num_docks_available":3,
"vehicle_docks_available":[
{
"vehicle_type_ids":[
"abc123"
],
"count":2
},
{
"vehicle_type_ids":[
"def456"
],
"count":1
}
],
"num_bikes_available":1,
"vehicle_types_available":[
{
"vehicle_type_id":"abc123",
"count":1
},
{
"vehicle_type_id":"def456",
"count":0
}
]
},
{
"station_id":"station 2",
"is_installed":true,
"is_renting":true,
"is_returning":true,
"last_reported":1609866106,
"num_docks_available":8,
"num_docks_disabled":1,
"vehicle_docks_available":[
{
"vehicle_type_ids":[
"abc123"
],
"count":6
},
{
"vehicle_type_ids":[
"def456"
],
"count":2
}
],
"num_bikes_available":6,
"vehicle_types_available":[
{
"vehicle_type_id":"abc123",
"count":2
},
{
"vehicle_type_id":"def456",
"count":4
}
]
},
{
"station_id":"station 3",
"is_installed":true,
"is_renting":true,
"is_returning":true,
"last_reported":1609866106,
"num_docks_available":999999,
"num_bikes_available":555555
}
]
}
Expand Down

0 comments on commit cf5337a

Please sign in to comment.