~ihabunek/triglav

d1b5915f3e023d04850eabf702bda7207a337302 — Ivan Habunek 3 months ago 837d6e2
Validate platform distance from route
3 files changed, 32 insertions(+), 1 deletions(-)

M lib/triglav/schemas/error.ex
M lib/triglav/zet/errors.ex
M lib/triglav/zet/validator.ex
M lib/triglav/schemas/error.ex => lib/triglav/schemas/error.ex +14 -0
@@ 5,6 5,7 @@ defmodule Triglav.Schemas.Error do
  alias Triglav.Schemas.Zet.Route
  alias Triglav.Schemas.Osmosis.Relation
  alias Triglav.Schemas.Osmosis.RelationMember
  alias Triglav.Schemas.PublicTransport.Platform

  @type t :: %__MODULE__{}



@@ 162,4 163,17 @@ defmodule Triglav.Schemas.Error do
        relation_id: relation.id,
        params: Map.take(member, [:member_id, :member_role, :member_type])
      }

  @spec platform_too_far_from_route(Route.t(), Relation.t(), Platform.t()) :: Error.t()
  def platform_too_far_from_route(
        %Route{} = route,
        %Relation{} = relation,
        %Platform{} = platform
      ),
      do: %__MODULE__{
        key: "platform_too_far_from_route",
        route_id: route.id,
        relation_id: relation.id,
        params: Map.take(platform, [:node_id, :way_id, :sequence_id, :distance_from_route])
      }
end

M lib/triglav/zet/errors.ex => lib/triglav/zet/errors.ex +7 -0
@@ 84,6 84,13 @@ defmodule Triglav.Zet.Errors do
    "Unexpected role \"#{member_role}\" on relation member #{member_type}#{member_id}"
  end

  def render(%Error{
        key: "platform_too_far_from_route",
        params: %{"sequence_id" => sequence_id, "distance_from_route" => distance_from_route}
      }) do
    "Platform #{sequence_id} is #{distance_from_route}m from route"
  end

  def render(%Error{key: key}) do
    "FIXME: missing render function for error '#{key}'"
  end

M lib/triglav/zet/validator.ex => lib/triglav/zet/validator.ex +11 -1
@@ 11,6 11,9 @@ defmodule Triglav.Zet.Validator do
  alias Triglav.Derived.PublicTransport
  alias Triglav.Schemas.PublicTransport.Platform

  # Maximum distance from platform to route
  @max_platform_distance_from_route 20

  defmodule ValidationData do
    @moduledoc """
    Contains data loaded from the database and used for validation.


@@ 201,7 204,8 @@ defmodule Triglav.Zet.Validator do
      validate_tag_values(route, relation, expected_tags),
      validate_continuous_ways(route, relation, trip, data),
      validate_has_gtfs_stop_ids(route, relation, platforms),
      validate_member_roles(route, relation)
      validate_member_roles(route, relation),
      validate_platform_distance_from_route(route, relation, platforms)
    ]
  end



@@ 290,6 294,12 @@ defmodule Triglav.Zet.Validator do
    end
  end

  defp validate_platform_distance_from_route(route, relation, platforms) do
    for platform <- platforms, platform.distance_from_route > @max_platform_distance_from_route do
      Error.platform_too_far_from_route(route, relation, platform)
    end
  end

  #
  # Generic relation validators
  #