~ihabunek/triglav

c799db7339adc2b824150e424794bf3a078a5ae6 — Ivan Habunek 7 months ago 5f140d5
Use new router functions for validation
2 files changed, 20 insertions(+), 16 deletions(-)

M lib/triglav/osm.ex
M lib/triglav/zet/validator.ex
M lib/triglav/osm.ex => lib/triglav/osm.ex +6 -0
@@ 23,6 23,12 @@ defmodule Triglav.Osm do
    Enum.map(node_ids, &Map.get(node_map, &1))
  end

  def list_ordered_ways(relation_id) when is_integer(relation_id) do
    relation_id
    |> get_relation()
    |> list_ordered_ways()
  end

  def list_ordered_ways(%Relation{} = relation) do
    way_ids =
      relation

M lib/triglav/zet/validator.ex => lib/triglav/zet/validator.ex +14 -16
@@ 129,6 129,13 @@ defmodule Triglav.Zet.Validator do
         ways,
         relation_stop_ids
       ) do
    ordered_ways =
      relation.members
      |> Enum.filter(&(&1.member_type == "W" and &1.member_role == ""))
      |> Enum.map(fn member -> Map.fetch!(ways, member.member_id) end)

    router_result = Triglav.Osm.Router.route_ways(ordered_ways)

    required_tags = ["type", "route", "ref", "operator", "from", "to", "name"]

    allowed_tags =


@@ 146,7 153,7 @@ defmodule Triglav.Zet.Validator do
      validate_required_tags(route, relation, required_tags),
      validate_allowed_tags(route, relation, allowed_tags),
      validate_tag_values(route, relation, expected_tags),
      validate_continuous_ways(route, relation, ways),
      validate_continuous_ways(route, relation, router_result),
      validate_has_gtfs_stop_ids(route, relation, relation_stop_ids),
      validate_member_roles(route, relation)
    ]


@@ 183,23 190,14 @@ defmodule Triglav.Zet.Validator do
    end
  end

  # Validates that for each way included in a relation, the following way starts
  # with the same node with which the previous way ends.
  defp validate_continuous_ways(route, relation, ways) do
    relation.members
    # Skip stops
    |> Enum.filter(&(&1.member_type == "W" and &1.member_role == ""))
    |> Enum.map(fn member -> Map.fetch!(ways, member.member_id) end)
    |> Enum.chunk_every(2, 1)
    |> Enum.find_value(fn
      [_] ->
  defp validate_continuous_ways(route, relation, router_result) do
    case router_result do
      {:ok, _} ->
        nil

      [a, b] ->
        if !Way.adjacent?(a, b) do
          Error.broken_route(route, relation, b.id)
        end
    end)
      {:error, {:ways_not_connected, _w1, w2}} ->
        Error.broken_route(route, relation, w2.id)
    end
  end

  defp validate_has_gtfs_stop_ids(route, relation, relation_stop_ids) do