I have tasks sprinkled throughout project notes in my vault. I use inline Dataview fields to flag them to do today (assigned) and sometimes to append an estimate of effort required.
For example, Project A.md might contain:
* [ ] Task 1, a trivial task. [assigned:: 2022-12-29]
* [ ] Task 2, a more substantial task. [assigned:: 2022-12-29], [effort:: 15 minutes]
* [ ] Task 3, an involved task. [assigned:: 2022-12-29], [effort:: 2 hours]
* [ ] Task 4, for someday later.
but being ignorant of Javascript, don’t know how to sum the array, and was only able to make this meager progress with the help of this vault of example Dataview queries.
TABLE rows.T.text, rows.T.effort, sum(rows.T.effort)
FROM #Project
FLATTEN file.tasks AS T
WHERE !T.completed AND T.assigned AND T.effort
GROUP BY file.link
a list with total per file
LIST sum(rows.T.effort)
FROM #Project
FLATTEN file.tasks AS T
WHERE !T.completed AND T.assigned AND T.effort
GROUP BY file.link
the global total
LIST WITHOUT ID "**Global Effort**: " + sum(rows.T.effort)
FROM #Project
FLATTEN file.tasks AS T
WHERE !T.completed AND T.assigned AND T.effort
GROUP BY true
This one isn’t an inline query. To that you need to use dvjs. But I’m not versed in js to help you with the conversion of duration. For example, taking your example, you can “sum” in this way:
But the problem is: you get the duration in milliseconds… And I don’t know how to convert that to hours, minutes. (I guess it’s necessary a function with some math…)
Thank you very much. Since I wrote the OP I’ve effectively locked myself out of my laptop and just about everything else for the next few days, so I regret that I won’t be able to try these until I’m reunited with my hardware key.
I think the summing of durations can be handled by Luxon, though I’d be just as happy using numbers only to represent hours. Thanks again!
Thanks again, @mnvwvnm. Your DQL queries do everything I described, and my preference for keeping DataviewJS disabled trumps my cosmetic preference for the totals query being inline.
For the benefit of anyone visiting this thread later, replacing this line:
const total = tasks.effort.array().reduce((acc, val) => acc + val, 0)
returns a total like “3 hours, 15 minutes,” but if the total is in round hours, something like “4 hours, 0 minutes.” Replacing shiftTo() with rescale() ought to fix this, I think, but causes an error (rescale is not a function).