<commit_before>(ns greenyet.view
  (:require [clojure.string :as str]
            [hiccup.core :refer [html]]))

(defn- host-for-environment [host-list environment]
  (first (filter #(= environment (:environment %)) host-list)))

(defn- system-row [environments host-list]
  (map (fn [environment]
         (host-for-environment host-list environment))
       environments))

(defn- environment-table [environments host-list]
  (->> host-list
       (group-by :system)
       (map (fn [[_ system-host-list]]
              (system-row environments system-host-list)))))


(defn- host-as-html [host]
  [:td {:class (str/join " " ["host" (some-> host
                                             :color
                                             name)])}
   (:hostname host)])

(defn- environment-table-as-html [environments rows]
  (html [:head
         [:meta {:http-equiv "refresh" :content "5"}]
         [:style (str/join "\n" [".host.green { background-color: green; }"
                                 ".host.yellow { background-color: yellow; }"
                                 ".host { background-color: red; }"
                                 ".host:empty { background: gray; }"])]]
        [:body
         [:table
          [:thead
           [:tr
            [:td]
            (for [env environments]
              [:td env])]]
          [:tbody
           (for [row rows]
             [:tr
              [:td (:system (first row))]
              (for [host row]
                (host-as-html host))])]]]))


(defn render [host-list-with-status]
  (let [environments (distinct (map :environment host-list-with-status))
        rows (environment-table environments host-list-with-status)]
    (environment-table-as-html environments rows)))<commit_msg>Sort columns and rows, don't be flaky<commit_after>(ns greenyet.view
  (:require [clojure.string :as str]
            [hiccup.core :refer [html]]))

(defn- host-for-environment [host-list environment]
  (first (filter #(= environment (:environment %)) host-list)))

(defn- system-row [environments host-list]
  (map (fn [environment]
         (host-for-environment host-list environment))
       environments))

(defn- environment-table [environments host-list]
  (->> host-list
       (group-by :system)
       (sort (fn [[system1 _] [system2 _]]
               (compare system1 system2)))
       (map (fn [[_ system-host-list]]
              (system-row environments system-host-list)))))


(defn- host-as-html [host]
  [:td {:class (str/join " " ["host" (some-> host
                                             :color
                                             name)])}
   (:hostname host)])

(defn- environment-table-as-html [environments rows]
  (html [:head
         [:meta {:http-equiv "refresh" :content "5"}]
         [:style (str/join "\n" [".host.green { background-color: green; }"
                                 ".host.yellow { background-color: yellow; }"
                                 ".host { background-color: red; }"
                                 ".host:empty { background: gray; }"])]]
        [:body
         [:table
          [:thead
           [:tr
            [:td]
            (for [env environments]
              [:td env])]]
          [:tbody
           (for [row rows]
             [:tr
              [:td (:system (first row))]
              (for [host row]
                (host-as-html host))])]]]))


(defn render [host-list-with-status]
  (let [environments (sort (distinct (map :environment host-list-with-status)))
        rows (environment-table environments host-list-with-status)]
    (environment-table-as-html environments rows)))
{'fraction_non_alphanumeric': 0.151440329218107, 'fraction_numerical': 0.0016460905349794238, 'mean_word_length': 1.7270007479431564, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6305678', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1018, 'n_words': 255}