              (fn [testcase] {:build build
                              :ok? (junit-xml/is-ok? testcase)})))))
 
-(defn- flaky-testcases-for-builds [builds test-results-func]
-  (->> builds
+(defn- flaky-testcases-for-builds [builds-with-same-input test-results-func]
+  (->> builds-with-same-input
        (mapcat (fn [build]
                  (unrolled-testcases build test-results-func)))
        (group-by transform/testcase->id)

    (assoc (average-runtime testcases)
           :failed-count failed-count)))

(defn- aggregate-runs [unrolled-testcases]
  (->> unrolled-testcases
       (group-by transform/testcase->id)
       (map (transform/testcase-with-data
             (fn [testcase-group] (aggregate-testcase-runs testcase-group))))
       (into {})))

(defn- aggregated-info-by-testcase [test-runs]
  (aggregate-runs (transform/test-runs->testcase-list test-runs)))


(defn aggregate-testcase-info [test-runs]
  (->> (aggregated-info-by-testcase test-runs)
       transform/testcase-list->testsuite-tree))

(defn aggregate-testcase-info-as-list [test-runs]
  (->> (aggregated-info-by-testcase test-runs)
       (map transform/testcase->map)))


(defn- average-runs [unrolled-testcases]
  (->> unrolled-testcases
       (group-by transform/testcase->id)
       (map (transform/testcase-with-data
             (fn [testcase-group] (average-runtime testcase-group))))
       (into {})))

(defn- accumulated-runtime [testcases]
  (let [runtimes (map :runtime testcases)]

     :latest-failure (:start last-build)
     :flaky-count (count unrolled-testcases)}))

(defn flaky-testcases-as-list [builds test-results-func]
  (->> builds
       find-flaky-build-candidates
       (mapcat #(flaky-testcases-for-builds % test-results-func))
       (group-by transform/testcase->id)
       (map (transform/testcase-with-data
             (fn [testcases] (flaky-testcase-summary testcases))))
       (map transform/testcase->map)))
