Help counting entries in a logbook

I’d really appreciate some help putting together a query. I’ve tried but struggled to get started with them.

I have this content on the page where I track my workouts:

- Logs:
	- [[Thu Mar 2nd, 2023]] - Legs #workout
	- [[Sat Mar 4th, 2023]] - Upper body #workout
	- [[Tue Mar 7th, 2023]] - Legs #workout
	- [[Sat Mar 11th, 2023]] - Upper body #workout
        - ...

I have a goal of 50 workouts by July 1st.

I’d like to write a query that will:

  1. Count the entries in that list.
  2. Print out this message:
Today is 2023-04-18 and there are 74 days and 10 weeks until July 1st
  Workouts per week to hit your goal: 2.2

  20/50  🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ 

Where the number of green boxes are the number of entries in the list (20), and the whiteboxes is the number remaining to hit my goal (50 -20).

Thanks in advance for any help.

So the first part of your question is definitely doable.
However for the second part I would recommend either getting a dedicated tracker app for that or finding a plugin that does so.
I feel it’s not a use case to be solved with an advanced query. Besides that it doesn’t really support date functions anyway.

Here’s a query to get the number of workouts:

#+BEGIN_QUERY
{:title "Number of workouts done"
 :query [:find (count ?b)
   :where
     [?wo :block/name "workout"]
     [?b :block/refs ?wo]
; if you use the workout tag in other places, you can add this to narrow it down.
     [?b :block/parent ?log]
     [?log :block/content ?c]
     [(= ?c "Logs:")]
 ]
}
#+END_QUERY

HI. a part of “PULL” and “COUNT” what other action there are in the advance query?

Aggregates in general: Datomic Queries and Rules | Datomic
And just separate variables: Datomic Queries and Rules | Datomic

1 Like

This looks great. I am trying to get a count of all the times I use the #inbox tag, but not the [[inbox]] link. Is there a way to differentiate this?

So for Logseq those are the same. The only difference between them is visual. So we can only differentiate them in that way. In short via specific text search.

[?b :block/content? ?bc]
[(clojure.string/includes? ?bc "#inbox")]

Does that just replace the where: clause from above or get added to the end of it?

It gets added to the end of it.

So it would look something like this?

#+BEGIN_QUERY
{:title "Number of workouts done"
 :query [:find (count ?b)
   :where
     [?wo :block/name "inbox"]
     [?b :block/refs ?wo]
     [?b :block/content? ?bc]
     [(clojure.string/includes? ?bc "#inbox")]
 ]
}
#+END_QUERY

Correct. That’s how it should look.
(This post needs to be 20 characters long lol)