This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-04-20
Channels
- # beginners (27)
- # calva (32)
- # cider (9)
- # clojure (111)
- # clojure-spec (71)
- # clojure-uk (7)
- # clojurescript (22)
- # cursive (20)
- # devcards (1)
- # emacs (4)
- # fulcro (3)
- # hyperfiddle (3)
- # off-topic (8)
- # pathom (26)
- # planck (19)
- # quil (4)
- # re-frame (1)
- # reitit (43)
- # rewrite-clj (9)
- # shadow-cljs (13)
- # spacemacs (7)
- # uncomplicate (5)
Data-y people in this room, good place to ask about making this less hairy:
(defn- twitter-follower-history
[db id]
(let [historys
(crux.api/history-descending db (crux.api/new-snapshot db) id)]
(into {}
(map (fn [[k v]]
;; Find last instant of the month, singular-group-by
[k (:count (apply max-key (comp t/long t/instant :at) v))])
;; Aggregate by year-month
(group-by (comp t/year-month t/instant :at)
;; Get data from history
(map (fn [history]
{:at (:crux.db/valid-time history)
:count (get-in history
[:crux.db/doc
:proj/followers_count])})
historys))))))
I'm getting the year-month & :count
of the last record within each year-month, that's the best english explantion I can give
(defn- twitter-follower-history2
[db id]
(into {}
(comp
(map (fn [history]
{:at (:crux.db/valid-time history)
:count (get-in history [:crux.db/doc ::twitter/followers_count])}))
(x/by-key (comp t/year-month t/instant :at) (x/into []))
(x/by-key (map #(:count (apply max-key (comp t/long t/instant :at) %)))))
(crux.api/history-descending
db
(crux.api/new-snapshot db) id)))
by-key
is pretty neat 🙂