 
 
 (declare calculate-summary
+         calculate-relative-performance
          render-html)
 
 

           [:div {:class "row"}
            [:div {:class "col-md-10"}
             (about)
             (relative-performance-table summary)
             (performance-graph)]
            [:div {:id "navbar"
                   :class "col-md-2"}

  (let [current-directory (System/getProperty "user.dir")
        html-path (str report-path "/index.html")
        chart-path (str report-path "/chart.png")
        summary (calculate-summary groups results)
        relative-performance (calculate-relative-performance summary)]
    (println "Summary: "
             (str "file://" current-directory "/" html-path))
    (make-parents html-path)
    (with-open [w (writer html-path)]
      (.write w (render-html relative-performance)))
    (make-chart summary chart-path)))


(defn calculate-relative-performance [summary]
  (let [last-of-each (partial mapv last)
        normalize #(let [m (apply min %)]
                     (mapv (fn [k] (/ k m)) %))
        group-by-first (partial group-by first)
        f (comp normalize last-of-each)
        rows (->> summary
                  (group-by-first)
                  (map (fn [[k v]] [k (f v)]))
                  (into (sorted-map)))
        columns (->> summary
                     (group-by-first)
                     (vals)
                     (first)
                     (mapv second))]        
    [columns rows]))


(defn calculate-summary [groups results]
