Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Evaluate Boston Location

evaluate-boston-location.livemd

Evaluate Boston Location

Section

defmodule EvaluateBostonLocation.Helpers do
  @moduledoc false

  @filter ~r/,\s(MA|NH|RI),\s/

  @doc """
  Get autocomplete results to the given location.
  """
  def get_autocomplete_results(location, options) do
    {:ok, results} = LocationService.autocomplete(location, 5, options)

    results
    |> Enum.map(& &1.address)
    |> Enum.filter(fn address ->
      Regex.match?(@filter, address)
    end)
  end
end

alias EvaluateBostonLocation.Helpers
Application.start(:yamerl)

write_path =
  System.tmp_dir!()
  |> Path.join("autocompletions.yml")
  |> IO.inspect()

bias_options = %{
  # Boston Commons
  BiasPosition: [-71.06606866833201, 42.35483511240896]
}

bounding_options = %{
  FilterBBox: [-71.9380, 41.3193, -69.6189, 42.8266]
}

locations =
  File.cwd!()
  |> Path.join("/livebooks/locations.yml")
  |> YamlElixir.read_from_file!()
  |> Enum.map(fn location ->
    %{
      given: location,
      bias_options_results: Helpers.get_autocomplete_results(location, bias_options),
      bounding_options_results: Helpers.get_autocomplete_results(location, bounding_options)
    }
  end)

yaml = Ymlr.document!(locations)

File.write!(write_path, yaml)