<commit_before>(ns ^:figwheel-always sidequarter-frontend.core
    (:require-macros [cljs.core.async.macros :refer [go]])
    (:require[om.core :as om :include-macros true]
             [om.dom :as dom :include-macros true]
             [cljs.core.async :refer [<!]]
             [cljsjs.chartist]
             [sidequarter-frontend.api :as api]))

(enable-console-print!)

(println "Edits to this text should show up in your developer console.")

;; define your app data so that it doesn't get over-written on reload

(defonce app-state (atom {}))

(defn sidekiq-stats-view [data owner]
  (reify
    om/IInitState
    (init-state [_]
      {:stats { :busy 0 :enqueued 0 :scheduled 0 :retries 0 :failed 0 :processed 0}})
    om/IWillMount
    (will-mount [_]
      (go
        (let [response ((<! (api/get-stats (data :id))) :body)
              stats (:stats response)]
          (om/set-state! owner :stats stats))))
    om/IRenderState
    (render-state [_ {:keys [stats]}]
      (dom/ul #js {:className "sidekiq-stats h-list"}
              (dom/li nil (str "Busy: " (stats :busy)))
              (dom/li nil (str "Enqueued: " (stats :enqueued)))
              (dom/li nil (str "Scheduled: " (stats :scheduled)))
              (dom/li nil (str "Retries: " (stats :retries)))
              (dom/li nil (str "Failed: " (stats :failed)))
              (dom/li nil (str "Processed: " (stats :processed)))))))

(defn sidekiq-redis-view [data owner]
  (om/component
   (dom/ul #js {:className "sidekiq-redis-info"}
           (dom/li nil
                   (dom/strong nil "Namespace: ")
                   (dom/span nil (data :namespace)))
           (dom/li nil
                   (dom/strong nil "Redis URL: ")
                   (dom/span nil (data :redis_url))))))

(defn sidekiq-poll-stats [data owner]
  (reify
    om/IInitState
    (init-state [_]
      {:graph [] :interval-id nil :graph-chart nil})
    om/IDidMount
    (did-mount [_]
      (let [interval-id
            (js/setInterval
             (fn []
               (go
                 (let [response ((<! (api/get-stats (data :id))) :body)
                       stats (:stats response)]
                   (om/update-state! owner [:graph] #(conj % stats))))
               ) 2000)
            g (.-Line js/Chartist)
            graph-chart (g. (str "#graph-" (data :id)) #js{:labels #js["", ""], :series #js[#js[0 0 0 0 0 0] #js[0 0 0 0 0 0]]})]
        (om/set-state! owner [:graph-chart] graph-chart)
        (om/set-state! owner [:interval-id] interval-id)))
    om/IRenderState
    (render-state [_ {:keys [graph]}]
      (dom/div #js {:className "col s12"}
               (dom/h5 nil "Live stats")
               (dom/div #js {:className "ct-chart ct-minor-seventh" :id (str "graph-" (data :id))} nil)))
    om/IDidUpdate
    (did-update [_ _ {:keys [graph-chart graph]}]
      (if (empty? graph)
        nil
        nil)) ;; Update the graph with new stats
    om/IWillUnmount
    (will-unmount [_]
      (js/clearInterval (om/get-state owner [:interval-id])))))
<commit_msg>Update graph every polling interval with new stats data<commit_after>(ns ^:figwheel-always sidequarter-frontend.core
    (:require-macros [cljs.core.async.macros :refer [go]])
    (:require[om.core :as om :include-macros true]
             [om.dom :as dom :include-macros true]
             [cljs.core.async :refer [<!]]
             [cljsjs.chartist]
             [sidequarter-frontend.api :as api]))

(enable-console-print!)

(println "Edits to this text should show up in your developer console.")

;; define your app data so that it doesn't get over-written on reload

(defonce app-state (atom {}))

(defn sidekiq-stats-view [data owner]
  (reify
    om/IInitState
    (init-state [_]
      {:stats { :busy 0 :enqueued 0 :scheduled 0 :retries 0 :failed 0 :processed 0}})
    om/IWillMount
    (will-mount [_]
      (go
        (let [response ((<! (api/get-stats (data :id))) :body)
              stats (:stats response)]
          (om/set-state! owner :stats stats))))
    om/IRenderState
    (render-state [_ {:keys [stats]}]
      (dom/ul #js {:className "sidekiq-stats h-list"}
              (dom/li nil (str "Busy: " (stats :busy)))
              (dom/li nil (str "Enqueued: " (stats :enqueued)))
              (dom/li nil (str "Scheduled: " (stats :scheduled)))
              (dom/li nil (str "Retries: " (stats :retries)))
              (dom/li nil (str "Failed: " (stats :failed)))
              (dom/li nil (str "Processed: " (stats :processed)))))))

(defn sidekiq-redis-view [data owner]
  (om/component
   (dom/ul #js {:className "sidekiq-redis-info"}
           (dom/li nil
                   (dom/strong nil "Namespace: ")
                   (dom/span nil (data :namespace)))
           (dom/li nil
                   (dom/strong nil "Redis URL: ")
                   (dom/span nil (data :redis_url))))))

(defn update-graph! [graph stats]
  (let [last-stat (last stats)
        data #js {:labels (clj->js (range (count stats)))
                  :series (clj->js (apply map vector (map vals stats)))}]
    (.log js/console data)
    (. graph (update data #js {:lineSmooth (.none (.-Interpolation js/Chartist))}))))

(defn sidekiq-poll-stats [data owner]
  (reify
    om/IInitState
    (init-state [_]
      {:graph [] :interval-id nil :graph-chart nil})
    om/IDidMount
    (did-mount [_]
      (let [interval-id
            (js/setInterval
             (fn []
               (go
                 (let [response ((<! (api/get-stats (data :id))) :body)
                       stats (:stats response)]
                   (om/update-state! owner [:graph] #(conj % stats))))
               ) 2000)
            g (.-Line js/Chartist)
            graph-chart (g. (str "#graph-" (data :id)) #js{:labels #js["", ""], :series #js[#js[0 0 0 0 0 0] #js[0 0 0 0 0 0]]})]
        (om/set-state! owner [:graph-chart] graph-chart)
        (om/set-state! owner [:interval-id] interval-id)))
    om/IRenderState
    (render-state [_ {:keys [graph]}]
      (dom/div #js {:className "col s12"}
               (dom/h5 nil "Live stats")
               (dom/div #js {:className "ct-chart ct-minor-seventh" :id (str "graph-" (data :id))} nil)))
    om/IDidUpdate
    (did-update [_ _ {:keys [graph]}]
      (if (empty? graph)
        nil
        (update-graph! (om/get-state owner [:graph-chart]) graph))) ;; Update the graph with new stats
    om/IWillUnmount
    (will-unmount [_]
      (js/clearInterval (om/get-state owner [:interval-id])))))

{'fraction_non_alphanumeric': 0.16176244030195655, 'fraction_numerical': 0.007702973347712217, 'mean_word_length': 2.085551330798479, 'pattern_counts': {'":': 0, '<': 9, '<?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': '962142', 'n_tokens_mistral': 2239, 'n_tokens_neox': 2115, 'n_words': 589}