I created the following for a simple way to track tasks as percent complete. I provided a couple examples, I hope folks find this useful:
THIS EXAMPLE IS A SIMPLE DATA VIEW QUERY THAT RETRIEVES FILE NAMES FROM A DEDICATED TASK LIST DIRECTORY
Task List(s) Links
list
from "02 - TASKS TO-DO"
where file.name
sort startswith(file.name, "View") desc, file.name asc
THE FOLLOWING EXAMPLE RETRIEVES THE PCT COMPLETE EACH TASK IS THAT WERE FOUND IN EACH OF THE FILES:
EXAMPLE OF A TASK SETUP FOR POLLING:
- This is a task, PCT 25%
- This is a Task, PCT 80
- This is a Task
the one above counts as 100 pct complete
const folderPath = "02 - TASKS TO-DO";
const pages = dv.pages('"02 - TASKS TO-DO"');
const regex = /^(.*?),\s*PC\s*(\d+)%?/i;
for (const page of pages) {
const tasks = page.file?.tasks ?? [];
let taskData = [];
for (const t of tasks) {
let percent = 0;
if (t.completed) {
percent = 100;
} else {
const match = t.text.match(regex);
if (match) {
percent = parseInt(match[2]);
} else {
continue;
}
}
taskData.push(percent);
}
// Build display line
const fileLink = dv.fileLink(page.file.path);
if (taskData.length === 0) {
dv.paragraph(`${fileLink} — 🚫 not monitored`);
} else {
const avg = Math.round(taskData.reduce((a, b) => a + b, 0) / taskData.length);
dv.paragraph(`${fileLink} — 📊 ${avg}%`);
}
}
SAME AS ABOVE BUT DISPLAYS THE RESULTS IN A TABLE :
const folderPath = "02 - TASKS TO-DO";
const pages = dv.pages(`"${folderPath}"`);
const regex = /^(.*?),\s*PC\s*(\d+)%?/i;
let tableRows = [];
for (const page of pages) {
const tasks = page.file?.tasks ?? [];
let taskPercents = [];
for (const t of tasks) {
let percent = 0;
if (t.completed) {
percent = 100;
} else {
const match = t.text.match(regex);
if (match) {
percent = parseInt(match[2]);
} else {
continue;
}
}
taskPercents.push(percent);
}
const fileLink = dv.fileLink(page.file.path);
const status = taskPercents.length === 0
? "UKN"
: `${Math.round(taskPercents.reduce((a, b) => a + b, 0) / taskPercents.length)}%`;
tableRows.push([fileLink, status]);
}
dv.table(["📄 File", "📊 Avg Completion"], tableRows);