std.timeseries.common
cluster
added in 3.0
(cluster arr n f)clusters a space with an aggregate function
(cluster (range 1 200) 10 math/mean) => 10 29 48 67 86 105 124 143 162 181
duration
added in 3.0
(duration arr {:keys [key unit order]})calculates the duration from array and options
(duration 1 2 3 4 {:key identity :unit :m}) => 180000
flat-fn
added in 3.0
(flat-fn template)creates a nested to flat transform
(def transform-fn (flat-fn (raw-template {:a {:b {:c 1}}})))
(transform-fn {:a {:b {:c 10}}}) => {:a.b.c 10}
from-ms
added in 3.0
(from-ms ms to)converts ms time into a given unit
(from-ms 100 :ns) => 100000000
linspace
added in 3.0
(linspace arr n)takes the linear space of n samples
(linspace (range 100) 10) => 0 11 22 33 44 55 66 77 88 99
make-empty
added in 3.0
(make-empty entry)creates an empty entry given structure
(make-empty {:a 1 :b “hello” :c :world}) => {:a 0, :b "", :c nil}
nest-fn
added in 3.0
(nest-fn template)creates a nested to flat transform
(def transform-fn (nest-fn (raw-template {:a {:b {:c 1}}})))
(transform-fn {:a.b.c 10}) => {:a {:b {:c 10}}}
order-flip
added in 3.0
(order-flip order)returns the opposite of the order
(order-flip :asc) => :desc
order-fn
added in 3.0
(order-fn [asc desc])creates a function that returns or flips the input
(mapv (order-fn :up :down) :asc :desc false true) => :up :up
order-fns
added in 3.0
(order-fns order)(order-fns order flip)returns commonly used functions
(order-fns :asc) => {:comp-fn <, :comp-eq-fn <=, :op-fn +}
parse-sample-expr
added in 3.0
(parse-sample-expr sample time-opts)parses a sample expression
(parse-sample-expr 10 {}) => {:size 10, :strategy :linear}
parse-time
added in 3.0
(parse-time s)(parse-time s unit)parses a string or keyword time representation
(parse-time :0.1m :us) => 6000000
(parse-time :0.5ms :us) => 500
parse-time-expr
added in 3.0
(parse-time-expr m)parses a time expression
(parse-time-expr {:interval “0.5ms”}) => {:key identity, :unit :ms, :order :asc, :interval 0}
process-sample
added in 3.0
(process-sample arr {:keys [size strategy every], :as m} time-opts)process sample given sampling function
(process-sample (range 100) (parse-sample-expr 10 :random {}) {:key identity :order :asc}) ;; (4 20 39 51 51 60 70 72 89 96) => coll?
;; extended sampling function from range (process-sample (range 100) (parse-sample-expr [0 :10ms :range] {:key identity :order :asc :unit :ms}) {:key identity :order :asc :unit :ms}) => 0 1 2 3 4 5 6 7 8 9 10
raw-template
added in 3.0
(raw-template entry)creates a template for nest/flat mapping
(raw-template {:a {:b 1 :c “2”}}) => {:nest {:a {:b “{{a.b}}”, :c “{{a.c}}”}}, :flat {:a.b “{{a.b}}”, :a.c “{{a.c}}”}, :types {:a.b java.lang.Long, :a.c java.lang.String} :empty {:a.b 0, :a.c ""}}
to-ms
added in 3.0
(to-ms ms from)converts a time to ms time
(to-ms 10000 :ns) => 0
(to-ms 10000 :s) => 10000000