Progress bar from Goals to be automatically updated by calculating the percentage of completed tasks in the child "Projects" that are linked to a "Parent Goal"

strong textHi there !

I’ve set up Christian’s BB Houman Goal Tracking System https://bagerbach.com/blog/projects-and-goals-obsidian, which is the best system I’ve tested so far.

However the is something missing in my opinion, it is the ability to have the progress bars updated automatically.

What I’m trying to do

I would like the progress bar of the Goals to be automatically updated by calculating the percentage of completed tasks in the child “Projects” that are linked to a “Parent Goal”.

Things I have tried

1. Displaying the progress bar

To sum all the completed tasks in Projects , I am using this code which work like a charm:

= "<progress value='" + (length(filter(this.file.tasks.completed, (t) => t = true)) / length(this.file.tasks)) * 100 + "' max='100'></progress>" + "<br>" + round((length(filter(this.file.tasks.completed, (t) => t = true)) / length(this.file.tasks)) * 100) + "% completed"

2. Getting the sum of tasks in the child projects

Then I needed to call the cild tasks, so I came up with these 2 inline queries that make the sum of all the tasks in the child projects that are linking to the current Goal. They are added in each goals :

Subtasks_Completed::  `$=dv.pages("[[" + dv.current().file.name + "]]").file.tasks.filter(t => t. completed).length`
Total_Subtasks
:: `$=dv.pages("[[" + dv.current().file.name + "]]").file.tasks.length` 

3. Obstacle : Can’t use the inline queries to render the progress bar

However when used as with dataview fields, I can’t use the results of these queries to render the progress bar.

'''dataview
TABLE WITHOUT ID
    (link(file.path, alias)) as title,
    round(Subtasks_Completed / Total_Subtasks * 100) + " %" AS "%", 
    "<progress value='" + (Subtasks_Completed / Total_Subtasks) * 100 + "' max='100'></progress>" AS Progress 
from -"_ Obsidian Elements/Templates" and #OKR/Goal 

SORT Type DESC
where Status !="Completed"
and Due_Date != date(thisQuater)

4. Rendering a Dataview table

So instead, I am trying to nest these inline queries within a dataview table , I am pretty sure it should work, but not how yet. Here is the dataview table I normally use for progress bars :

I came up with this dvjs :

const subtasks_completed = dv.pages("[[" + dv.current().file.name + "]]").file.tasks.filter(t => t. completed).length;

const total_subtasks = dv.pages("[[" + dv.current().file.name + "]]").file.tasks.length;

dv.table(["Title", "Progress"],dv.pages('#OKR/Goal').map(p => [
	dv.fileLink(p.file.path,false,[p.alias]),
	"<progress value='" + (subtasks_completed / total_subtasks) * 100 + "' max='100'></progress>"
	]))

But it does not work as expected, because in the const, the “dv.current” is not printing the tasks from the linked child projects, but the tasks on the current page.

So I need ti figure out a way to query the from the child projects.

Any help would be greatly appreciated !

3 Likes

A query to test under certain conditions:

  1. be placed in Goal note
  2. considering that all inlinks (notes linked) to Goal are Projects
const DQL = await dv.tryQuery(`TABLE WITHOUT ID
	N as Files,
	length(rows) AS Total,
	length(filter(rows.inT, (i) => i.completed)) AS Completed
FROM [[]]
FLATTEN file.tasks AS inT
GROUP BY file.link AS N`)

dv.table(["Projects", "Progress"], DQL.values.map(r => [r[0], "<progress value='" + (r[2]/r[1])*100 + "' max='100'></progress>" + "<br>" + Math.round((r[2]/r[1])*100) + "% completed" ]))
1 Like