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

NeTEx validator : travaux préliminaires #4139

Merged
merged 3 commits into from
Aug 28, 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
3 changes: 0 additions & 3 deletions apps/transport/lib/db/resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ defmodule DB.Resource do
query |> where([resource: r], r.dataset_id == ^dataset_id)
end

@spec endpoint() :: binary()
def endpoint, do: Application.fetch_env!(:transport, :gtfs_validator_url) <> "/validate"

def changeset(resource, params) do
resource
|> cast(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ associated_netex = get_associated_netex(@related_files) %>
path: &resource_path/4,
action: :details
) %>
<%= render(template(@issues), issues: @issues || [], conn: @conn) %>
<%= render(gtfs_template(@issues), issues: @issues || [], conn: @conn) %>
</div>
<% end %>
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
path: &validation_path/4,
action: :show
) %>
<%= render(template(@issues), issues: @issues || [], conn: @conn) %>
<%= render(gtfs_template(@issues), issues: @issues || [], conn: @conn) %>
<div class="pt-24">
<%= pagination_links(@conn, @issues, [@validation_id],
issue_type: issue_type(@issues.entries),
Expand Down
53 changes: 28 additions & 25 deletions apps/transport/lib/transport_web/views/resource_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,34 @@ defmodule TransportWeb.ResourceView do
def issue_type([]), do: nil
def issue_type([h | _]), do: h["issue_type"]

def template(issues) do
Map.get(
%{
"UnloadableModel" => "_unloadable_model_issue.html",
"DuplicateStops" => "_duplicate_stops_issue.html",
"DuplicateStopSequence" => "_duplicate_stop_sequence_issue.html",
"ExtraFile" => "_extra_file_issue.html",
"MissingFile" => "_missing_file_issue.html",
"NullDuration" => "_speed_issue.html",
"ExcessiveSpeed" => "_speed_issue.html",
"NegativeTravelTime" => "_speed_issue.html",
"Slow" => "_speed_issue.html",
"UnusedStop" => "_unused_stop_issue.html",
"InvalidCoordinates" => "_coordinates_issue.html",
"MissingCoordinates" => "_coordinates_issue.html",
"UnusedShapeId" => "_unused_shape_issue.html",
"InvalidShapeId" => "_invalid_shape_id_issue.html",
"MissingId" => "_missing_id_issue.html",
"MissingName" => "_missing_name_issue.html",
"SubFolder" => "_subfolder_issue.html",
"NegativeStopDuration" => "_negative_stop_duration_issue.html"
},
issue_type(issues.entries),
"_generic_issue.html"
)
def gtfs_template(issues) do
template =
Map.get(
%{
"UnloadableModel" => "_unloadable_model_issue.html",
"DuplicateStops" => "_duplicate_stops_issue.html",
"DuplicateStopSequence" => "_duplicate_stop_sequence_issue.html",
"ExtraFile" => "_extra_file_issue.html",
"MissingFile" => "_missing_file_issue.html",
"NullDuration" => "_speed_issue.html",
"ExcessiveSpeed" => "_speed_issue.html",
"NegativeTravelTime" => "_speed_issue.html",
"Slow" => "_speed_issue.html",
"UnusedStop" => "_unused_stop_issue.html",
"InvalidCoordinates" => "_coordinates_issue.html",
"MissingCoordinates" => "_coordinates_issue.html",
"UnusedShapeId" => "_unused_shape_issue.html",
"InvalidShapeId" => "_invalid_shape_id_issue.html",
"MissingId" => "_missing_id_issue.html",
"MissingName" => "_missing_name_issue.html",
"SubFolder" => "_subfolder_issue.html",
"NegativeStopDuration" => "_negative_stop_duration_issue.html"
},
issue_type(issues.entries),
"_generic_issue.html"
)

"_gtfs#{template}"
end

@spec action_path(Plug.Conn.t()) :: any
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule TransportWeb.ValidationView do
use TransportWeb, :view
import Phoenix.Controller, only: [current_url: 1]
import TransportWeb.ResourceView, only: [issue_type: 1, template: 1]
import TransportWeb.ResourceView, only: [issue_type: 1, gtfs_template: 1]
import TransportWeb.PaginationHelpers

def render("_" <> _ = partial, assigns) do
Expand Down
10 changes: 10 additions & 0 deletions apps/transport/lib/validators/gtfs_transport_validator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ defmodule Transport.Validators.GTFSTransport do

def get_issues(_, _), do: []

@doc """
iex> validation_result = %{"tooClose" => [%{"severity" => "Warning"}], "funnyName" => [%{"severity" => "Information"}]}
iex> summary(validation_result)
[
{"Warning", [{"tooClose", %{count: 1, severity: "Warning", title: nil}}]},
{"Information", [{"funnyName", %{count: 1, severity: "Information", title: nil}}]}
]
iex> summary(%{})
[]
"""
@spec summary(map) :: list
def summary(%{} = validation_result) do
validation_result
Expand Down