<commit_before>module IdeaFight.Compete exposing (Model, Msg, init, update, subscriptions, view)

import IdeaFight.PartialForest as Forest
import IdeaFight.Shuffle as Shuffle

import Html.App as App
import Html exposing (Html, br, button, div, li, text, ul)
import Html.Attributes exposing (class)
import Html.Events exposing (onClick)

import Random
import String

type Model = Uninitialized | Initialized (Forest.Forest String)
type Msg = ShuffledContents (List String) | Choice String

init : String -> (Model, Cmd Msg)
init contents =
  let lines = String.lines contents
  in (Uninitialized, Random.generate ShuffledContents <| Shuffle.shuffle lines)

update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
  case model of
    Uninitialized ->
      case msg of
        ShuffledContents contents -> (Initialized <| Forest.fromList contents, Cmd.none)
        _ -> Debug.crash "Somehow you got a non-initialization message on an uninitialized state"
    Initialized forest ->
      case msg of
        Choice choice -> (Initialized <| Forest.choose forest choice, Cmd.none)
        _ -> Debug.crash "Somehow you got an initialization message on an initialized state"

subscriptions : Model -> Sub Msg
subscriptions _ = Sub.none

chooser : Forest.Forest String -> Html Msg
chooser forest =
  case Forest.getNextPair forest of
    Just (lhs, rhs) -> div [] [
      text "Which of these ideas do you like better?",
      br [] [],
      button [onClick <| Choice lhs, class "button-primary"] [text lhs],
      button [onClick <| Choice rhs, class "button-primary"] [text rhs]
    ]<commit_msg>Trim excess whitespace from input<commit_after>module IdeaFight.Compete exposing (Model, Msg, init, update, subscriptions, view)

import IdeaFight.PartialForest as Forest
import IdeaFight.Shuffle as Shuffle

import Html.App as App
import Html exposing (Html, br, button, div, li, text, ul)
import Html.Attributes exposing (class)
import Html.Events exposing (onClick)

import Random
import String

type Model = Uninitialized | Initialized (Forest.Forest String)
type Msg = ShuffledContents (List String) | Choice String

init : String -> (Model, Cmd Msg)
init contents =
  let lines = String.lines <| String.trim contents
  in (Uninitialized, Random.generate ShuffledContents <| Shuffle.shuffle lines)

update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
  case model of
    Uninitialized ->
      case msg of
        ShuffledContents contents -> (Initialized <| Forest.fromList contents, Cmd.none)
        _ -> Debug.crash "Somehow you got a non-initialization message on an uninitialized state"
    Initialized forest ->
      case msg of
        Choice choice -> (Initialized <| Forest.choose forest choice, Cmd.none)
        _ -> Debug.crash "Somehow you got an initialization message on an initialized state"

subscriptions : Model -> Sub Msg
subscriptions _ = Sub.none

chooser : Forest.Forest String -> Html Msg
chooser forest =
  case Forest.getNextPair forest of
    Just (lhs, rhs) -> div [] [
      text "Which of these ideas do you like better?",
      br [] [],
      button [onClick <| Choice lhs, class "button-primary"] [text lhs],
      button [onClick <| Choice rhs, class "button-primary"] [text rhs]
    ]
{'fraction_non_alphanumeric': 0.09062789978348283, 'fraction_numerical': 0.0, 'mean_word_length': 3.606837606837607, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 27, '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': '75039', 'n_tokens_mistral': 936, 'n_tokens_neox': 937, 'n_words': 357}