<commit_before>module Update (update) where
import Model exposing (..)
import Actions exposing (..)
import Effects exposing (Effects)
import Time exposing (Time)
import Random
import DeliveryPerson exposing (Location(..))
import Article exposing (State(..), Article)
import Request
import Obstacle exposing (Obstacle)
import Warehouse exposing (Warehouse)
import House exposing (House)
import Request exposing (Request)

update : Action -> Model -> (Model, Effects Action)
update action model =
  case action of
    Init time ->
      ( {model | seed = Random.initialSeed (floor time)}
      , Effects.tick (always Start)
      )
    Start ->
      ({model | state = Playing }, Effects.tick Tick)
    Tick time ->
      if model.state == Playing then
        (Model.animate time animate model, Effects.tick Tick)
      else
        ({model | animationState = Nothing}, Effects.none)
    ClickArticle article ->
        (onArticleClick article model, Effects.none)
    ClickHouse house ->
        (onHouseClick house model, Effects.none)
    ClickWarehouse warehouse ->
        (onWarehouseClick warehouse model, Effects.none)
    ClickRequest request ->
        (onRequestClick request model, Effects.none)


animate : Time -> Model -> Model
animate elapsed model =
  model |> animateObstacles elapsed


animateObstacles : Time -> Model -> Model
animateObstacles elapsed model =
  { model | obstacles = List.map (Obstacle.animate elapsed) model.obstacles }


-- calculate the route
onWarehouseClick : Warehouse -> Model -> Model
onWarehouseClick warehouse model =
  model


-- calculate the route
onHouseClick : House -> Model -> Model
onHouseClick house model =
  model


onRequestClick : Request -> Model -> Model
onRequestClick request model =
  model


onArticleClick : Article -> Model -> Model
onArticleClick article model =
  case model.deliveryPerson.location of
    AtHouse house ->
      case article.state of
        AwaitingReturn house' ->
          if house' == house then
            { model | requests = Request.removeReturns house article model.requests
                    , articles = Article.updateState Picked article model.articles
            }
          else
            model
        Picked ->
          if Request.hasOrder house article.category model.requests then
            { model | requests = Request.removeOrders house article.category model.requests
                    , articles = Article.removeDelivered house article.category model.articles
                                |> Article.updateState (Delivered house) article
            }
          else
            model
        _ ->
          model

    AtWarehouse warehouse' ->
      case article.state of
        InStock warehouse ->
          if warehouse == warehouse' then
            {model | articles = Article.updateState Picked article model.articles}
          else
            model
        Picked ->
          if List.length (Article.filterInWarehouse warehouse' model.articles) < 6 then
            {model | articles = Article.updateState (InStock warehouse') article model.articles}
          else
            model
        _ -> model

    OnTheWay -> model
<commit_msg>Added placeholder for delivery animation<commit_after>module Update (update) where
import Model exposing (..)
import Actions exposing (..)
import Effects exposing (Effects)
import Time exposing (Time)
import Random
import DeliveryPerson exposing (Location(..))
import Article exposing (State(..), Article)
import Request
import Obstacle exposing (Obstacle)
import Warehouse exposing (Warehouse)
import House exposing (House)
import Request exposing (Request)

update : Action -> Model -> (Model, Effects Action)
update action model =
  case action of
    Init time ->
      ( {model | seed = Random.initialSeed (floor time)}
      , Effects.tick (always Start)
      )
    Start ->
      ({model | state = Playing }, Effects.tick Tick)
    Tick time ->
      if model.state == Playing then
        (Model.animate time animate model, Effects.tick Tick)
      else
        ({model | animationState = Nothing}, Effects.none)
    ClickArticle article ->
        (onArticleClick article model, Effects.none)
    ClickHouse house ->
        (onHouseClick house model, Effects.none)
    ClickWarehouse warehouse ->
        (onWarehouseClick warehouse model, Effects.none)
    ClickRequest request ->
        (onRequestClick request model, Effects.none)


animate : Time -> Model -> Model
animate elapsed model =
  model |> animateObstacles elapsed
        |> animateDeliveryPerson elapsed


animateObstacles : Time -> Model -> Model
animateObstacles elapsed model =
  { model | obstacles = List.map (Obstacle.animate elapsed) model.obstacles }


animateDeliveryPerson : Time -> Model -> Model
animateDeliveryPerson elapsed model =
  model


-- calculate the route
onWarehouseClick : Warehouse -> Model -> Model
onWarehouseClick warehouse model =
  model


-- calculate the route
onHouseClick : House -> Model -> Model
onHouseClick house model =
  model


onRequestClick : Request -> Model -> Model
onRequestClick request model =
  model


onArticleClick : Article -> Model -> Model
onArticleClick article model =
  case model.deliveryPerson.location of
    AtHouse house ->
      case article.state of
        AwaitingReturn house' ->
          if house' == house then
            { model | requests = Request.removeReturns house article model.requests
                    , articles = Article.updateState Picked article model.articles
            }
          else
            model
        Picked ->
          if Request.hasOrder house article.category model.requests then
            { model | requests = Request.removeOrders house article.category model.requests
                    , articles = Article.removeDelivered house article.category model.articles
                                |> Article.updateState (Delivered house) article
            }
          else
            model
        _ ->
          model

    AtWarehouse warehouse' ->
      case article.state of
        InStock warehouse ->
          if warehouse == warehouse' then
            {model | articles = Article.updateState Picked article model.articles}
          else
            model
        Picked ->
          if List.length (Article.filterInWarehouse warehouse' model.articles) < 6 then
            {model | articles = Article.updateState (InStock warehouse') article model.articles}
          else
            model
        _ -> model

    OnTheWay -> model

{'fraction_non_alphanumeric': 0.07714768710619332, 'fraction_numerical': 0.0003073613032119256, 'mean_word_length': 2.4397463002114166, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 70, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '850471', 'n_tokens_mistral': 1715, 'n_tokens_neox': 1559, 'n_words': 548}