So just to briefly tell people my experience: I taught myself python before, and teach myself clojure + datalog with a very top-down approach. I barely touch on computer science. There’s probably a better way to implement what I want to do with my query, but I don’t know how, lol.
So my advanced query has a :view
property that only returns(?) a single string (no [:divs]
or [:spans]
, i kinda don’t know how that works). When my query is on a page, the newlines work, but when I put it in my journal queries via config.edn, the \n
are non-existent (and the formatting’s pretty bad too since it’s really just one string). I just want my newline to not be erased.
The query basically gives me a visual representation of whether or not I tagged certain pages on a journal page for the past few days.
Here’s my query!
#+BEGIN_QUERY
{
:title [:b "habits"]
:query [
:find ?habitname ?d ?boolemoji
:in $ ?dstart ?dyesterday ?htagname
:keys habitname d boolemoji
:where
[?habitpage :page/name ?habitname]
[?habitpage :page/tags ?htag]
[?htag :page/name ?htagname]
[?jpage :block/journal-day ?d]
[(>= ?d ?dstart)]
[(<= ?d ?dyesterday)]
[?jblock :block/page ?jpage]
(or
(and [?jblock :block/refs ?habitpage] [(str "🟩") ?boolemoji])
(and (not [?jblock :block/refs ?habitpage]) [(str "🟥") ?boolemoji])
)
]
:inputs [:-30d :today "habits"]
:view( fn[qmaps]
(def habitmap {})
(doseq [qmap qmaps]
(when (not= "🟩" (get-in habitmap [ (get-in qmap [:habitname]) (get-in qmap [:d]) ]) )
(def habitmap
(assoc-in habitmap [ (get-in qmap [:habitname]) (get-in qmap [:d]) ]
(get-in qmap [:boolemoji])
)
)
)
)
(def outputvect [])
(doseq [habit (keys (into (sorted-map) habitmap) ) ]
(def datemap (habitmap habit))
(def datemap (into (sorted-map) datemap) )
(def outputvect (conj outputvect (into (vector) (vals datemap)) ) )
(def outputvect (conj outputvect " " habit "\n" ))
)
(def outputvect (flatten outputvect))
(def output (clojure.string/join outputvect))
(str output) ;; the sole output of this query
)
}
#+END_QUERY
on a page it looks like this:
but as a journal query, it looks like this:
I also appreciate any suggestions to optimize(?) it more, thanks!