~ihabunek/triglav

78bb75d49195cafb126a845b7334ba75e31173a6 — Ivan Habunek 8 days ago 3caf5e0
Tweaks to the route match page
M lib/triglav_web/controllers/zet/routes_controller.ex => lib/triglav_web/controllers/zet/routes_controller.ex +4 -2
@@ 124,6 124,7 @@ defmodule TriglavWeb.Zet.RoutesController do
    platforms =
      platform_members
      |> Enum.map(& &1.member)
      |> Enum.filter(& &1.tags["gtfs:stop_id"])
      |> Map.new(&{&1.tags["gtfs:stop_id"], &1})

    stops =


@@ 138,9 139,10 @@ defmodule TriglavWeb.Zet.RoutesController do

    diffs =
      for trip <- trips do
        List.myers_difference(relation_stop_ids, trip.stops)
        diffs = List.myers_difference(relation_stop_ids, trip.stops)
        %{trip: trip, diffs: diffs, eq_count: count_eq(diffs)}
      end
      |> Enum.sort_by(&count_eq/1, &>=/2)
      |> Enum.sort_by(& &1.eq_count, &>=/2)

    render(conn, "match.html",
      diffs: diffs,

M lib/triglav_web/templates/zet/routes/match.html.eex => lib/triglav_web/templates/zet/routes/match.html.eex +17 -7
@@ 6,9 6,19 @@
  </ul>

  <h1>Find a matching trip for relation #<%= @relation.id %></h1>
  <p>Sorted by most to least probable.</p>

  <%= for trip_diffs <- @diffs do %>
  <p>Compares platforms defined in the OSM relation with ZET GTFS trips.</p>
  <p>The relation is compared to each distinct trip. Diffs with more elements in common are shown on top.</p>

  <%= osm_link(@relation, tags: ["type"], name: true, josm: true) %>

  <hr style="margin: 1rem 0" />

  <%= for {row, index} <- Enum.with_index(@diffs) do %>
    <h3>
      Option #<%= index + 1%>,
      <%= row.trip.trip_count %> departures
    </h3>
    <table>
      <thead>
        <tr>


@@ 17,14 27,15 @@
        </tr>
      </thead>
      <tbody>
      <%= for {op, ids} <- trip_diffs do %>
      <%= for {op, ids} <- row.diffs do %>
        <%= for id <- ids do %>
          <% platform = Map.get(@platforms, id) %>
          <% platform_name = if platform, do: platform.tags["name"], else: "Missing GTFS Stop ID" %>
          <% stop = Map.get(@stops, id) %>
          <tr>
            <%= if op == :eq do %>
              <td><%= id %></td>
              <td><%= platform.tags["name"] %></td>
              <td><%= platform_name %></td>
              <td><%= id %></td>
              <td><%= stop.name %></td>
            <% end %>


@@ 37,8 48,8 @@
            <% end %>

            <%= if op == :del do %>
              <td class="bg-red"><%= id %></td>
              <td class="bg-red"><%= platform.tags["name"] %></td>
              <td class="bg-red"><%= id || "???" %></td>
              <td class="bg-red"><%= platform_name %></td>
              <td></td>
              <td></td>
            <% end %>


@@ 47,6 58,5 @@
      <% end %>
      </tbody>
    </table>
    <hr style="margin: 2rem 0" />
  <% end %>
</main>

M lib/triglav_web/views/osm_helpers.ex => lib/triglav_web/views/osm_helpers.ex +1 -1
@@ 43,7 43,7 @@ defmodule TriglavWeb.OsmHelpers do
      <% end %>
      <%= if josm? do %>
        <a class="josm-remote" href="<%= josm_link %>" title="Open relation in JOSM" target="_blank">
          JOSM
          🜨 Load
        </a>
      <% end %>
    </span>