Skip to content

Commit

Permalink
NewDatagouvDatasetsJob : gérer JDD non identifiés (#4334)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAugusti authored Nov 25, 2024
1 parent 945e2a6 commit affa80f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 2 additions & 6 deletions apps/transport/lib/jobs/new_datagouv_datasets_job.ex
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,8 @@ defmodule Transport.Jobs.NewDatagouvDatasetsJob do
defp string_matches?(nil, _rule), do: false

defp string_matches?(str, %{formats: formats, tags: tags} = _rule) when is_binary(str) do
str
|> String.downcase()
|> String.split(" ")
|> MapSet.new()
|> MapSet.intersection(MapSet.union(formats, tags))
|> MapSet.size() > 0
searches = MapSet.union(formats, tags) |> MapSet.to_list()
str |> String.downcase() |> String.contains?(searches)
end

defp tags_is_relevant?(%{"tags" => tags} = _dataset, rule) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ defmodule Transport.Test.Transport.Jobs.NewDatagouvDatasetsJobTest do
|> Enum.filter(&NewDatagouvDatasetsJob.dataset_is_relevant?(dataset, &1))
|> case do
[rule] -> rule
[_ | _] = rules -> Enum.sort_by(rules, & &1.category)
_ -> :no_match
end
end

assert [%{category: "Freefloating"}, %{category: "Vélo et stationnements"}] =
relevant_fn.(%{base | "title" => "Vélos en libre service"})

assert %{category: "IRVE"} = relevant_fn.(%{base | "title" => "Borne de recharge Lidl"})
assert %{category: "Transport en commun"} = relevant_fn.(%{base | "title" => "GTFS de Dijon"})
assert %{category: "Transport en commun"} = relevant_fn.(%{base | "description" => "GTFS de Dijon"})
assert %{category: "Transport en commun"} = relevant_fn.(%{base | "tags" => [Ecto.UUID.generate(), "gtfs"]})
Expand Down

0 comments on commit affa80f

Please sign in to comment.