Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- aliases:
- tags:
- title: Personal Goals
- date-created: 2022-11-24
- date-modified: 2022-11-25
- cssClass:
- - table-lines
- - table-small
- - row-lines
- - col-lines
- - wide-view
- ---
- %% [[2022-11-24]] %%
- >[!INFO] Ziele
- >🥤 *6* | 🦶 *6000* | 😴-🕗 *8* | 😴-📈 *100*
- ``` dataviewjs
- /*
- Frontmatter structure:
- ---
- gesundheit:
- schritte: 693
- wasser: 5
- schlafdauer: 401
- schlafquali: 87
- ---
- */
- async function getGoalAverage(nDays) {
- const kpis = ['Wasser', 'Schritte', 'Schlaf-Dauer)', 'Schlaf-Index']
- const kpiIcons = ['🥤', '🦶', '😴-🕗', '😴-📈']
- const goals = [6, 6000, 480, 100];
- const qryWeekAverage = await dv.query(`
- TABLE WITHOUT ID
- round(sum(rows.G.wasser) / `+nDays+`, 2) as "Wasser",
- round(sum(rows.G.schritte) / `+nDays+`) as "Schritte",
- round(sum(rows.G.schlafdauer) / `+nDays+`) as "SchlafDauer",
- round(sum(rows.G.schlafquali) / `+nDays+`) as "SchlafIndex"
- FROM "10 - Daily Notes"
- WHERE gesundheit.wasser
- AND gesundheit.wasser
- AND gesundheit.schritte
- AND gesundheit.schlafdauer
- AND gesundheit.schlafquali
- AND date(today) - file.day <= dur(`+nDays+` days)
- FLATTEN gesundheit AS G
- GROUP BY true
- `)
- let wAvg = qryWeekAverage.value.values;
- let wAvgTable = [];
- let tmpTable = [];
- for (let r of wAvg) {
- for (var i = 0; i < goals.length; i++) {
- const stat = r[i];
- const goal = goals[i];
- const kpiName = kpiIcons[i];
- const percentOfGoal = Math.round(stat * 100 / goal);
- let progressBar = '<progress value="' + percentOfGoal + '" max="100"></progress>'
- tmpTable.push(kpiName);
- tmpTable.push(stat);
- tmpTable.push(goal);
- tmpTable.push(percentOfGoal);
- tmpTable.push(progressBar);
- wAvgTable.push(tmpTable);
- tmpTable = [];
- }
- }
- // === Output ===
- var out = '';
- // Table
- out = out + '|*' + nDays + ' Tage*||\n';
- out = out + '|---|---|\n';
- for (let r of wAvgTable) {
- let kpi = r[0];
- let actual = r[1];
- let target = r[2];
- let percent = r[3];
- let bar = r[4];
- out = out + '|' + kpi + '|' + bar + '|\n';
- }
- dv.paragraph(out);
- } // end: function
- // Execute main function
- getGoalAverage(7);
- this.container.style.margin = "auto";
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement