This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-30
Channels
- # announcements (40)
- # babashka (41)
- # beginners (32)
- # calva (15)
- # clara (8)
- # clj-kondo (14)
- # cljs-dev (30)
- # clojure (37)
- # clojure-dev (8)
- # clojure-europe (21)
- # clojure-norway (21)
- # clojure-uk (4)
- # clojured (3)
- # clojurescript (4)
- # community-development (10)
- # core-async (13)
- # cursive (23)
- # datomic (15)
- # emacs (9)
- # fulcro (3)
- # google-cloud (4)
- # graphql (24)
- # gratitude (2)
- # holy-lambda (4)
- # honeysql (5)
- # hyperfiddle (9)
- # keechma (1)
- # klipse (5)
- # lsp (23)
- # malli (4)
- # missionary (32)
- # pathom (28)
- # re-frame (2)
- # reagent (40)
- # reitit (17)
- # releases (2)
- # remote-jobs (1)
- # shadow-cljs (25)
- # specter (3)
- # vim (19)
- # xtdb (41)
Building on my previous question, let's say I'm accumulating facts over time in my session, where these facts are will be grouped by an id I then want to write a rule that will operate on each group. Do I need to do something like:
(def gb (acc/grouping-by :id))
(defrecord Event [id timestamp ,,,])
(defrecord Group [id data])
(defrule update-aggregateion
[Event (= ?id id)
?acc <- gb :from [Event]
?group <- Group (= ?id id)]
=>
(retract! ?group)
(insert! (->Group ?id (get ?acc ?id))))
I need to keep track of each accumulated group separately and apply further rules per group
bit more details about what I'm trying to do because maybe I'm just way off - I want to track some status change events according to a bunch of rules, accumulate them by id for a period, and after that period has elapsed do some side effect with the all the accumulated events and remove them from the session
retractions always get tricky… you can very easily get into logical loops, so in general i recommend avoiding them. rather than retracting them, would it be possible to instead only collect the “latest” grouping. If we are talking time-based groupings/events, i would imagine that you could assume that there would be a linear progression in events and that the ids could be numerically incremented.
Already managed to trap myself in one 😆 Problem is the IDs are user ids coming from outside the system, I want a windowed aggregation per user
It's a bit wasteful but I figured I can have a rule which inserts a Group on the first time and another rule which matches on the group and the event, retracts the previous group and updates the current But it's ugly
i guess, looking at this again… i’m a little confused as to why this isn’t handled by the truth maintenance inherit to Clara. I would think that this would likely be as simple as something like:
(cr/defrule grouped-events
[?acc <- gb :from [Event]]
=>
(doseq [[id events] ?acc]
(r/insert! (->Group id events))))
any new events in the session would re-evaluate that accumulator. Doing an implicit retraction of the prior grouping.