Skip to content

Instantly share code, notes, and snippets.

@holyjak
Created November 4, 2018 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save holyjak/c57c6e31d515259ed05f5a520571bb2c to your computer and use it in GitHub Desktop.
Save holyjak/c57c6e31d515259ed05f5a520571bb2c to your computer and use it in GitHub Desktop.
Comparison of gnuplot, Incanter, oz/vega-lite for plotting usage data - Oz
(ns clj-charting.oz
(:require
[oz.core :as oz]
[incanter.core :refer :all]
[clj-charting.usage-chart-preparation :refer [read-usage-data moving-window-means]]))
(defn dataset->map-list
"Incanter dataset into a list of maps like
{\"0\" 1541065398391, \"1\" 446693376, \"2\" 99.9, \"cpu_mean\" 89}"
[ds]
(let [rows (to-list ds)
means (moving-window-means 60 (sel ds :cols 2))]
(map
#(assoc
(zipmap (map str (range)) %1)
"cpu_mean" %2)
rows
means)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def gb4 (* 3 1024 1024 1024))
;; TODO Display legend - IMPOSSIBLE :-( until Datum
(def line-plot
(let [data (dataset->map-list (read-usage-data "siege-c10-all-urls-async-node11.dat"))
x-enc {:field "0"
:type "temporal"
:timeUnit "hoursminutesseconds" ; :aggregate "mean" l <- this kills points with same value
:axis {:title "Time"}
:scale {:zero false}}]
{:width 700
:data {:values data}
;;; 👇 requires VL v3 until then we have to compute cpu_mean using Incanter
;:transform [{:window [{:op "mean"
; :field "1"
; :as "cpu_mean"}]
; :frame [-10, 10]}]
; TODO VLv3: use this 👇 instead of repeating the X on each plot
;:encoding {:x x-enc}
:layer [{:mark {:type "line"
:clip true
:color "red"}
:encoding {:x x-enc
:y {:field "1"
:type "quantitative"
:axis {:format ".1s" :title "Memory" :labelColor "red" #_"required VL 3"}
:scale {:domain [0 gb4]}}}}
{:layer [
{:mark {:type "point"
:clip true}
:encoding {:x x-enc
:y {:field "2"
:type "quantitative"
:axis {:title "CPU [%]" :labelColor "blue"}}}}
{:mark {:type "line"
:clip true
:color "blue"}
:encoding {:x x-enc
:y {:field "cpu_mean"
:type "quantitative"
:title nil
:axis nil}}}]}]
:resolve {:scale {:y "independent"}}}))
(oz/start-plot-server!)
(oz/v! line-plot)
@holyjak
Copy link
Author

holyjak commented Nov 4, 2018

You can open the chart in the online Vega Editor and play with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment