Created
May 9, 2022 10:08
-
-
Save sushant12/240bfef645a92a7728c181c45755019e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mix.install([:nimble_csv, :geo]) | |
# defmodule DefinedZones do | |
# defstruct [:country, :city, :zone, :sub_zone, :priority, :geo] | |
# end | |
defmodule Converter do | |
alias NimbleCSV.RFC4180, as: CSV | |
def run() do | |
"demo.csv" | |
|> File.read!() | |
|> CSV.parse_string | |
|> Enum.map(fn [sub_zone, priority, coordinates] -> | |
[lat, lng] = coordinates |> String.trim() |> String.split | |
priority = priority |> String.trim |> String.to_integer | |
{lat, _} = lat |> String.trim |> Float.parse | |
{lng, _} = lng |> String.trim |> Float.parse | |
%{ | |
country: "UAE", | |
city: "Fujeriah", | |
zone: "Zone 1", | |
sub_zone: sub_zone |> String.trim, | |
priority: priority, | |
geo: %Geo.Point{coordinates: {lat, lng}, srid: 4326} | |
} | |
end) | |
end | |
end | |
Converter.run() |> IO.inspect | |
[ | |
{"Bateen Al Samar", ""}, | |
{"Al Dhait South", ""}, | |
{"Al Dhait North", ""}, | |
{"Dafan Al Khor", ""}, | |
{"The Old Market", ""}, | |
{"Al Qurm", ""}, | |
{"Sidroh", ""}, | |
{"Al Uraibi", ""}, | |
{"Al Nakheel", ""}, | |
{"Ras Al Selaab", ""}, | |
{"Al Mairid", ""}, | |
{"Al Sall", ""}, | |
{"Wadi Ammar", ""}, | |
{"Al Sharisha", ""}, | |
{"Al Mataf", ""}, | |
{"Al Nudood", ""}, | |
{"Al Darbijaniyah", ""}, | |
{"Al Rams", ""}, | |
{"Al Ghubb", ""}, | |
{"Seih Al Ghubb", ""}, | |
{"Al Hudaibah", ""}, | |
{"Liwa Badr", ""}, | |
{"Seih Al Burairat", ""}, | |
{"Seih Al Qusaidat", ""} | |
] |> Enum.map(fn {sub_zone, priority} -> | |
priority = if priority == "", do: 0 | |
%{ | |
country: "UAE", | |
city: "Ras al Khaimah", | |
zone: "Zone 1", | |
sub_zone: sub_zone |> String.trim, | |
priority: priority | |
} | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment