std.timeseries.journal

+defaults+

add-bulk

added in 3.0

(add-bulk {:keys [meta template], :as journal} entries)

adds multiple entries to the journal

add-entry

added in 3.0

(add-entry {:keys [meta template], :as journal} entry)

adds an entry to the journal

(-> (journal {:meta {:head {:range 0 3}}}) (add-entry {:start 1 :output {:value 1}}) journal-info) => (contains-in {:id string? :order :desc, :count 1, :duration “0ms”, :template :output.value :start, :head {:start 1, :output.value 1, :s/time string?}})

add-time

added in 3.0

(add-time entry key unit)

adds time to entry if if doesn’t exist

(add-time {} :t :s) => (contains {:t integer?})

create-template

added in 3.0

(create-template {:keys [template]} entry)

creates a template a puts in the cache

derive

added in 3.0

(derive {:keys [meta], :as journal} {:keys [range sample transform], :as params})

derives the journal given a select statement

(derive -jnl- {:range :1m :15m :sample 2000 :transform {:interval :0.1s :time {:aggregate :first} :default {:aggregate :mean :sample 3}}})

entries-seq

added in 3.0

(entries-seq {:keys [limit entries previous]})

gets entries in time order

(-> (journal {:limit 2 :entries {:a 2 :s/time 2} :previous {:a 1 :s/time 1} {:a 0 :s/time 0}}) (entries-seq)) => {:a 2, :s/time 2} {:a 1, :s/time 1}

entries-vec

added in 3.0

(entries-vec {:keys [limit entries previous]})

gets entries in time order

(-> (journal {:meta {:time {:order :asc}} :limit 2 :entries {:a 2 :s/time 2} :previous {:a 0 :s/time 0} {:a 1 :s/time 1}}) (entries-vec)) => {:a 1, :s/time 1} {:a 2, :s/time 2}

entry-display

added in 3.0

(entry-display entry {:keys [meta]})

displays entry, formatting time

(entry-display {:data {:in "" :out “ABC”} :time 100000} {:meta {:time {:key :time :unit :s :format “HH:mm:ss”}}}) => (contains {:data {:in "", :out “ABC”}, :time #(.endsWith ^String % “:46:40”)})

format-time

added in 3.0

(format-time val {:keys [unit format]})

output the time according to format and time unit

(format-time 10000 {:unit :s :format “HH:mm:ss”}) => #(.endsWith ^String % “:46:40”)

get-template

added in 3.0

(get-template {:keys [entries template], :as journal})

gets existing or creates a new template

(get-template (journal {:entries {:a {:b 1} :s/time 0}})) => map?

journal

added in 3.0

(journal)(journal {:keys [id meta entries previous], :as m, :or {id (f/sid)}})

creates a new journal

(journal {:meta {:time {:unit :s :format “HH:mm:ss”} :entry {:flatten false} :head {:range 0 3}}})

journal-entries

added in 3.0

(journal-entries journal)

gets entries from the journal

(-> (journal {:meta {:time {:order :asc} :entry {:flatten true :pre-flattened true}} :limit 2 :entries {:a 2 :s/time 2} :previous {:a 0 :s/time 0} {:a 1 :s/time 1}}) (add-entry {:a 3 :s/time 3}) (add-entry {:a 4 :s/time 4}) ((juxt :entries journal-entries))) => [{:a 4, :s/time 4} {:a 3, :s/time 3} {:a 4, :s/time 4}]

journal-info

added in 3.0

(journal-info {:keys [id meta], :as journal})

returns info for the journal

(-> (journal {:meta {:time {:key :start :order :desc} :head {:range 0 3} :hide #{:meta :template :id}}}) journal-info) => {:order :desc, :count 0, :head []}

journal-invoke

added in 3.0

(journal-invoke journal)(journal-invoke journal arg)(journal-invoke journal k v & more)

invoke function for the journal

merge

added in 3.0

(merge)(merge j0)(merge j0 j1)

merges two journals of the same type together ^:hiddene

(-> ((merge (derive -jnl- {:range :1m :3m :transform {:interval 1 :time {:aggregate :middle} :default {:aggregate :mean :sample 3}}}) (derive -jnl- {:range :10m -1 :transform {:interval :5s :time {:aggregate :first} :default {:aggregate :mean}}})) {:sample :0.1s :transform {:interval :1s :time {:aggregate :first :fn #(long (/ % 100))} :custom [{:keys :output.value :aggregate :random :fn #(long (* % 100))}]} :series [{:data ’(:start :output.value) :s/meta {:title “Output 1” :with :lines}}]}))

merge-sorted

added in 3.0

(merge-sorted coll)(merge-sorted coll key-fn)(merge-sorted coll key-fn comp-fn)

select

added in 3.0

(select journal)(select {:keys [meta], :as journal} {:keys [range sample transform series template compute], :or {range :all}})

selects data ferom the journal

(def -jnl- (->> [0 (journal {:meta {:time {:key :start :order :desc} :head {:range 0 3} :hide #{:meta :template :id}}})] (iterate (fn t journal (let t (+ t 1000000000 (rand-int 100000000)) t (add-entry journal {:start t :output {:value (Math/sin (+ (/ t 100000000000) (rand)))}})))) (map second) (take 1000) (last)))

(select -jnl- {:range :1m :5m :sample 10}) => (fn entries (= 10 (count entries)))

(first (select -jnl- {:range :1m :5m :sample 10})) => (contains {:start integer? :output.value number?})

select-series

added in 3.0

(select-series entries series)

select data from the series

template-keys

added in 3.0

(template-keys template)

get keys for the template

(template-keys (common/create-template {:data {:in "" :out “ABC”}})) => :data.in :data.out

update-journal-bulk

added in 3.0

(update-journal-bulk {:keys [limit entries], :as journal} new-entries)

adds multiple entries to the journal

update-journal-single

added in 3.0

(update-journal-single {:keys [limit entries], :as journal} entry)

adds a single entry to the journal

update-meta

added in 3.0

(update-meta journal meta)

updates journal meta. used for display