How do I calculate a value from a list of objects and display it?

I have the following page for tracking exercise. I have similar pages for other goals:

I have the following object decorator in my space-config:

objectDecorators:
- where: 'tag = "exercise"'
  attributes:
    week: 'weekNumberFor(day)'

I would like to display something like this on my index, a list of weeks I did (or didn’t) go to the gym, based on my #exercise object, and how that matches my rubric:

{{weekNumber}} || days went || rubric value

How can I:

  • Display "Week of XXXX-XX-XX (There are many date functions on the forums, I can probably figure that out?)
  • Sum the days in a week that I went to the gym
  • associate that number of days with a rubric value (I realize the rubric needs to be captured in an object or some other way to get this value)

I question whether:

  • using objects is “correct”
  • if I should be logging my goals differently
  • how I should be rendering the data I want to output.
  • is Goal Tracking/Exercise a bad path?

Also maybe this is a case of “When all you have is a hammer, everything looks like a nail” and I could be using a different tool. But also silverbullet is in the name :slight_smile:

Suggestions, recommendations, and alternatives are very welcome.

I just want to say, as someone who works in IT and has self-taught experience in programming, I love the concept of this tool and am very excited to use it more, but am very challenged to understand how to best utilize its capabilities. I’m hoping by asking questions specific to my needs I can better understand how I can use this tool.

I figured it out, here’s my solution:

Template

{{#let @lastWeek = weekNumberPrevious(today())}}

{{#let @exercises = {exercise where week = @lastWeek}}}
{{#let @numberOfExercises = count(@exercises)}}

{{#each {rubric-exercise}}}

{{#if score = @numberOfExercises}}
|Week of | Days Exercised|Rubric|
|--------|---------------|------|
|{{weekStart}} | {{@numberOfExercises}}| {{value}}
{{/if}}
{{/each}}

{{/let}}
{{/let}}
{{/let}}

Goal tracking page

score: 6 #day/week
value: "+3"
---
score: 5 #day/week
value: "+2"
---
score: 4 #day/week
value: "+1"
---
score: 3 #day/week
value: "0"
---
score: 2 #day/week
value: "-1"
---
score: 1 #day/week
value: "-2"
---
score: 0 #day/week
value: "-3"
---
day: "2024-10-22"
exercise: arms
---
day: "2024-10-23"
exercise: legs
---
day: "2024-10-24"
exercise: back
---
day: "2024-10-29"
exercise: arms
---
day: "2024-10-30"
exercise: back
---
day: "2024-11-01"
exercise: legs
---
day: "2024-11-02"
exercise: arms
---
day: "2024-11-03"
exercise: back

I made it a little better. I’m not sure how to remove the excessive white space though :sweat_smile:

EDIT: Whitespace. The problem was the whitespace. The template directive literally interpretted linebreaks. But then, when everything was bunched together, a blank row was added to the table. Solution: Wrap the table in comments #

{{#let @allExercises = {exercise}}}
{{#let @allExerciseWeeks = {exercise select week}}}
{{#let @uniqueExerciseWeeks = uniqueNumbers(@allExerciseWeeks)}}
{{#each @weekNumber in @uniqueExerciseWeeks}}
{{#let @exercisesThisWeek = count({exercise where week = @weekNumber.week})}}
{{#each {rubric-exercise}}}
{{#if value = @exercisesThisWeek}}
#
|Week of | Days Exercised|Rubric|
|--------|---------------|------|
|{{weekStartFromWeekNumber(@weekNumber.week)}}|{{@exercisesThisWeek}}|{{score}}
#
{{/if}}
{{/each}}
{{/let}}
{{/each}}
{{/let}}
{{/let}}
{{/let}}
5 Likes