Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation NeTEx : statistiques dans les cartes de ressources NeTEx d'un dataset #4227

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ defmodule TransportWeb.DatasetController do
Transport.Validators.GTFSRT,
Transport.Validators.TableSchema,
Transport.Validators.EXJSONSchema,
Transport.Validators.GBFSValidator
Transport.Validators.GBFSValidator,
Transport.Validators.NeTEx
]

def resources_infos(dataset) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,22 @@
<% end %>

<%= if Resource.gtfs?(@resource) do %>
<%= if GTFSTransport.mine?(validation) do %>
<div class="pb-24">
<a href={resource_path(@conn, :details, @resource.id) <> "#validation-report"}>
<% {severity, count} = GTFSTransport.count_max_severity(validation.result) %>
<span class={summary_class(%{severity: severity, count_errors: count})}>
<%= if severity == "NoError" do %>
<%= dgettext("page-dataset-details", "No error detected") %>
<% else %>
<%= "#{count} #{String.downcase(GTFSTransport.severity(severity)[:text])}" %>
<% end %>
</span>
</a>
<span><%= dgettext("page-dataset-details", "during validation") %></span>
</div>
<% end %>
<%= render(TransportWeb.DatasetView, "_resource_validation_summary_gtfs.html",
conn: @conn,
resource: @resource,
validation: validation
) %>
<% end %>

<%= if Resource.netex?(@resource) do %>
<%= render(TransportWeb.DatasetView, "_resource_validation_summary_netex.html",
conn: @conn,
resource: @resource,
validation: validation
) %>
<% end %>

<%= unless Resource.gtfs?(@resource) do %>
<%= unless Resource.gtfs?(@resource) or Resource.netex?(@resource) do %>
<%= if multi_validation_performed?(validation) do %>
<% nb_warnings = warnings_count(validation) %>
<% nb_errors = errors_count(validation) %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<%= if GTFSTransport.mine?(@validation) do %>
<div class="pb-24">
<% link = resource_path(@conn, :details, @resource.id) <> "#validation-report" %>
<% {severity, count} = GTFSTransport.count_max_severity(@validation.result) %>
<a href={link}>
<span class={summary_class(%{severity: severity, count_errors: count})}>
<%= if GTFSTransport.no_error?(severity) do %>
<%= dgettext("page-dataset-details", "No error detected") %>
<% else %>
<%= "#{count} #{String.downcase(GTFSTransport.severity(severity)[:text])}" %>
<% end %>
</span>
</a>
<span><%= dgettext("page-dataset-details", "during validation") %></span>
</div>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="pb-24">
<% link = resource_path(@conn, :details, @resource.id) <> "#validation-report" %>
<% {severity, count} = NeTEx.count_max_severity(@validation.result) %>
<a href={link}>
<span class={summary_class(%{severity: severity, count_errors: count})}>
<%= if NeTEx.no_error?(severity) do %>
<%= dgettext("page-dataset-details", "No error detected") %>
<% else %>
<%= "#{count} #{String.downcase(NeTEx.severity(severity)[:text])}" %>
<% end %>
</span>
</a>
<span><%= dgettext("page-dataset-details", "during validation") %></span>
</div>
1 change: 1 addition & 0 deletions apps/transport/lib/transport_web/views/dataset_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule TransportWeb.DatasetView do
import DB.MultiValidation, only: [get_metadata_info: 2, get_metadata_info: 3]
alias Shared.DateTimeDisplay
alias Transport.Validators.GTFSTransport
alias Transport.Validators.NeTEx

@gtfs_rt_validator_name Transport.Validators.GTFSRT.validator_name()

Expand Down
2 changes: 2 additions & 0 deletions apps/transport/lib/validators/gtfs_transport_validator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ defmodule Transport.Validators.GTFSTransport do
|> Enum.min_by(fn {severity, _count} -> severity |> severity() |> Map.get(:level) end)
end

def no_error?(severity), do: @no_error == severity

@spec mine?(any) :: boolean()
def mine?(%{validator: validator}), do: validator == validator_name()
def mine?(_), do: false
Expand Down
2 changes: 2 additions & 0 deletions apps/transport/lib/validators/netex_validator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ defmodule Transport.Validators.NeTEx do
|> Enum.min_by(fn {severity, _count} -> severity |> severity() |> Map.get(:level) end)
end

def no_error?(severity), do: @no_error == severity

@spec severities_map() :: map()
def severities_map,
do: %{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,30 @@ defmodule TransportWeb.DatasetControllerTest do
assert conn |> html_response(200) =~ "1 erreur"
end

test "show NeTEx number of errors", %{conn: conn} do
%{id: dataset_id} = insert(:dataset, %{slug: slug = "dataset-slug", aom: build(:aom)})

%{id: resource_id} = insert(:resource, %{dataset_id: dataset_id, format: "NeTEx", url: "url"})

%{id: resource_history_id} = insert(:resource_history, %{resource_id: resource_id})

insert(:multi_validation, %{
resource_history_id: resource_history_id,
validator: Transport.Validators.NeTEx.validator_name(),
result: %{"xsd-1871" => [%{"criticity" => "error"}]},
metadata: %DB.ResourceMetadata{
metadata: %{"elapsed_seconds" => 42},
modes: [],
features: []
}
})

mock_empty_history_resources()

conn = conn |> get(dataset_path(conn, :details, slug))
assert conn |> html_response(200) =~ "1 erreurs"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Faudra vraiment corriger ce problème de pluriel un jour 😬

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je m'en occuperai dans la semaine, ça me démange fort depuis 1 mois.

end

test "GTFS-RT without validation", %{conn: conn} do
%{id: dataset_id} = insert(:dataset, %{slug: slug = "dataset-slug"})
insert(:resource, %{dataset_id: dataset_id, format: "gtfs-rt", url: "url"})
Expand Down