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:

{:title "Number of workouts done"
 :query [:find (count ?b)
     [?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:")]

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