<commit_before>(ns buildviz.jobinfo
  (:require [buildviz.data.schema :as schema]
            [buildviz.math :as math]
            [clj-time
             [coerce :as tc]
             [core :as t]
             [format :as tf]]))

(defn builds-with-outcome [build-data-entries]
  (filter schema/build-with-outcome? build-data-entries))


(defn- build-inputs-as-map [build]
  (let [inputs (:inputs build)
        input-map (->> inputs
                       (map (fn [{id :id revision :revision}] {id revision}))
                       (into {}))]
    (assoc build :inputs input-map)))

(defn builds-grouped-by-same-inputs [builds]
  (->> builds
       (filter :inputs)
       (map build-inputs-as-map)
       (group-by :inputs)
       vals))

;; flaky builds

(defn- outcomes-for-builds-grouped-by-input [build-data-entries]
  (->> build-data-entries
       builds-grouped-by-same-inputs
       (map #(map :outcome %))
       (map distinct)))

(defn flaky-build-count [build-data-entries]
  (->> (outcomes-for-builds-grouped-by-input build-data-entries)
       (map count)<commit_msg>Refactor, simplify<commit_after>(ns buildviz.jobinfo
  (:require [buildviz.data.schema :as schema]
            [buildviz.math :as math]
            [clj-time
             [coerce :as tc]
             [core :as t]
             [format :as tf]]))

(defn builds-with-outcome [build-data-entries]
  (filter schema/build-with-outcome? build-data-entries))


(defn builds-grouped-by-same-inputs [builds]
  (->> builds
       (filter :inputs)
       (group-by #(set (:inputs %)))
       vals))

;; flaky builds

(defn- outcomes-for-builds-grouped-by-input [build-data-entries]
  (->> build-data-entries
       builds-grouped-by-same-inputs
       (map #(map :outcome %))
       (map distinct)))

(defn flaky-build-count [build-data-entries]
  (->> (outcomes-for-builds-grouped-by-input build-data-entries)
       (map count)
{'fraction_non_alphanumeric': 0.15639810426540285, 'fraction_numerical': 0.0, 'mean_word_length': 2.3216783216783217, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '4117510', 'n_tokens_mistral': 666, 'n_tokens_neox': 655, 'n_words': 131}