Skip to content

Instantly share code, notes, and snippets.

@LuisThiamNye
Created March 13, 2021 16:31
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 LuisThiamNye/34904512a42c0320b3d19855f46936b5 to your computer and use it in GitHub Desktop.
Save LuisThiamNye/34904512a42c0320b3d19855f46936b5 to your computer and use it in GitHub Desktop.
Block Creation History as CSV
(ns block-chart
(:require
[clojure.string]
[reagent.core :as r]
[roam.datascript :as d]))
(defn string-bytes [s]
(.-size (js/Blob. [s])))
(defn totals [coll]
(persistent!
(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
:where
(or
(and [?e :edit/time ?t]
[(missing? $ ?e :create/time)])
[?e :create/time ?t])]))
totals)
(-> (into []
(map (fn [t] (.toDateString (js/Date. t))))
(d/q '[:find [?t ...]
:with ?e
:where
(or
(and [?e :edit/time ?t]
[(missing? $ ?e :create/time)])
[?e :create/time ?t])]))
frequencies))
(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)"]
[:textarea
{:value (clojure.string/join "\n" @result)
:style {:width "300px"}}]])))
@LuisThiamNye
Copy link
Author

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.

image

image

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