<commit_before>defmodule Rsvps do
  def csv_for(id) do
    all_attendances = OsdiClient.stream(client(), "events/#{id}/attendances")
    people_ids = Enum.map(all_attendances, & &1.person)

    people_fetch_tasks =
      Enum.map(
        people_ids,
        &Task.async(fn ->
          %{body: body} = OsdiClient.get(client(), "people/#{&1}")
          body
        end)
      )

    people = Enum.map(people_fetch_tasks, fn t -> Task.await(t, :infinity) end)
    IO.inspect(people)

    csv_content =
      Enum.map(people, fn p ->
        Enum.join(
          [
            Enum.join([p.given_name, p.family_name], " "),
            List.first(p.email_addresses) |> get_email(),
            List.first(p.phone_numbers) |> get_number(),
            Map.get(p, :postal_addresses, []) |> List.first() |> get_zip()
          ],
          ","
        )
      end)

    ["Name,Email,Phone,Zip"]
    |> Enum.concat(csv_content)
    |> Enum.join("\n")
  end

  def emails_for(id) do
    all_attendances = OsdiClient.stream(client(), "events/#{id}/attendances")
    people_ids = Enum.map(all_attendances, & &1.person)<commit_msg>include source in rsvp download<commit_after>defmodule Rsvps do
  def csv_for(id) do
    all_attendances = OsdiClient.stream(client(), "events/#{id}/attendances")

    people_sources =
      Enum.reduce(all_attendances, %{}, fn attendance, acc ->
        Map.put(acc, attendance.person, get_in(attendance, ~w(referrer_data source)a))
      end)

    people_ids = Enum.map(all_attendances, & &1.person) |> MapSet.new()

    people_fetch_tasks =
      Enum.map(
        people_ids,
        &Task.async(fn ->
          %{body: body} = OsdiClient.get(client(), "people/#{&1}")
          Map.put(body, :id, &1)
        end)
      )

    people = Enum.map(people_fetch_tasks, fn t -> Task.await(t, :infinity) end)

    csv_content =
      Enum.map(people, fn p ->
        Enum.join(
          [
            Enum.join([p.given_name, p.family_name], " "),
            List.first(p.email_addresses) |> get_email(),
            List.first(p.phone_numbers) |> get_number(),
            Map.get(p, :postal_addresses, []) |> List.first() |> get_zip(),
            Map.get(people_sources, p.id)
          ],
          ","
        )
      end)

    ["Name,Email,Phone,Zip,Source"]
    |> Enum.concat(csv_content)
    |> Enum.join("\n")
  end

  def emails_for(id) do
    all_attendances = OsdiClient.stream(client(), "events/#{id}/attendances")
    people_ids = Enum.map(all_attendances, & &1.person)
{'fraction_non_alphanumeric': 0.15789473684210525, 'fraction_numerical': 0.0027910685805422647, 'mean_word_length': 2.4043419267299866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2532125', 'n_tokens_mistral': 899, 'n_tokens_neox': 875, 'n_words': 136}