<commit_before>(ns inspect.communicator
  (:require-macros [cljs.core.match.macros :refer (match)]
                   [cljs.core.async.macros :refer [go-loop go]])
  (:require [inspect.appstate :as appstate]
            [cljs.core.match]
            [taoensso.sente  :as sente :refer (cb-success?)]
            [cljs.core.async :as async :refer [<! >! chan put! alts! timeout]]))

(enable-console-print!)

(let [{:keys [chsk ch-recv send-fn state]} (sente/make-channel-socket! "/chsk")]
  (def chsk chsk)
  (def ch-chsk ch-recv)    ; ChannelSocket's receive channel
  (def chsk-send! send-fn) ; ChannelSocket's send API fn
  (def chsk-state state))  ; Watchable, read-only atom

(defn- receive-stats
  [stats]
  (when (empty? @appstate/stats)
    (reset! appstate/selected (into #{} (map (fn [[t _]] t) (seq stats)))))
  (reset! appstate/stats stats))

(defn- event-handler [{:keys [event]}]
  (match event
         [:chsk/recv payload]
         (match payload
                [:info/msg msg] (swap! appstate/app assoc :events (conj (:events @appstate/app) msg))
                [:info/stats stats] (receive-stats stats)
                [:info/client-map client-map] (reset! appstate/client-map client-map)
                :else (print "Unkown msg-type " payload))
         [:chsk/state state] (when (:open? state)
                               (chsk-send! [:cmd/get-stats])
                               (chsk-send! [:cmd/initialize {:n 10}]))
         :else (print "Unmatched event: %s" event)))<commit_msg>cleanup<commit_after>(ns inspect.communicator
  (:require-macros [cljs.core.match.macros :refer (match)]
                   [cljs.core.async.macros :refer [go-loop go]])
  (:require [inspect.appstate :as appstate]
            [cljs.core.match]
            [taoensso.sente  :as sente :refer (cb-success?)]
            [cljs.core.async :as async :refer [<! >! chan put! alts! timeout]]))

(enable-console-print!)

(let [{:keys [chsk ch-recv send-fn state]} (sente/make-channel-socket! "/chsk")]
  (def chsk chsk)
  (def ch-chsk ch-recv)    ; ChannelSocket's receive channel
  (def chsk-send! send-fn) ; ChannelSocket's send API fn
  (def chsk-state state))  ; Watchable, read-only atom

(defn- receive-stats
  [stats]
  (when (empty? @appstate/stats) (reset! appstate/selected (into #{} (map (fn [[t _]] t) stats))))
  (reset! appstate/stats stats))

(defn- event-handler [{:keys [event]}]
  (match event
         [:chsk/recv payload]
         (match payload
                [:info/msg msg] (swap! appstate/app assoc :events (conj (:events @appstate/app) msg))
                [:info/stats stats] (receive-stats stats)
                [:info/client-map client-map] (reset! appstate/client-map client-map)
                :else (print "Unkown msg-type " payload))
         [:chsk/state state] (when (:open? state)
                               (chsk-send! [:cmd/get-stats])
                               (chsk-send! [:cmd/initialize {:n 10}]))
         :else (print "Unmatched event: %s" event)))
{'fraction_non_alphanumeric': 0.1590153027278776, 'fraction_numerical': 0.0013306719893546241, 'mean_word_length': 2.424829157175399, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5089377', 'n_tokens_mistral': 1030, 'n_tokens_neox': 993, 'n_words': 254}