Skip to content

Commit 8812cef

Browse files
authored
Suppression de la consolidation "brute" IRVE et renommage de la consolidation transport (#5529)
1 parent bbab8cf commit 8812cef

20 files changed

Lines changed: 121 additions & 504 deletions

apps/transport/lib/irve/simple_consolidation.ex renamed to apps/transport/lib/irve/consolidation.ex

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmodule Transport.IRVE.SimpleConsolidation do
1+
defmodule Transport.IRVE.Consolidation do
22
@moduledoc """
33
This module:
44
- takes the list of relevant IRVE resources from data.gouv.fr,
@@ -38,7 +38,7 @@ defmodule Transport.IRVE.SimpleConsolidation do
3838
# If a task times out, we get {:exit, :timeout} instead of {:ok, result} and the following line will crash.
3939
# This is intentional, we want to be aware of such timeouts.
4040
|> Stream.map(fn {:ok, result} -> result end)
41-
|> Stream.map(&Transport.IRVE.SimpleReportItem.from_result/1)
41+
|> Stream.map(&Transport.IRVE.ReportItem.from_result/1)
4242
|> maybe_log_items(debug)
4343
|> Enum.into([])
4444

@@ -54,7 +54,7 @@ defmodule Transport.IRVE.SimpleConsolidation do
5454

5555
write_consolidated_file(consolidated_df, @consolidated_file_base_name, destination)
5656

57-
Logger.info("IRVE simple consolidation process completed.")
57+
Logger.info("IRVE consolidation process completed.")
5858
{:ok, report}
5959
end
6060

@@ -75,7 +75,7 @@ defmodule Transport.IRVE.SimpleConsolidation do
7575

7676
def resource_list do
7777
Transport.IRVE.Extractor.datagouv_resources()
78-
|> Transport.IRVE.RawStaticConsolidation.exclude_irrelevant_resources()
78+
|> Transport.IRVE.Extractor.exclude_irrelevant_resources()
7979
|> Enum.sort_by(fn r -> [r.dataset_id, r.resource_id] end)
8080
end
8181

@@ -114,7 +114,7 @@ defmodule Transport.IRVE.SimpleConsolidation do
114114
# it’s not linked to the file content/format, but to how it is published on data.gouv.fr.
115115
# it is done after downloading the file in order to be able to report on the potential
116116
# loss of PDC count.
117-
Transport.IRVE.RawStaticConsolidation.ensure_producer_is_org!(resource)
117+
ensure_producer_is_org!(resource)
118118

119119
validation_result = Transport.IRVE.Validator.validate(path, extension)
120120
file_valid? = validation_result |> Transport.IRVE.Validator.full_file_valid?()
@@ -134,7 +134,7 @@ defmodule Transport.IRVE.SimpleConsolidation do
134134
def generate_report(report_rows, destination: destination) do
135135
report_df =
136136
report_rows
137-
|> Enum.map(&Transport.IRVE.SimpleReportItem.to_map/1)
137+
|> Enum.map(&Transport.IRVE.ReportItem.to_map/1)
138138
|> Explorer.DataFrame.new()
139139
# `select` orders columns in the provided order
140140
# (https://github.com/elixir-explorer/explorer/issues/1126)
@@ -231,4 +231,8 @@ defmodule Transport.IRVE.SimpleConsolidation do
231231
raise "Error processing resource (#{resource_id}) (http_status=#{status})"
232232
end
233233
end
234+
235+
defp ensure_producer_is_org!(%{dataset_organisation_id: "???"}), do: raise("producer is not an organization")
236+
237+
defp ensure_producer_is_org!(_row), do: :ok
234238
end

apps/transport/lib/irve/database_importer.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ defmodule Transport.IRVE.DatabaseImporter do
5656
) do
5757
content =
5858
File.read!(file_path)
59-
|> Transport.IRVE.RawStaticConsolidation.ensure_utf8()
59+
|> Transport.IRVE.Transcoder.ensure_utf8()
6060

6161
rows_stream =
6262
content |> Transport.IRVE.Processing.read_as_data_frame() |> Explorer.DataFrame.to_rows_stream()

apps/transport/lib/irve/extractor.ex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ defmodule Transport.IRVE.Extractor do
1111

1212
@static_irve_datagouv_url "https://www.data.gouv.fr/api/1/datasets/?schema=etalab/schema-irve-statique"
1313

14+
# needed to filter out the existing, data-gouv provided consolidation
15+
@datagouv_organization_id Application.compile_env!(:transport, :datagouvfr_publisher_id)
16+
# Filter also our own consolidation!
17+
@transport_organization_id Application.compile_env!(:transport, :datagouvfr_transport_publisher_id)
18+
1419
@doc """
1520
Fetches the list of all `schema-irve-statique` resources from data gouv, using parallelized pagination.
1621
@@ -29,6 +34,13 @@ defmodule Transport.IRVE.Extractor do
2934
|> Enum.into([])
3035
end
3136

37+
def exclude_irrelevant_resources(stream) do
38+
stream
39+
# exclude data gouv generated consolidation
40+
|> Enum.reject(fn r -> r.dataset_organisation_id == @datagouv_organization_id end)
41+
|> Enum.reject(fn r -> r.dataset_organisation_id == @transport_organization_id end)
42+
end
43+
3244
@doc """
3345
Retrieve one page of resource results from data gouv.
3446
"""

apps/transport/lib/irve/raw_report_item.ex

Lines changed: 0 additions & 9 deletions
This file was deleted.

apps/transport/lib/irve/raw_static_consolidation.ex

Lines changed: 0 additions & 277 deletions
This file was deleted.

apps/transport/lib/irve/simple_report_item.ex renamed to apps/transport/lib/irve/report_item.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmodule Transport.IRVE.SimpleReportItem do
1+
defmodule Transport.IRVE.ReportItem do
22
@moduledoc """
33
Quick & dirty structure to massage the processing outcome of a single
44
IRVE file into a structure with all the same keys.

0 commit comments

Comments
 (0)