<commit_before>(ns swarmpit.component.task.list
  (:require [material.icon :as icon]
            [material.components :as comp]
            [material.component.list.basic :as list]
            [material.component.list.util :as list-util]
            [material.component.label :as label]
            [swarmpit.component.state :as state]
            [swarmpit.component.mixin :as mixin]
            [swarmpit.component.progress :as progress]
            [swarmpit.ajax :as ajax]
            [swarmpit.routes :as routes]
            [swarmpit.url :refer [dispatch!]]
            [sablono.core :refer-macros [html]]
            [clojure.contrib.humanize :as humanize]
            [goog.string :as gstring]
            [goog.string.format]
            [rum.core :as rum]
            [swarmpit.component.common :as common]))

(enable-console-print!)

(defn- render-percentage
  [val]
  (if (some? val)
    (str (gstring/format "%.2f" val) "%")
    "-"))

(defn- render-capacity
  [val]
  (if (some? val)
    (humanize/filesize val :binary false)
    "-"))

(defn render-item-state [value]
  (case value
    "preparing" (label/pulsing value)
    "starting" (label/pulsing value)
    "pending" (label/pulsing value)
    "new" (label/blue value)
    "ready" (label/blue value)
    "assigned" (label/blue value)
    "accepted" (label/blue value)
    "complete" (label/blue value)
    "running" (label/green value)
    "shutdown" (label/grey value)
    "orphaned" (label/grey value)
    "rejected" (label/red value)
    "failed" (label/red value)))

<<<<<<< HEAD
(defn- render-percentage
  [val]
  (if (some? val)
    (str (gstring/format "%.2f" val) "%")
    "-"))

(defn- render-capacity
  [val]
  (if (some? val)
    (humanize/filesize val :binary true)
    "-"))
=======
(defn- render-item-name [item]
  (html
    [:div
     [:div
      [:span (:taskName item)]]
     [:div
      [:span.Swarmpit-list-image (get-in item [:repository :image])]]]))
>>>>>>> origin / issues/159

(def render-metadata
  {:table {:summary [{:name      "Task"
                      :render-fn (fn [item] (render-item-name item))}
                     {:name      "Node"
                      :render-fn (fn [item] (:nodeName item))}
                     {:name      "CPU Usage"
                      :render-fn (fn [item] (render-percentage (get-in item [:stats :cpuPercentage])))}
                     {:name      "Memory Usage"
                      :render-fn (fn [item] (render-percentage (get-in item [:stats :memoryPercentage])))}
                     {:name      "Memory"
                      :render-fn (fn [item] (render-capacity (get-in item [:stats :memory])))}
                     {:name      "State"
                      :render-fn (fn [item] (render-item-state (:state item)))}]}
   :list  {:primary   (fn [item] (:taskName item))
           :secondary (fn [item] (get-in item [:repository :image]))
           :status-fn (fn [item] (render-item-state (:state item)))}})

(defn- onclick-handler
  [item]
  (dispatch! (routes/path-for-frontend :task-info (select-keys item [:id]))))

(defn- tasks-handler<commit_msg>task list fixed<commit_after>(ns swarmpit.component.task.list
  (:require [material.icon :as icon]
            [material.component.list.util :as list-util]
            [material.component.label :as label]
            [swarmpit.component.state :as state]
            [swarmpit.component.mixin :as mixin]
            [swarmpit.component.progress :as progress]
            [swarmpit.ajax :as ajax]
            [swarmpit.routes :as routes]
            [swarmpit.url :refer [dispatch!]]
            [sablono.core :refer-macros [html]]
            [clojure.contrib.humanize :as humanize]
            [goog.string :as gstring]
            [goog.string.format]
            [rum.core :as rum]
            [swarmpit.component.common :as common]))

(enable-console-print!)

(defn- render-percentage
  [val]
  (if (some? val)
    (str (gstring/format "%.2f" val) "%")
    "-"))

(defn- render-capacity
  [val]
  (if (some? val)
    (humanize/filesize val :binary false)
    "-"))

(defn render-item-state [value]
  (case value
    "preparing" (label/pulsing value)
    "starting" (label/pulsing value)
    "pending" (label/pulsing value)
    "new" (label/blue value)
    "ready" (label/blue value)
    "assigned" (label/blue value)
    "accepted" (label/blue value)
    "complete" (label/blue value)
    "running" (label/green value)
    "shutdown" (label/grey value)
    "orphaned" (label/grey value)
    "rejected" (label/red value)
    "failed" (label/red value)))

(defn- render-item-name [item]
  (html
    [:div
     [:div
      [:span (:taskName item)]]
     [:div
      [:span.Swarmpit-list-image (get-in item [:repository :image])]]]))

(def render-metadata
  {:table {:summary [{:name      "Task"
                      :render-fn (fn [item] (render-item-name item))}
                     {:name      "Node"
                      :render-fn (fn [item] (:nodeName item))}
                     {:name      "CPU Usage"
                      :render-fn (fn [item] (render-percentage (get-in item [:stats :cpuPercentage])))}
                     {:name      "Memory Usage"
                      :render-fn (fn [item] (render-percentage (get-in item [:stats :memoryPercentage])))}
                     {:name      "Memory"
                      :render-fn (fn [item] (render-capacity (get-in item [:stats :memory])))}
                     {:name      "State"
                      :render-fn (fn [item] (render-item-state (:state item)))}]}
   :list  {:primary   (fn [item] (:taskName item))
           :secondary (fn [item] (get-in item [:repository :image]))
           :status-fn (fn [item] (render-item-state (:state item)))}})

(defn- onclick-handler
  [item]
  (dispatch! (routes/path-for-frontend :task-info (select-keys item [:id]))))

(defn- tasks-handler
{'fraction_non_alphanumeric': 0.15895509646576747, 'fraction_numerical': 0.0010244152296397474, 'mean_word_length': 2.1011116993118053, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '2223551', 'n_tokens_mistral': 1966, 'n_tokens_neox': 1885, 'n_words': 458}