71 lines
2.2 KiB
Markdown
71 lines
2.2 KiB
Markdown
|
<%*
|
||
|
let filename = tp.file.title
|
||
|
let path = tp.file.folder(true)
|
||
|
let splitpath = path.split("/")
|
||
|
let unitindex = 2
|
||
|
if (splitpath.length > 2) { unitindex = 3 }
|
||
|
if (splitpath.length > 3) { unitindex = 4 }
|
||
|
if (path != "Notes" && path != "_Templates" && path != "Log") { %>
|
||
|
```table-of-contents
|
||
|
title: Contents
|
||
|
```
|
||
|
|
||
|
## Chart
|
||
|
<%* if (splitpath.length == 5) { %>
|
||
|
```dataviewjs
|
||
|
let query = `
|
||
|
TABLE WITHOUT ID
|
||
|
habit as habit,
|
||
|
created_ts as time,
|
||
|
unit as unit,
|
||
|
quantity as quantity
|
||
|
WHERE
|
||
|
startswith(file.folder, this.file.folder)
|
||
|
AND quantity != null AND unit != null
|
||
|
`;
|
||
|
let result = await dv.tryQuery(query);
|
||
|
let headers = ["Habit", "Created", "Unit", "Quantity"];
|
||
|
dv.table(result.headers,
|
||
|
dv.array(result.values)
|
||
|
.sort(r => r[2], "asc")
|
||
|
.sort(r => r[1], "desc")
|
||
|
.sort(r => r[0], "asc"));
|
||
|
```
|
||
|
<%* } else { %>
|
||
|
```dataviewjs
|
||
|
let query = `
|
||
|
TABLE WITHOUT ID
|
||
|
nonnull(rows.habit)[0] as habit,
|
||
|
split(rows.file.folder[0], "/")[2] as year,
|
||
|
<%* if (splitpath.length > 2) { %>split(rows.file.folder[0], "/")[3] as month,<%* } %>
|
||
|
<%* if (splitpath.length > 3) { %>split(rows.file.folder[0], "/")[4] as day,<%* } %>
|
||
|
nonnull(rows.unit)[0] as unit,
|
||
|
average(nonnull(rows.quantity)) as qty_avg,
|
||
|
sum(nonnull(rows.quantity)) as qty_tot
|
||
|
WHERE
|
||
|
startswith(file.folder, this.file.folder)
|
||
|
AND file.folder != this.file.folder
|
||
|
AND quantity != null AND unit != null
|
||
|
GROUP BY habit
|
||
|
+ split(file.folder, "/")[2]
|
||
|
<%* if (splitpath.length > 2) { %>+ split(file.folder, "/")[3]<%* } %>
|
||
|
<%* if (splitpath.length > 3) { %>+ split(file.folder, "/")[4]<%* } %>
|
||
|
+ unit
|
||
|
`;
|
||
|
let result = await dv.tryQuery(query);
|
||
|
let headers = ["Habit", "Year",
|
||
|
<%* if (splitpath.length > 2) { %>"Month", <%* } %>
|
||
|
<%* if (splitpath.length > 3) { %>"Day", <%* } %>
|
||
|
"Unit", "qty_avg", "qty_tot"];
|
||
|
dv.table(result.headers,
|
||
|
dv.array(result.values)
|
||
|
.sort(r => r[<% unitindex %>], "asc")
|
||
|
.sort(r => r[1], "desc")
|
||
|
<%* if (splitpath.length > 2) { %>.sort(r => r[2], "desc")<%* } %>
|
||
|
<%* if (splitpath.length > 3) { %>.sort(r => r[3], "desc")<%* } %>
|
||
|
.sort(r => r[0], "asc"));
|
||
|
```
|
||
|
<%* } %>
|
||
|
## Navigation<%* } %>
|
||
|
|
||
|
<%* if (splitpath.length == 3 || splitpath.length == 2) {%><% "%" + "% Landmark %" + "%" %> <%*} else {%><% "%" + "% Waypoint %" + "%" %><%*} %>
|