<commit_before>(ns load-test-client.core
  (:require [om.core :as om :include-macros true]
            [om.dom :as dom :include-macros true]
            [cljs.repl :as repl :include-macros true]
            [goog.events :as events]
            [goog.json :as gjson]
            [goog.net.XhrIo :as gxhr]
            [load-test-client.form :as form]
            [load-test-client.load-tests :as load-tests])
  (:import [goog.net XhrIo WebSocket]))

(defonce app-state
  (atom {:api {:http-url "http://localhost:3000/"
               :ws-url "ws://localhost:3000/"}
         :text "GoCardless Enterprise API Load Tester"
         :form {}
         :load-tests {}}))

(enable-console-print!)

(defn initial-selected-resource [resources]
  [(first (first resources))
   (first (second (first resources)))])

(defn handle-preset-response [app e]
  (let [json (js->clj (.. e -target getResponseJson))]
    (om/transact! app :form (fn [form]
                              (assoc form
                                     :resources (get json "resources")
                                     :url (get json "url")
                                     :duration (get json "duration")
                                     :rate (get json "rate")
                                     :selected-resource (initial-selected-resource (get json "resources")))))))

(defn handle-new-or-updated-load-test [app data]
  (om/transact! app :load-tests
                #(merge % (js->clj (gjson/parse data) :keywordize-keys true))))

(defn main []
  (om/root
    (fn [app owner]
      (reify
        om/IWillMount
        (will-mount [_]
          (let [ws (WebSocket.)
                ws-endpoint (str (-> app :api :ws-url) "load-tests")
                http-endpoint (str (-> app :api :http-url) "presets")]
            (gxhr/send http-endpoint (partial handle-preset-response app))
            (doto ws
              (events/listen WebSocket.EventType.MESSAGE #(handle-new-or-updated-load-test app (.-message %)))
              (.open ws-endpoint))
            (om/set-state! owner :load-tests-ws ws)))

        om/IWillUnmount
        (will-unmount [_]
          (.close (om/get-state owner :load-tests-ws)))

        om/IRender
        (render [_]
          (dom/div nil
                   (dom/header nil
                               (dom/div #js {:className "container"}
                                        (dom/h2 #js {:id "title"} (:text app))))<commit_msg>An excuse to use juxt :)<commit_after>(ns load-test-client.core
  (:require [om.core :as om :include-macros true]
            [om.dom :as dom :include-macros true]
            [cljs.repl :as repl :include-macros true]
            [goog.events :as events]
            [goog.json :as gjson]
            [goog.net.XhrIo :as gxhr]
            [load-test-client.form :as form]
            [load-test-client.load-tests :as load-tests])
  (:import [goog.net XhrIo WebSocket]))

(defonce app-state
  (atom {:api {:http-url "http://localhost:3000/"
               :ws-url "ws://localhost:3000/"}
         :text "GoCardless Enterprise API Load Tester"
         :form {}
         :load-tests {}}))

(enable-console-print!)

(defn handle-preset-response [app e]
  (let [json (js->clj (.. e -target getResponseJson))
        initial-selected-resource (juxt (comp first first)
                                        (comp first second first))]
    (om/transact! app :form (fn [form]
                              (assoc form
                                     :resources         (get json "resources")
                                     :url               (get json "url")
                                     :duration          (get json "duration")
                                     :rate              (get json "rate")
                                     :selected-resource (initial-selected-resource (get json "resources")))))))

(defn handle-new-or-updated-load-test [app data]
  (om/transact! app :load-tests
                #(merge % (js->clj (gjson/parse data) :keywordize-keys true))))

(defn main []
  (om/root
    (fn [app owner]
      (reify
        om/IWillMount
        (will-mount [_]
          (let [ws (WebSocket.)
                ws-endpoint (str (-> app :api :ws-url) "load-tests")
                http-endpoint (str (-> app :api :http-url) "presets")]
            (gxhr/send http-endpoint (partial handle-preset-response app))
            (doto ws
              (events/listen WebSocket.EventType.MESSAGE #(handle-new-or-updated-load-test app (.-message %)))
              (.open ws-endpoint))
            (om/set-state! owner :load-tests-ws ws)))

        om/IWillUnmount
        (will-unmount [_]
          (.close (om/get-state owner :load-tests-ws)))

        om/IRender
        (render [_]
          (dom/div nil
                   (dom/header nil
                               (dom/div #js {:className "container"}
                                        (dom/h2 #js {:id "title"} (:text app))))
{'fraction_non_alphanumeric': 0.1369035635192269, 'fraction_numerical': 0.0036239178578618887, 'mean_word_length': 1.5002516356316054, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5090498', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1423, 'n_words': 361}