Skip to content

Commit

Permalink
Added operations chart
Browse files Browse the repository at this point in the history
  • Loading branch information
dferens committed Jun 10, 2015
1 parent e896fb3 commit 6ac7db2
Showing 1 changed file with 126 additions and 84 deletions.
210 changes: 126 additions & 84 deletions src/cljs/asols/client/stats.cljs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
(ns asols.client.stats
(:require [om.core :as om]
(:require [clojure.string :as str]
[om.core :as om]
[om.dom :refer [render-to-str]]
[om-tools.core :refer-macros [defcomponent]]
[sablono.core :refer-macros [html]]
[asols.client.solvings :refer [solving-block mutation-view]]
[asols.client.widgets :as widgets]
[asols.client.utils :refer [debug format]]))
[asols.client.utils :refer [debug format log]]))

(defn- iter-count-serie
[solvings]
Expand All @@ -26,90 +27,112 @@
[x y])))

(defn- costs-chart-config
[solvings train-values test-values]
(let [train-serie (cons [1 (get train-values 1)]
(solvings->serie solvings #(-> % :best-case :train-cost)))
test-serie (cons [1 (get test-values 1)]
(solvings->serie solvings #(-> % :best-case :test-cost)))]
{:chart {:type "scatter"
:height "400"}
:title {:text "Cost"}
:xAxis {:allowDecimals false}
:yAxis {:title {:text "Cost"}
:maxPadding 0}
:plotOptions {:scatter {:lineWidth 1
:marker {:enabled false}}}
:tooltip {:shared true
:useHTML true
:headerFormat "<b>{point.key}</b><br/>"
:pointFormat "<span style=\"color:{point.color}\">\u25CF</span> {series.name}: <b>{point.y}</b><br/>"}
:series [{:name "Static train cost"
:data (->> (sequence train-values)
(sort-by first))
:color "red"
:allowPointSelect true}
{:name "Static test cost"
:data (->> (sequence test-values)
(sort-by first))
:color "red"
:dashStyle "Dash"
:allowPointSelect true}
{:name "Train cost"
:data train-serie
:color "blue"
:marker {:enabled true :symbol "square"}}
{:name "Test cost"
:data test-serie
:color "blue"
:dashStyle "Dash"
:marker {:enabled true :symbol "square"}}]}))
[train-serie test-serie static-train-serie static-test-serie]
{:chart {:type "scatter"
:height "400"}
:title {:text "Cost"}
:xAxis {:allowDecimals false}
:yAxis {:title {:text "Cost"}
:maxPadding 0}
:plotOptions {:scatter {:lineWidth 1
:marker {:enabled false}}}
:tooltip {:shared true
:useHTML true
:headerFormat "<b>{point.key}</b><br/>"
:pointFormat "<span style=\"color:{point.color}\">\u25CF</span> {series.name}: <b>{point.y}</b><br/>"}
:series [{:name "Static train cost"
:data static-train-serie
:color "red"
:allowPointSelect true}
{:name "Static test cost"
:data static-test-serie
:color "red"
:dashStyle "Dash"
:allowPointSelect true}
{:name "Train cost"
:data train-serie
:color "blue"
:marker {:enabled true :symbol "square"}}
{:name "Test cost"
:data test-serie
:color "blue"
:dashStyle "Dash"
:marker {:enabled true :symbol "square"}}]})

(defn- ca-chart-config
[solvings train-values test-values]
(let [train-serie (cons [1 (get train-values 1)]
(solvings->serie solvings #(-> % :best-case :train-ca)))
test-serie (cons [1 (get test-values 1)]
(solvings->serie solvings #(-> % :best-case :test-ca)))]
{:chart {:type "scatter"
:height "500"}
:title {:text "CA"}
:xAxis {:allowDecimals false}
:yAxis {:title {:text "CA"}
:maxPadding 0}
:plotOptions {:scatter {:lineWidth 1
:marker {:enabled false}}}
:tooltip {:shared true
:useHTML true
:headerFormat "<b>{point.key}</b><br/>"
:pointFormat "<span style=\"color:{point.color}\">\u25CF</span> {series.name}: <b>{point.y}</b><br/>"}
:series [{:name "Static train CA"
:data (sort-by first train-values)
:color "red"}
{:name "Static test CA"
:data (sort-by first test-values)
:color "red"
:dashStyle "Dash"}
{:name "Train CA"
:data train-serie
:color "blue"
:marker {:enabled true :symbol "square"}}
{:name "Test CA"
:data test-serie
:color "blue"
:dashStyle "Dash"
:marker {:enabled true :symbol "square"}}]}))
[train-serie test-serie static-train-serie static-test-serie]
{:chart {:type "scatter"
:height "400"}
:title {:text "CA"}
:xAxis {:allowDecimals false}
:yAxis {:title {:text "CA"}
:maxPadding 0}
:plotOptions {:scatter {:lineWidth 1
:marker {:enabled false}}}
:tooltip {:shared true
:useHTML true
:headerFormat "<b>{point.key}</b><br/>"
:pointFormat "<span style=\"color:{point.color}\">\u25CF</span> {series.name}: <b>{point.y}</b><br/>"}
:series [{:name "Static train CA"
:data static-train-serie
:color "red"}
{:name "Static test CA"
:data static-test-serie
:color "red"
:dashStyle "Dash"}
{:name "Train CA"
:data train-serie
:color "blue"
:marker {:enabled true :symbol "square"}}
{:name "Test CA"
:data test-serie
:color "blue"
:dashStyle "Dash"
:marker {:enabled true :symbol "square"}}]})

(defcomponent cost-chart [{:keys [solvings train-values test-values]}]
(defn- operations-chart-config
[solvings]
(let [operations (mapcat
(fn [solving]
(let [m (:mutation (:best-case solving))
o (:operation m)]
(if (= :asols.mutations/combined o)
(map :operation (:mutations m))
[o])))
solvings)
series (for [[operation ops] (group-by identity operations)]
[(name operation) (count ops)])]
{:chart {:plotBackgroundColor nil
:plotBorderWidth nil
:plotShadow false
:height 300}
:title {:text "Operations"}
:plotOptions {:pie {:allowPointSelect true
:showInLegend true}}
:series [{:type "pie"
:name "Operations used"
:data series}]}))

(defcomponent cost-chart [[s1 s2 s3 s4]]
(render [_]
(om/build widgets/highchart (costs-chart-config s1 s2 s3 s4))))

(defcomponent ca-chart [[s1 s2 s3 s4]]
(render [_]
(om/build widgets/highchart (costs-chart-config solvings train-values test-values))))
(om/build widgets/highchart (ca-chart-config s1 s2 s3 s4))))

(defcomponent ca-chart [{:keys [solvings train-values test-values]}]
(defcomponent operations-chart [{:keys [solvings]}]
(render [_]
(om/build widgets/highchart (ca-chart-config solvings train-values test-values))))
(om/build widgets/highchart (operations-chart-config solvings))))

(defn- series->csv
[series]
(str/join "\n\n" (for [serie series]
(str (mapv first serie) "\n" (mapv second serie)))))

(defcomponent stats-panel [{:keys [progress solvings metrics]}]
(render [_]
(let [[train-cost-serie test-cost-serie train-ca-serie test-ca-serie] metrics]
(let [[train-cost-data test-cost-data train-ca-data test-ca-data] metrics]
(html
[:.panel.panel-success
[:.panel-heading "Stats"]
Expand All @@ -121,12 +144,31 @@
(widgets/progress-bar (:value progress))]])

[:.row
[:.col-md-12
(om/build cost-chart {:solvings solvings
:train-values train-cost-serie
:test-values test-cost-serie})]]
(let [train-serie (cons [1 (get train-cost-data 1)]
(solvings->serie solvings #(-> % :best-case :train-cost)))
test-serie (cons [1 (get test-cost-data 1)]
(solvings->serie solvings #(-> % :best-case :test-cost)))
static-train-serie (sort-by first train-cost-data)
static-test-serie (sort-by first test-cost-data)
series [train-serie test-serie
static-train-serie static-test-serie]]
[:.col-md-12
(om/build cost-chart series)
[:.btn.btn-success.btn-block {:on-click #(log (series->csv series))}
"Export"]])]
[:.row
(let [train-serie (cons [1 (get train-ca-data 1)]
(solvings->serie solvings #(-> % :best-case :train-ca)))
test-serie (cons [1 (get test-ca-data 1)]
(solvings->serie solvings #(-> % :best-case :test-ca)))
static-train-serie (sort-by first train-ca-data)
static-test-serie (sort-by first test-ca-data)
series [train-serie test-serie
static-train-serie static-test-serie]]
[:.col-md-12
(om/build ca-chart series)
[:.btn.btn-success.btn-block {:on-click #(log (series->csv series))}
"Export"]])]
[:.row
[:.col-md-12
(om/build ca-chart {:solvings solvings
:train-values train-ca-serie
:test-values test-ca-serie})]]]]))))
(om/build operations-chart {:solvings solvings})]]]]))))

0 comments on commit 6ac7db2

Please sign in to comment.