Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Block Creation History as CSV
(ns block-chart
[reagent.core :as r]
[roam.datascript :as d]))
(defn string-bytes [s]
(.-size (js/Blob. [s])))
(defn totals [coll]
(reduce (fn [counts [k v]]
(assoc! counts k (+ v (get counts k 0))))
(transient {}) coll)))
(defn get-c-times [measure-type]
(if (= :bytes measure-type)
(-> (into []
(comp (map (fn [[eid t]]
[(.toDateString (js/Date. t))
(string-bytes (str " "
(clojure.string/join \space
(into []
(map (comp pr-str pop vec))
(d/datoms :eavt eid)))))])))
(d/q '[:find ?e ?t
(and [?e :edit/time ?t]
[(missing? $ ?e :create/time)])
[?e :create/time ?t])]))
(-> (into []
(map (fn [t] (.toDateString (js/Date. t))))
(d/q '[:find [?t ...]
:with ?e
(and [?e :edit/time ?t]
[(missing? $ ?e :create/time)])
[?e :create/time ?t])]))
(mapv (fn [x] (update x 0 #(js/Date. %))))
(sort-by #(.getTime (first %)))
(mapv (fn [t] (-> t
;(update 0 #(.getTime %))
;(update 0 #(.toISOString %))
(update 0 #(.toLocaleDateString %))
(mapv #(str \" % \"))
(clojure.string/join ", ")))))))
(defn c [_]
(let [result (r/atom [])]
(fn [_]
[:div {:style {:display :flex
:flex-direction :column
:align-items :flex-start}}
[:div "Page and block volume over time as csv."]
[:button {:on-click #(reset! result (get-c-times))}
"Get no. of created blocks"]
[:button {:on-click #(reset! result (get-c-times :bytes))}
"Get byte size of created blocks (takes a while)"]
{:value (clojure.string/join "\n" @result)
:style {:width "300px"}}]])))
Copy link

Usage: {{roam/render: ((ref-to-clojure-codeblock))}}

This allows you to generate CSV data of the number/size of blocks created per day. You can copy the text (Ctrl/Cmd+A) and paste it into spreadsheet software for producing charts of how your graph has evolved over time.



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