<commit_before>module UserStudyLog exposing (log, logModelUpdate)

import InterfaceModel exposing (..)

import Native.UserStudyLog

import String


log : String -> String -> ()
log eventName info =
  Native.UserStudyLog.log eventName info


logModelUpdate updateFunc msg model =
  let (Msg msgName _) = msg in
  let _ =
    case msgInfo msg model of
      Just info -> log msgName <| "{ " ++ info ++ " }"
      Nothing   -> ()
  in
  let (newModel, cmd) =
    updateFunc msg model
  in
  let _ =
    let somethingSelected model =
      model.codeBoxInfo.selections |> List.any (\range -> range.start /= range.end)
    in
    if model.codeBoxInfo.selections /= newModel.codeBoxInfo.selections && (somethingSelected model || somethingSelected newModel) then
      log "Text Selection Changed" (if somethingSelected newModel then "Non-empty" else "Empty")
    else if model.codeBoxInfo.cursorPos /= newModel.codeBoxInfo.cursorPos && model.code == newModel.code then
      log "Text Cursor Moved" ""
    else
      ()
  in
  let _ =
    if model.code /= newModel.code
    then log "New Code" (toString newModel.code)
    else ()
  in
  let _ =
    case (msgName, newModel.errorBox) of
      ("Run", Nothing)     -> log "Run Success" ""
      ("Run", Just errMsg) -> log "Run Error" (toString errMsg)
      _                    -> ()
  in
  (newModel, cmd)


msgInfo (Msg msgName updater) model =
  case msgName of
    "Ace Update" -> Nothing

    _ ->
      let info = "\"deuceSelectionsCount\" : " ++ toString (List.length model.deuceState.selectedWidgets) in
      if String.startsWith "MousePosition" msgName
      then Nothing
      else Just info<commit_msg>Log actual selection ranges (for possible later reconstruction)<commit_after>module UserStudyLog exposing (log, logModelUpdate)

import InterfaceModel exposing (..)

import Native.UserStudyLog

import String


log : String -> String -> ()
log eventName info =
  Native.UserStudyLog.log eventName info


logModelUpdate updateFunc msg model =
  let (Msg msgName _) = msg in
  let _ =
    case msgInfo msg model of
      Just info -> log msgName <| "{ " ++ info ++ " }"
      Nothing   -> ()
  in
  let (newModel, cmd) =
    updateFunc msg model
  in
  let _ =
    let nonEmptySelections model =
      model.codeBoxInfo.selections
      |> List.filter (\range -> range.start /= range.end)
    in
    let rangeToJson {start, end} =
      let posToJson {row, column} =
        "{ " ++ "\"row\" : " ++ toString row ++ ", \"column\" : " ++ toString column ++ " }"
      in
      "{ " ++ "\"start\" : " ++ posToJson start ++ ", \"end\" : " ++ posToJson end ++ " }"
    in
    let rangeListToJson ranges =
      "[ " ++ String.join ", " (List.map rangeToJson ranges) ++ " ]"
    in
    let somethingSelected model = nonEmptySelections model /= [] in
    if model.codeBoxInfo.selections /= newModel.codeBoxInfo.selections && (somethingSelected model || somethingSelected newModel) then
      log "Text Selection Changed" (rangeListToJson (nonEmptySelections newModel))
    else if model.codeBoxInfo.cursorPos /= newModel.codeBoxInfo.cursorPos && model.code == newModel.code then
      log "Text Cursor Moved" ""
    else
      ()
  in
  let _ =
    if model.code /= newModel.code
    then log "New Code" (toString newModel.code)
    else ()
  in
  let _ =
    case (msgName, newModel.errorBox) of
      ("Run", Nothing)     -> log "Run Success" ""
      ("Run", Just errMsg) -> log "Run Error" (toString errMsg)
      _                    -> ()
  in
  (newModel, cmd)


msgInfo (Msg msgName updater) model =
  case msgName of
    "Ace Update" -> Nothing

    _ ->
      let info = "\"deuceSelectionsCount\" : " ++ toString (List.length model.deuceState.selectedWidgets) in
      if String.startsWith "MousePosition" msgName
      then Nothing
      else Just info
{'fraction_non_alphanumeric': 0.11647429171038824, 'fraction_numerical': 0.0, 'mean_word_length': 2.659309021113244, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '1417721', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1154, 'n_words': 342}