~ihabunek/triglav

ee4251c93178790d61a645828d6632b4f27383ac — Ivan Habunek 10 months ago d5fdfad
Minor cleanup
M lib/mix/tasks/triglav/import_osm.ex => lib/mix/tasks/triglav/import_osm.ex +0 -1
@@ 9,7 9,6 @@ defmodule Mix.Tasks.Triglav.ImportOsm do
    {:ok, _} = Application.ensure_all_started(:triglav)

    {opts, _rest} = OptionParser.parse!(args, strict: [force: :boolean])

    Triglav.Import.Osm.run(opts[:force])
  end
end

M lib/mix/tasks/triglav/import_zet.ex => lib/mix/tasks/triglav/import_zet.ex +5 -3
@@ 4,9 4,11 @@ defmodule Mix.Tasks.Triglav.ImportZet do
  @shortdoc "Imports GTFS data for ZET routes"

  @impl Mix.Task
  def run(_args) do
  def run(args) do
    Application.put_env(:triglav, :repo_only, true)
    Application.ensure_all_started(:triglav)
    Triglav.Import.Zet.run()
    {:ok, _} = Application.ensure_all_started(:triglav)

    {opts, _} = OptionParser.parse!(args, strict: [force: :boolean])
    Triglav.Import.Zet.run(opts)
  end
end

M lib/triglav/import/zet.ex => lib/triglav/import/zet.ex +1 -1
@@ 13,7 13,7 @@ defmodule Triglav.Import.Zet do
  @type option :: :force

  def run(opts \\ []) do
    force = :force in opts
    force = Keyword.get(opts, :force, false)

    web_feed_archive = get_web_feed_archive()
    web_info = extract_feed_info(web_feed_archive)

M lib/triglav/zet/gtfs.ex => lib/triglav/zet/gtfs.ex +7 -3
@@ 5,17 5,17 @@ defmodule Triglav.Zet.Gtfs do
  import Ecto.Query

  def get_feed_info do
    Zet.FeedInfo |> Triglav.Repo.one!()
    Zet.FeedInfo |> Repo.one!()
  end

  def list_routes do
    Zet.Route |> Triglav.Repo.all()
    Zet.Route |> Repo.all()
  end

  def get_route(id) do
    Zet.Route
    |> where(id: ^id)
    |> Triglav.Repo.one!()
    |> Repo.one!()
  end

  def fetch_distinct_trips(%Zet.Route{} = route) do


@@ 43,6 43,10 @@ defmodule Triglav.Zet.Gtfs do
    )
  end

  @doc """
  Returns a list of all stops contained in any trip in the given route.
  """
  @spec fetch_distinct_stops(Zet.Route.t()) :: [Zet.Stop.t()]
  def fetch_distinct_stops(%Zet.Route{} = route) do
    from(t in Zet.Trip,
      where: t.route_id == ^route.id,

M lib/triglav_web/controllers/zet/routes_controller.ex => lib/triglav_web/controllers/zet/routes_controller.ex +8 -2
@@ 49,7 49,13 @@ defmodule TriglavWeb.Zet.RoutesController do
      |> group_errors_by_relation()

    trips = Gtfs.fetch_distinct_trips(route) |> Enum.group_by(& &1["direction_id"])
    stops = Gtfs.fetch_distinct_stops(route) |> Enum.map(&Map.take(&1, [:id, :name, :lat, :lon]))

    # JSON encode stops for drawing on the map
    stops_json =
      route
      |> Gtfs.fetch_distinct_stops()
      |> Enum.map(&Map.take(&1, [:id, :name, :lat, :lon]))
      |> Jason.encode!()

    render(conn, "detail.html",
      conn: conn,


@@ 59,7 65,7 @@ defmodule TriglavWeb.Zet.RoutesController do
      errors: errors,
      rel_errors: rel_errors,
      trips: trips,
      stops: stops
      stops_json: stops_json
    )
  end


M lib/triglav_web/templates/zet/routes/detail.html.eex => lib/triglav_web/templates/zet/routes/detail.html.eex +1 -1
@@ 8,7 8,7 @@
</style>

<script id="stops-json" type="application/json">
  <%= @stops|> Jason.encode!() |> raw() %>
  <%= raw(@stops_json) %>
</script>

<main role="main" class="container-wide">