<commit_before>defmodule Typeform.SubmitEvent do
  require Logger

  @doc"""
  Takes a typeform post body from a webhook, creates the event in NB, and sends an email
  """
  def on_event_submit(%{"form_response" => %{"answers" => answers, "definition" => definition}}) do
    questions =
      definition["fields"]
      |> Enum.map(&field_name/1)

    responses =
      answers
      |> Enum.map(&get_answer/1)

    together = questions |> Enum.zip(responses) |> Enum.into(%{})

    ensure_host = Task.async(fn ->
      names = String.split(together["host_name"], " ")
      first_name = List.first(names)

      last_name = if length(names) > 1 do
        List.last(names)
      else
        ""
      end

      %{"id" => id} = Nb.People.push(%{
        email: together["host_email"],
        phone: together["host_phone"],
        first_name: first_name,
        last_name: last_name
      })

      id
    end)

    find_calendar = Task.async(fn ->
      calendar_id = case Zip.closest_candidate(together["venue_zip"]) do
        %{"metadata" => %{"calendar_id" => result}} -> result
        _ -> 9
      end

      calendar_id
    end)

    Logger.info(together["venue_zip"])
  
    find_time_zone = Task.async(fn ->
      Zip.time_zone_of(together["venue_zip"])
    end)

    host_id = Task.await(ensure_host)
    calendar_id = Task.await(find_calendar)
    time_zone = Task.await(find_time_zone)<commit_msg>remove zip logging<commit_after>defmodule Typeform.SubmitEvent do
  require Logger

  @doc"""
  Takes a typeform post body from a webhook, creates the event in NB, and sends an email
  """
  def on_event_submit(%{"form_response" => %{"answers" => answers, "definition" => definition}}) do
    questions =
      definition["fields"]
      |> Enum.map(&field_name/1)

    responses =
      answers
      |> Enum.map(&get_answer/1)

    together = questions |> Enum.zip(responses) |> Enum.into(%{})

    ensure_host = Task.async(fn ->
      names = String.split(together["host_name"], " ")
      first_name = List.first(names)

      last_name = if length(names) > 1 do
        List.last(names)
      else
        ""
      end

      %{"id" => id} = Nb.People.push(%{
        email: together["host_email"],
        phone: together["host_phone"],
        first_name: first_name,
        last_name: last_name
      })

      id
    end)

    find_calendar = Task.async(fn ->
      calendar_id = case Zip.closest_candidate(together["venue_zip"]) do
        %{"metadata" => %{"calendar_id" => result}} -> result
        _ -> 9
      end

      calendar_id
    end)

    find_time_zone = Task.async(fn ->
      Zip.time_zone_of(together["venue_zip"])
    end)

    host_id = Task.await(ensure_host)
    calendar_id = Task.await(find_calendar)
    time_zone = Task.await(find_time_zone)
{'fraction_non_alphanumeric': 0.13507703332139018, 'fraction_numerical': 0.002866356144750985, 'mean_word_length': 2.616580310880829, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6410591', 'n_tokens_mistral': 924, 'n_tokens_neox': 887, 'n_words': 184}