<commit_before>module Components.View
    exposing
        ( Model
        , Msg(..)
        , init
        , update
        , view
        , subscriptions
        , updateLevels
        , updateWindow
        )

-- elm.core

import Html exposing (Html, text, ul, li, a, h3, div, input, span)
import Html.Attributes exposing (style, type', checked)
import Html.Events exposing (onClick)
import Svg as S exposing (svg)
import Svg.Attributes as S
import Svg.Events as S
import Date exposing (Date)
import RemoteData as RD
import Http
import Basics.Extra exposing (never)
import Task


-- extra

import Date.Extra.Period as DP


-- ours

import Api.Apps as Apps
import Ports
import Out
import Helpers exposing (class, twoimap)
import RCSS


type alias ViewData =
    { timings : List ( Int, Int )
    , id : String
    , ceiling : Int
    , floor : Int
    }


type alias Model =
    { data : RD.WebData ViewData
    , app : String
    , name : String
    , hosts : List String
    , graph : Bool
    , checked : Bool
    , trap : Maybe Int
    , start : Maybe Date
    , end : Maybe Date
    , floor : Int
    , ceiling : Int
    , globalFloor : Int
    , globalFloorI : String
    , globalCeiling : Int
    , globalCeilingI : String
    , globalLevels : Bool
    }


init :
    Int
    -> String
    -> Int
    -> String
    -> Bool
    -> String
    -> Apps.View
    -> ( Model, Cmd Msg )
init floor floorI ceiling ceilingI global app view =
    ( { data = RD.NotAsked
      , app = app
      , name = view.name
      , hosts = view.hosts
      , graph = False
      , checked = False
      , trap = Nothing
      , start = Nothing
      , end = Nothing
      , floor = 0
      , ceiling = 0
      , globalFloor = floor
      , globalFloorI = floorI
      , globalCeiling = ceiling
      , globalCeilingI = ceilingI
      , globalLevels = global
      }
    , Cmd.batch
        (List.map
            (\f -> Ports.get_key (f app view.name))
            [ key1, key2 ]
        )
    )


key1 : String -> String -> String
key1 a n =
    "key_" ++ a ++ "_" ++ n ++ "_1"


key2 : String -> String -> String
key2 a n =
    "key_" ++ a ++ "_" ++ n ++ "_2"


type Msg
    = ToggleGraph
    | ToggleCheck
    | DateFetched Date.Date
    | ViewDataFetched ( String, ( String, String, String ), ( Int, Int ), List ( Int, Int ) )
    | KeyData ( String, ( Bool, String ) )
    | LineClick Int
    | GotJson Apps.JsonResp
    | JsonFailed Http.Error
    | TrapMouseIn Int
    | TrapMouseOut Int


updateLevels : Int -> String -> Int -> String -> Bool -> Model -> ( Model, Cmd Msg )
updateLevels floor floorI ceiling ceilingI global model =
    ( { model
        | globalFloor = floor
        , globalFloorI = floorI
        , globalCeiling = ceiling
        , globalCeilingI = ceilingI
        , globalLevels = global
      }
      -- TODO refresh the graph
    , Cmd.none
    )


updateWindow : Date -> Date -> Model -> ( Model, Cmd Msg )
updateWindow start end model =
    ( { model | start = Just start, end = Just end }
      -- TODO refresh the graph
    , Cmd.none
    )


floor : Model -> Int
floor model =
    if model.globalLevels then
        model.globalFloor
    else
        0


floorI : Model -> String
floorI model =
    if model.globalLevels then
        model.globalFloorI
    else
        case model.data of
            RD.Success data ->
                (toString data.floor)

            _ ->
                "unknown"


ceiling : Model -> Int
ceiling model =
    if model.globalLevels then
        model.globalFloor
    else
        0


ceilingI : Model -> String
ceilingI model =
    if model.globalLevels then
        model.globalCeilingI
    else
        case model.data of
            RD.Success data ->
                (toString data.ceiling)

            _ ->
                "unknown"


update : Msg -> Model -> ( Model, Cmd Msg, Maybe Out.Msg )
update msg model =
    case Debug.log "P.View" msg of
        ToggleCheck ->
            ( { model | checked = not model.checked }
            , (Ports.set_key
                ( key1 model.app model.name
                , if model.checked then
                    ""
                  else
                    "open"
                )<commit_msg>stupid bug<commit_after>module Components.View
    exposing
        ( Model
        , Msg(..)
        , init
        , update
        , view
        , subscriptions
        , updateLevels
        , updateWindow
        )

-- elm.core

import Html exposing (Html, text, ul, li, a, h3, div, input, span)
import Html.Attributes exposing (style, type', checked)
import Html.Events exposing (onClick)
import Svg as S exposing (svg)
import Svg.Attributes as S
import Svg.Events as S
import Date exposing (Date)
import RemoteData as RD
import Http
import Basics.Extra exposing (never)
import Task


-- extra

import Date.Extra.Period as DP


-- ours

import Api.Apps as Apps
import Ports
import Out
import Helpers exposing (class, twoimap)
import RCSS


type alias ViewData =
    { timings : List ( Int, Int )
    , id : String
    , ceiling : Int
    , floor : Int
    }


type alias Model =
    { data : RD.WebData ViewData
    , app : String
    , name : String
    , hosts : List String
    , graph : Bool
    , checked : Bool
    , trap : Maybe Int
    , start : Maybe Date
    , end : Maybe Date
    , floor : Int
    , ceiling : Int
    , globalFloor : Int
    , globalFloorI : String
    , globalCeiling : Int
    , globalCeilingI : String
    , globalLevels : Bool
    }


init :
    Int
    -> String
    -> Int
    -> String
    -> Bool
    -> String
    -> Apps.View
    -> ( Model, Cmd Msg )
init floor floorI ceiling ceilingI global app view =
    ( { data = RD.NotAsked
      , app = app
      , name = view.name
      , hosts = view.hosts
      , graph = False
      , checked = False
      , trap = Nothing
      , start = Nothing
      , end = Nothing
      , floor = 0
      , ceiling = 0
      , globalFloor = floor
      , globalFloorI = floorI
      , globalCeiling = ceiling
      , globalCeilingI = ceilingI
      , globalLevels = global
      }
    , Cmd.batch
        (List.map
            (\f -> Ports.get_key (f app view.name))
            [ key1, key2 ]
        )
    )


key1 : String -> String -> String
key1 a n =
    "key_" ++ a ++ "_" ++ n ++ "_1"


key2 : String -> String -> String
key2 a n =
    "key_" ++ a ++ "_" ++ n ++ "_2"


type Msg
    = ToggleGraph
    | ToggleCheck
    | DateFetched Date.Date
    | ViewDataFetched ( String, ( String, String, String ), ( Int, Int ), List ( Int, Int ) )
    | KeyData ( String, ( Bool, String ) )
    | LineClick Int
    | GotJson Apps.JsonResp
    | JsonFailed Http.Error
    | TrapMouseIn Int
    | TrapMouseOut Int


updateLevels : Int -> String -> Int -> String -> Bool -> Model -> ( Model, Cmd Msg )
updateLevels floor floorI ceiling ceilingI global model =
    ( { model
        | globalFloor = floor
        , globalFloorI = floorI
        , globalCeiling = ceiling
        , globalCeilingI = ceilingI
        , globalLevels = global
      }
      -- TODO refresh the graph
    , Cmd.none
    )


updateWindow : Date -> Date -> Model -> ( Model, Cmd Msg )
updateWindow start end model =
    ( { model | start = Just start, end = Just end }
      -- TODO refresh the graph
    , Cmd.none
    )


floor : Model -> Int
floor model =
    if model.globalLevels then
        model.globalFloor
    else
        0


floorI : Model -> String
floorI model =
    if model.globalLevels then
        model.globalFloorI
    else
        case model.data of
            RD.Success data ->
                (toString data.floor)

            _ ->
                "unknown"


ceiling : Model -> Int
ceiling model =
    if model.globalLevels then
        model.globalCeiling
    else
        0


ceilingI : Model -> String
ceilingI model =
    if model.globalLevels then
        model.globalCeilingI
    else
        case model.data of
            RD.Success data ->
                (toString data.ceiling)

            _ ->
                "unknown"


update : Msg -> Model -> ( Model, Cmd Msg, Maybe Out.Msg )
update msg model =
    case Debug.log "P.View" msg of
        ToggleCheck ->
            ( { model | checked = not model.checked }
            , (Ports.set_key
                ( key1 model.app model.name
                , if model.checked then
                    ""
                  else
                    "open"
                )
{'fraction_non_alphanumeric': 0.0939022940687032, 'fraction_numerical': 0.0033281825745869486, 'mean_word_length': 1.6779121578612348, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 67, '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': '3369564', 'n_tokens_mistral': 2660, 'n_tokens_neox': 2509, 'n_words': 789}