<commit_before>defmodule Api.CompetitionActions do
  use Api.Web, :action

  alias Api.{Competition, TeamActions, Vote, PaperVote, Team, Category, User}
  alias Ecto.{Changeset}

  defp _get do
    Repo.one(from(c in Competition)) || %Competition{}
  end

  defp _change(params) do
    _get()
    |> Competition.changeset(params)
    |> Repo.insert_or_update
  end

  defp missing_voters do
    voters = from(v in Vote,
      join: u in assoc(v, :voter),
      select: u.id) |> Repo.all()

    missing_voters = from u in User,
      join: tm in assoc(u, :teams),
      join: t in assoc(tm, :team),
      where: u.id not in ^voters,
      select: {t, u}

    Repo.all(missing_voters)
    |> Enum.group_by(fn {team, _} -> team end, fn {_, user} -> user end)
    |> Enum.map(fn {k, v} -> %{team: k, users: v} end)

  end

  defp unredeemed_paper_votes do
    paper_votes = from pv in PaperVote,
      where: is_nil(pv.redeemed_at) and is_nil(pv.annulled_at),
      preload: [:category]

      Repo.all(paper_votes)
  end

  def start_voting do
    case voting_status() do
      :not_started ->
        TeamActions.shuffle_tie_breakers
        TeamActions.assign_missing_preferences
        _change(%{voting_started_at: DateTime.utc_now})
      :started -> {:error, :already_started}
      :ended -> {:error, :already_ended}
    end
  end
<commit_msg>Fix syntax<commit_after>defmodule Api.CompetitionActions do
  use Api.Web, :action

  alias Api.{Competition, TeamActions, Vote, PaperVote, Team, Category, User}
  alias Ecto.{Changeset}

  defp _get do
    Repo.one(from(c in Competition)) || %Competition{}
  end

  defp _change(params) do
    _get()
    |> Competition.changeset(params)
    |> Repo.insert_or_update
  end

  defp missing_voters do
    voters =
      from(
        v in Vote,
        join: u in assoc(v, :voter),
        select: u.id
      )
      |> Repo.all()

    missing_voters = from(
      u in User,
      join: tm in assoc(u, :teams),
      join: t in assoc(tm, :team),
      where: not (u.id in ^voters),
      order_by: u.id,
      select: {t, u}
    )

    Repo.all(missing_voters)
    |> Enum.group_by(fn {team, _} -> team end, fn {_, user} -> user end)
    |> Enum.map(fn {k, v} -> %{team: k, users: v} end)

  end

  defp unredeemed_paper_votes do
    paper_votes = from pv in PaperVote,
      where: is_nil(pv.redeemed_at) and is_nil(pv.annulled_at),
      preload: [:category]

      Repo.all(paper_votes)
  end

  def start_voting do
    case voting_status() do
      :not_started ->
        TeamActions.shuffle_tie_breakers
        TeamActions.assign_missing_preferences
        _change(%{voting_started_at: DateTime.utc_now})
      :started -> {:error, :already_started}
      :ended -> {:error, :already_ended}
    end
  end

{'fraction_non_alphanumeric': 0.11992753623188405, 'fraction_numerical': 0.0, 'mean_word_length': 2.721024258760108, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '3379588', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1015, 'n_words': 248}