Add the ability obfuscate coordinates

main
Jeremy Boles 2 months ago
parent 7d50a5c713
commit b057429625
Signed by: jb
GPG Key ID: 7DE0508F61CB57DF
  1. 4
      config/runtime.exs
  2. 1
      config/test.exs
  3. 38
      lib/ann/helpers.ex
  4. 2
      mix.exs
  5. 2
      mix.lock

@ -3,4 +3,6 @@ import Config
if config_env() == :prod do
config :ann, Storala.Journal, data_path: System.get_env("ANN_JOURNAL_PATH")
config :ann, Storala.Wiki, data_path: System.get_env("ANN_WIKI_PATH")
end
config :ann, Ann.Helpers, translate_coords: System.get_env("ANN_TRANSLATE_COORDS")
end

@ -0,0 +1 @@
import Config

@ -1,4 +1,6 @@
defmodule Ann.Helpers do
import Geocalc
def city(%{"city" => city, "state" => state, "country" => "United States"}) do
~s(#{city}, #{state}, <abbr title="United States">US</abbr>)
end
@ -33,7 +35,7 @@ defmodule Ann.Helpers do
end
def dms(%Geo.Point{} = point) do
%Geo.Point{coordinates: {lng, lat}} = round_point(point)
%Geo.Point{coordinates: {lng, lat}} = point |> round_point() |> obfuscate()
"#{decimal_to_lat_dms(lat)} #{decimal_to_lng_dms(lng)}"
end
@ -71,6 +73,17 @@ defmodule Ann.Helpers do
minutes |> Float.floor() |> Kernel.trunc()
end
defp obfuscate(%Geo.Point{} = point) do
case translate_to(point) do
{_, to} -> to
_ -> point
end
end
defp parse_pair(pair) when is_binary(pair), do: pair |> String.split(":") |> parse_pair()
defp parse_pair([from | [to | _]]), do: {to_circle(from), to_point(to)}
defp parse_pair(_), do: nil
defp round_point(%Geo.Point{coordinates: {lng, lat}}, precision \\ 4) do
%Geo.Point{coordinates: {Float.round(lng, precision), Float.round(lat, precision)}}
end
@ -79,4 +92,27 @@ defmodule Ann.Helpers do
seconds = ((Kernel.abs(decimal) - degrees(decimal)) * 60 - minutes(decimal)) * 60
seconds |> Decimal.from_float() |> Decimal.round(1)
end
def to_circle(hash) when is_binary(hash), do: hash |> Geohash.decode() |> to_circle()
def to_circle({lat, lng}), do: %Geocalc.Shape.Circle{latitude: lat, longitude: lng, radius: 150}
def to_point(hash) when is_binary(hash), do: hash |> Geohash.decode() |> to_point()
def to_point({lat, lng}), do: %Geo.Point{coordinates: {lng, lat}}
defp translate_coords do
Application.get_env(:ann, __MODULE__, [])
|> Keyword.get(:translate_coords, "")
|> String.split(",")
|> Enum.map(&parse_pair/1)
|> Enum.reject(&is_nil/1)
end
defp translate_to(%Geo.Point{coordinates: {lng, lat}} = point) do
translate_coords()
|> Enum.find(fn {from, _to} ->
IO.inspect(from, label: "from")
IO.inspect(point, label: "point")
in_area?(from, %{lat: lat, lng: lng})
end)
end
end

@ -27,6 +27,8 @@ defmodule Ann.MixProject do
{:ex_cldr_numbers, "~> 2.27.2"},
{:floki, "~> 0.33.1"},
{:geo, "~> 3.4"},
{:geocalc, "~> 0.8.4"},
{:geohash, "~> 1.2.2"},
{:inflex, "~> 2.1.0"},
{:number, "~> 1.0.3"},
{:plug, "~> 1.13"},

@ -12,6 +12,8 @@
"ex_cldr_numbers": {:hex, :ex_cldr_numbers, "2.27.2", "d1400a0502fb66ab3abcce3d10d5d11efcfc786eafe1c442ea2ddf834670d743", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:digital_token, "~> 0.3 or ~> 1.0", [hex: :digital_token, repo: "hexpm", optional: false]}, {:ex_cldr, "~> 2.28", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:ex_cldr_currencies, "~> 2.13", [hex: :ex_cldr_currencies, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "f682f46193e1793a3a98cc636314e9bea483da0925eb47935a39c4feef79e364"},
"floki": {:hex, :floki, "0.33.1", "f20f1eb471e726342b45ccb68edb9486729e7df94da403936ea94a794f072781", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "461035fd125f13fdf30f243c85a0b1e50afbec876cbf1ceefe6fddd2e6d712c6"},
"geo": {:hex, :geo, "3.4.3", "0ddf3f681993d32c397e5ef346e7b4b6f36f39ed138502429832fa4000ebb9d5", [:mix], [{:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "e23f2892e5437ec8b063cee1beccec89c58fd841ae11133304700235feb25552"},
"geocalc": {:hex, :geocalc, "0.8.4", "ee0526cccccbcd52498670e20852b0b763edbfc67c5225c33dfebd3be7bd5393", [:mix], [], "hexpm", "d58cbfc54fee549340c790efc54321e68fbc92d9dc334e24cef4afc120fefc8c"},
"geohash": {:hex, :geohash, "1.2.2", "4e95a65594afde96ba8c003d43947eb06e97b1a4ad25a21f863922918e3819e8", [:mix], [], "hexpm", "98ed91f7e4682f71a21cb9eeec7ca70e2f578f600c1c9335cc6c55b1b9a30ee2"},
"gettext": {:hex, :gettext, "0.20.0", "75ad71de05f2ef56991dbae224d35c68b098dd0e26918def5bb45591d5c8d429", [:mix], [], "hexpm", "1c03b177435e93a47441d7f681a7040bd2a816ece9e2666d1c9001035121eb3d"},
"hackney": {:hex, :hackney, "1.18.1", "f48bf88f521f2a229fc7bae88cf4f85adc9cd9bcf23b5dc8eb6a1788c662c4f6", [:rebar3], [{:certifi, "~>2.9.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "a4ecdaff44297e9b5894ae499e9a070ea1888c84afdd1fd9b7b2bc384950128e"},
"hpax": {:hex, :hpax, "0.1.1", "2396c313683ada39e98c20a75a82911592b47e5c24391363343bde74f82396ca", [:mix], [], "hexpm", "0ae7d5a0b04a8a60caf7a39fcf3ec476f35cc2cc16c05abea730d3ce6ac6c826"},

Loading…
Cancel
Save