<commit_before>defmodule Chess.Game do
  use Chess.Web, :model

  schema "games" do
    field :board, :map

    timestamps
  end

  @doc """
  Builds a changeset based on the `struct` and `params`.
  """
  def changeset(struct) do
    struct
    |> cast(%{}, [:board])
    |> set_default_board
    |> validate_required([:board])
  end

  def changeset(struct, params \\ %{}) do
    struct
    |> cast(params, [:board])
    |> validate_required([:board])
  end

  def ordered(query) do
    query
    |> order_by([game], game.id)
  end

  def set_default_board(changeset) do
    changeset
    |> put_change(:board, default_board)
  end

  def default_board do
    %{
      "8" => %{
        a: %{ type: "rook",   colour: "black" },
        b: %{ type: "knight", colour: "black" },
        c: %{ type: "bishop", colour: "black" },
        d: %{ type: "queen",  colour: "black" },
        e: %{ type: "king",   colour: "black" },
        f: %{ type: "bishop", colour: "black" },<commit_msg>Order by created time descending<commit_after>defmodule Chess.Game do
  use Chess.Web, :model

  schema "games" do
    field :board, :map

    timestamps
  end

  @doc """
  Builds a changeset based on the `struct` and `params`.
  """
  def changeset(struct) do
    struct
    |> cast(%{}, [:board])
    |> set_default_board
    |> validate_required([:board])
  end

  def changeset(struct, params \\ %{}) do
    struct
    |> cast(params, [:board])
    |> validate_required([:board])
  end

  def ordered(query) do
    query
    |> order_by([game], desc: game.inserted_at)
  end

  def set_default_board(changeset) do
    changeset
    |> put_change(:board, default_board)
  end

  def default_board do
    %{
      "8" => %{
        a: %{ type: "rook",   colour: "black" },
        b: %{ type: "knight", colour: "black" },
        c: %{ type: "bishop", colour: "black" },
        d: %{ type: "queen",  colour: "black" },
        e: %{ type: "king",   colour: "black" },
        f: %{ type: "bishop", colour: "black" },
{'fraction_non_alphanumeric': 0.1669990029910269, 'fraction_numerical': 0.0009970089730807576, 'mean_word_length': 2.635869565217391, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '6916177', 'n_tokens_mistral': 731, 'n_tokens_neox': 681, 'n_words': 185}