<commit_before>module BarkSpider.View (..) where

import BarkSpider.Comms as Comms
import BarkSpider.Model as Model
import BarkSpider.Simulation exposing (Simulation, createSimulation)
import BarkSpider.Util exposing (distinctColors, noFx)
import Bootstrap.Html exposing (glyphiconChevronRight', glyphiconChevronDown', btnParam, btnDefault', row_, colSm_, containerFluid_, colMd_)
import Chartjs.Line exposing (defStyle, defaultOptions, chart)
import Color
import Dict
import Effects
import Html exposing (Html, node, span, input, div, label, text, textarea, fromElement, h1, hr)
import Html.Attributes exposing (rel, class, type', value, href, src)
import Html.Events exposing (on, targetValue)
import Html.Lazy
import String


type alias SimViewParams =
  { hidden : Bool
  }


defaultSimViewParams : SimViewParams
defaultSimViewParams =
  { hidden = False }


type alias ViewModel =
  { model : Model.Model
  , sim_view_params : Dict.Dict Model.ID SimViewParams
  , next_id : Model.ID
  }

-- TODO: Consider constructing an alternative type for use in rendering which
-- coalesces the view and non-view model elements under a single dict.

defaultViewModel : ViewModel
defaultViewModel =
  { model = Model.createModel
  , sim_view_params = Dict.empty
  , next_id = 0
  }


type SimulationAction
  = Delete
  | SetHidden Bool
  | SetAssimilationDelay Int
  | SetTrainingOverheadProportion Float
  | SetInterventions String
  | SetName String
  | SetIncluded Bool


type Action
  = AddSimulation Simulation
  | ModifySimulation Model.ID SimulationAction
  | RunSimulation


updateSimulation : SimulationAction -> Simulation -> Simulation
updateSimulation action sim =
  case action of
    SetHidden hidden ->
      -- TODO
      sim

    SetAssimilationDelay delay ->
      -- TODO
      sim

    SetTrainingOverheadProportion overhead ->
      --TODO
      sim

    SetInterventions interventions ->
      -- TODO
      sim

    SetName name ->
      -- TODO
      sim

    SetIncluded included ->
      -- TODO
      sim

    Delete ->
      sim


{-| Replace the simulation at an ID in a view model with a new simulation.
-}
modifySimulation : ViewModel -> Model.ID -> Simulation -> ViewModel
modifySimulation viewModel id sim =
  let
    sims =
      Dict.insert id sim viewModel.model.simulations

    mod =
      viewModel.model

    model =
      { mod
        | simulations = sims
      }
  in
    { viewModel
      | model = model
    }


update : Action -> ViewModel -> ( ViewModel, Effects.Effects Action )
update action viewModel =
  case action of
    AddSimulation sim ->
      let
        id =
          viewModel.next_id

        model =
          Model.addSimulation viewModel.model id sim
      in
        { viewModel
          | model = model
          , next_id = id + 1
        }
          |> noFx

    ModifySimulation id Delete ->
      -- TODO
      noFx viewModel

    ModifySimulation id simAction ->
      case (Dict.get id viewModel.model.simulations) of
        Just sim ->
          modifySimulation viewModel id (updateSimulation simAction sim)
            |> noFx

        Nothing ->
          -- TODO: What to do here?
          noFx viewModel

    RunSimulation ->
      -- TODO
      noFx viewModel



-- Simulation view
<commit_msg>I think I've reached the end of this experiment.<commit_after>module BarkSpider.View (..) where

import BarkSpider.Comms as Comms
import BarkSpider.Model as Model
import BarkSpider.Simulation exposing (Simulation, createSimulation)
import BarkSpider.Util exposing (distinctColors, noFx)
import Bootstrap.Html exposing (glyphiconChevronRight', glyphiconChevronDown', btnParam, btnDefault', row_, colSm_, containerFluid_, colMd_)
import Chartjs.Line exposing (defStyle, defaultOptions, chart)
import Color
import Dict
import Effects
import Html exposing (Html, node, span, input, div, label, text, textarea, fromElement, h1, hr)
import Html.Attributes exposing (rel, class, type', value, href, src)
import Html.Events exposing (on, targetValue)
import Html.Lazy
import String


type alias SimViewParams =
  { hidden : Bool
  }


defaultSimViewParams : SimViewParams
defaultSimViewParams =
  { hidden = False }


type alias ViewModel =
  { model : Model.Model
  , sim_view_params : Dict.Dict Model.ID SimViewParams
  , next_id : Model.ID
  }

-- TODO: Consider constructing an alternative type for use in rendering which
-- coalesces the view and non-view model elements under a single dict.

defaultViewModel : ViewModel
defaultViewModel =
  { model = Model.createModel
  , sim_view_params = Dict.empty
  , next_id = 0
  }


type SimulationAction
  = Delete
  | SetAssimilationDelay Int
  | SetTrainingOverheadProportion Float
  | SetInterventions String
  | SetName String
  | SetIncluded Bool

type SimulationViewAction
  = SetHidden Bool

type Action
  = AddSimulation Simulation
  | ModifySimulation Model.ID SimulationAction
  | ModifySimulationView Model.ID SimulationViewAction
  | RunSimulation


updateSimulation : SimulationAction -> Simulation -> Simulation
updateSimulation action sim =
  case action of
    SetAssimilationDelay delay ->
      -- TODO
      sim

    SetTrainingOverheadProportion overhead ->
      --TODO
      sim

    SetInterventions interventions ->
      -- TODO
      sim

    SetName name ->
      -- TODO
      sim

    SetIncluded included ->
      -- TODO
      sim

    Delete ->
      sim

updateSimulationView : SimulationViewAction -> SimViewParams -> SimViewParams
updateSimulationView action params =
  case action of
    SetHidden hidden ->
      { params
        | hidden = hidden
      }

{-| Replace the simulation at an ID in a view model with a new simulation.
-}
modifySimulation : ViewModel -> Model.ID -> Simulation -> ViewModel
modifySimulation viewModel id sim =
  let
    sims =
      Dict.insert id sim viewModel.model.simulations

    mod =
      viewModel.model

    model =
      { mod
        | simulations = sims
      }
  in
    { viewModel
      | model = model
    }

{-| Replace the simulationview at an ID in a view model with new params
 -}
modifySimulationView : ViewModel -> Model.ID -> SimViewParams -> ViewModel
modifySimulationView viewModel id simViewParams =
  let
    svps =
      Dict.insert id simViewParams viewModel.sim_view_params

    mod =
      viewModel.model

    model =
      { mod
        | sim_view_params = svps
      }
  in
    { viewModel
      | model = model
    }

update : Action -> ViewModel -> ( ViewModel, Effects.Effects Action )
update action viewModel =
  case action of
    AddSimulation sim ->
      let
        id =
          viewModel.next_id

        model =
          Model.addSimulation viewModel.model id sim
      in
        { viewModel
          | model = model
          , next_id = id + 1
        }
          |> noFx

    ModifySimulation id Delete ->
      -- TODO
      noFx viewModel

    ModifySimulation id simAction ->
      case (Dict.get id viewModel.model.simulations) of
        Just sim ->
          modifySimulation viewModel id (updateSimulation simAction sim)
            |> noFx

        Nothing ->
          -- TODO: What to do here?
          noFx viewModel

    ModifySimulation id simAction ->
      case (Dict.get id viewModel.model.simulations) of
        Just sim ->
          modifySimulation viewModel id (updateSimulation simAction sim)
            |> noFx

        Nothing ->
          -- TODO: What to do here?
          noFx viewModel

    RunSimulation ->
      -- TODO
      noFx viewModel



-- Simulation view

{'fraction_non_alphanumeric': 0.06870431893687708, 'fraction_numerical': 0.0007973421926910299, 'mean_word_length': 2.5433145009416194, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 56, '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': '5385697', 'n_tokens_mistral': 2225, 'n_tokens_neox': 2119, 'n_words': 673}