<commit_before>(ns distillery.view.hitlist
  (:require [distillery.config :as cfg])
  (:require [distillery.data :refer :all])
  (:require [distillery.view.html :refer :all]))

(defn render-hitlist
  [words occ-fn config cloud-key]
  (let [hitlist (take 10 (reverse (sort-by #(count (occ-fn %)) words)))
        max-occ (count (occ-fn (first hitlist)))
        color (or (cfg/value [cloud-key :color] config) [0 0 0])
        conf-fn (fn [cnf]
                  (let [minc (cfg/value :min-confidence config)
                        cnf* (/ (- cnf minc) (- 1 minc))]
                    (* cnf* cnf*)))
        stats-str-fn (if (= 1.0 (mean (map :mean-confidence hitlist)))
                       (fn [n c] (str n))
                       (fn [n c] (str n " | " (format "%2.1f%%" (* 100 c)))))
        item-gen (fn [{:keys [id lexical-form pronunciation mean-confidence] :as w}]
                   (let [num-occ (count (occ-fn w))]
                     (list-item
                      (bar
                       [(span "hitlist_text"
                              (jslink
                               (str "word('" id "');")
                               {:tag :span
                                :attrs {:title pronunciation}
                                :content lexical-form}))
                        (span "hitlist_stats"
                              (strong (stats-str-fn num-occ mean-confidence)))]
                       color
                       (/ num-occ max-occ)
                       (conf-fn mean-confidence)))))]
    (div "hitlist"
         [(headline 3 "Häufige Worte")
          (olist (map item-gen hitlist))])))


<commit_msg>bugfix in distillery.view.hitlist: - no automatic suppression of confidence value - possible format exception with integer values for confidence<commit_after>(ns distillery.view.hitlist
  (:require [distillery.config :as cfg])
  (:require [distillery.data :refer :all])
  (:require [distillery.view.html :refer :all]))

(defn render-hitlist
  [words occ-fn config cloud-key]
  (let [hitlist (take 10 (reverse (sort-by #(count (occ-fn %)) words)))
        max-occ (count (occ-fn (first hitlist)))
        color (or (cfg/value [cloud-key :color] config) [0 0 0])
        conf-fn (fn [cnf]
                  (let [minc (cfg/value :min-confidence config)
                        cnf* (/ (- cnf minc) (- 1 minc))]
                    (* cnf* cnf*)))
        stats-str-fn (if (== 1 (mean (map :mean-confidence hitlist)))
                       (fn [n c] (str n))
                       (fn [n c] (str n " | " (format "%2.1f%%" (* 100.0 c)))))
        item-gen (fn [{:keys [id lexical-form pronunciation mean-confidence] :as w}]
                   (let [num-occ (count (occ-fn w))]
                     (list-item
                      (bar
                       [(span "hitlist_text"
                              (jslink
                               (str "word('" id "');")
                               {:tag :span
                                :attrs {:title pronunciation}
                                :content lexical-form}))
                        (span "hitlist_stats"
                              (strong (stats-str-fn num-occ mean-confidence)))]
                       color
                       (/ num-occ max-occ)
                       (conf-fn mean-confidence)))))]
    (div "hitlist"
         [(headline 3 "Häufige Worte")
          (olist (map item-gen hitlist))])))

{'fraction_non_alphanumeric': 0.13921113689095127, 'fraction_numerical': 0.008120649651972157, 'mean_word_length': 1.3225589225589225, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5301791', 'n_tokens_mistral': 1054, 'n_tokens_neox': 970, 'n_words': 274}