~ihabunek/triglav

c5fb7ed384adc94e9c8e1de07360080e86510502 — Ivan Habunek 21 days ago 807966d hps
WIP PARSING GPX
4 files changed, 38 insertions(+), 2 deletions(-)

M lib/triglav/import/hps.ex
A lib/triglav/schemas/hps/track_geometry.ex
M mix.exs
M mix.lock
M lib/triglav/import/hps.ex => lib/triglav/import/hps.ex +21 -2
@@ 4,9 4,11 @@ defmodule Triglav.Import.Hps do
  """

  alias Ecto.Multi
  alias Triglav.Hps
  alias Triglav.Http
  alias Triglav.Schemas.Hps.Track
  alias Triglav.Repo
  alias Triglav.Schemas.Hps.Track
  require Logger

  @tracks_url "https://www.hps.hr/karta/csv/tracks.csv"



@@ 15,7 17,8 @@ defmodule Triglav.Import.Hps do
      tracks =
        tracks_csv
        |> String.trim()
        |> String.replace_leading("", "")
        # Remove BOM
        |> String.replace_leading("\uFEFF", "")
        |> String.split("\n")
        |> Enum.map(&String.trim/1)
        # Some rows are duplicated


@@ 30,6 33,22 @@ defmodule Triglav.Import.Hps do
    end
  end

  def import_gpx() do
    Hps.list_tracks()
    |> Enum.map(fn track -> [{track, track.gpx1_url}, {track, track.gpx2_url}] end)
    |> List.flatten()
    |> Enum.take(2)
    |> Enum.map(&import_track_gpx/1)
  end

  defp import_track_gpx({track, url}) do
    Logger.debug("Loading: #{url}")

    with {:ok, gpx} = Http.get(url) do
      nil
    end
  end

  defp parse_track([
         gpx1,
         _,

A lib/triglav/schemas/hps/track_geometry.ex => lib/triglav/schemas/hps/track_geometry.ex +15 -0
@@ 0,0 1,15 @@
defmodule Triglav.Schemas.Hps.TrackGeometry do
  use Ecto.Schema
  alias Triglav.Schemas.Hps.Track

  @type t() :: %__MODULE__{
          __meta__: Ecto.Schema.Metadata.t()
        }

  schema "hps_tracks" do
    belongs_to :track, Track
    field :ref, :string
    field :gpx_url, :string
    field :geometry, Geo.PostGIS.Geometry
  end
end

M mix.exs => mix.exs +1 -0
@@ 47,6 47,7 @@ defmodule Triglav.MixProject do
      {:phoenix_live_reload, "~> 1.2", only: :dev},
      {:plug_cowboy, "~> 2.0"},
      {:postgrex, ">= 0.0.0"},
      {:sweet_xml, "~> 0.6.6"},
      {:telemetry_metrics, "~> 0.4"},
      {:telemetry_poller, "~> 0.4"}
    ]

M mix.lock => mix.lock +1 -0
@@ 28,6 28,7 @@
  "plug_crypto": {:hex, :plug_crypto, "1.2.0", "1cb20793aa63a6c619dd18bb33d7a3aa94818e5fd39ad357051a67f26dfa2df6", [:mix], [], "hexpm", "a48b538ae8bf381ffac344520755f3007cc10bd8e90b240af98ea29b69683fc2"},
  "postgrex": {:hex, :postgrex, "0.15.7", "724410acd48abac529d0faa6c2a379fb8ae2088e31247687b16cacc0e0883372", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "88310c010ff047cecd73d5ceca1d99205e4b1ab1b9abfdab7e00f5c9d20ef8f9"},
  "ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm", "451d8527787df716d99dc36162fca05934915db0b6141bbdac2ea8d3c7afc7d7"},
  "sweet_xml": {:hex, :sweet_xml, "0.6.6", "fc3e91ec5dd7c787b6195757fbcf0abc670cee1e4172687b45183032221b66b8", [:mix], [], "hexpm", "2e1ec458f892ffa81f9f8386e3f35a1af6db7a7a37748a64478f13163a1f3573"},
  "telemetry": {:hex, :telemetry, "0.4.2", "2808c992455e08d6177322f14d3bdb6b625fbcfd233a73505870d8738a2f4599", [:rebar3], [], "hexpm", "2d1419bd9dda6a206d7b5852179511722e2b18812310d304620c7bd92a13fcef"},
  "telemetry_metrics": {:hex, :telemetry_metrics, "0.6.0", "da9d49ee7e6bb1c259d36ce6539cd45ae14d81247a2b0c90edf55e2b50507f7b", [:mix], [{:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "5cfe67ad464b243835512aa44321cee91faed6ea868d7fb761d7016e02915c3d"},
  "telemetry_poller": {:hex, :telemetry_poller, "0.5.1", "21071cc2e536810bac5628b935521ff3e28f0303e770951158c73eaaa01e962a", [:rebar3], [{:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4cab72069210bc6e7a080cec9afffad1b33370149ed5d379b81c7c5f0c663fd4"},