Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- week: {{date:w}}
- year: {{date:gggg}}
- ---
- # {{date:[Week] ww [-] MMM gggg}}
- ## Journal
- ``` dataview
- LIST log
- FROM "10 - Daily Notes"
- WHERE log
- AND date(file.day).weekyear = this.week
- AND date(file.day).year = this.year
- ```
- ## Gesundheit
- ``` dataviewjs
- async function getGoalAverage(nDays) {
- //console.log('nbDays: ' + nbDays);
- const kpiIcons = ['🦶', '🕗', '📈']
- const goals = [4000, 420, 70];
- const qryWeekAverage = await dv.query(`
- TABLE WITHOUT ID
- round(sum(rows.schritte) / `+nDays+`) as "Schritte",
- round(sum(rows.schlafdauer) / `+nDays+`) as "SchlafDauer",
- round(sum(rows.schlafquali) / `+nDays+`) as "SchlafIndex"
- FROM "10 - Daily Notes"
- WHERE schritte
- AND date(file.day).weekyear = this.week
- AND date(file.day).year = this.year
- GROUP BY true
- `)
- var schritte = qryWeekAverage.value.values[0][0];
- var dauer = qryWeekAverage.value.values[0][1];
- var index = qryWeekAverage.value.values[0][2];
- var rDauer = 0;
- var summary = '';
- if (schritte == null) {schritte='-';}
- if (dauer == null) {
- dauer = '-';
- } else {
- dauer = Math.round(dauer / 60 * 10) / 10;
- }
- if (index == null) {index='-';}
- // Gewicht
- const qryGewicht = await dv.query(`TABLE WITHOUT ID file.name as Date, gewicht as Gewicht FROM "10 - Daily Notes" WHERE gewicht SORT file.name DESC `)
- var datum = qryGewicht.value.values[0][0]
- var gewicht = qryGewicht.value.values[0][1]
- summary = `*Schritte (∅/Tag):* **${schritte}**
- *Schlafen (∅/Tag):* **${dauer}** Stunden (**${index}**)
- *Gewicht am ${datum}:* **${gewicht}** kg`;
- dv.paragraph(summary);
- //************
- 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 + '||||\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.span(out);
- } // end: function
- // *******************
- // Execute main function
- // *******************
- const qryNbDays = await dv.query(`
- TABLE WITHOUT ID
- length(rows)
- FROM "10 - Daily Notes"
- WHERE schritte
- AND date(file.day).weekyear = this.week
- AND date(file.day).year = this.year
- GROUP BY true
- `);
- let nbDays = qryNbDays.value.values[0][0];
- getGoalAverage(nbDays);
- this.container.style.width = "100%";
- this.container.style.margin = "auto";
- ```
- ### Gesundheit Details
- ``` dataview
- TABLE WITHOUT ID
- link(file.name) AS Date,
- choice(schritte >= 4000, "🟩 (" + schritte + ")",
- "🟥 (" + schritte + ")" ) AS "Schritte",
- choice(schlafdauer >= 420, "🟩 (" + schlafdauer + ")",
- "🟥 (" + schlafdauer + ")" ) AS "Schlaf Dauer",
- choice(schlafquali >= 70, "🟩 (" + schlafquali + ")", "🟥 (" + schlafquali + ")" ) AS "Schlaf Index"
- FROM
- "10 - Daily Notes"
- WHERE date(file.day).weekyear = this.week
- AND date(file.day).year = this.year
- AND schritte AND schlafdauer AND schlafquali
- ```
- ## Gewicht
- ```dataviewjs
- const rawData = await dv.query('TABLE WITHOUT ID file.name as Date, gewicht as Gewicht FROM "10 - Daily Notes" WHERE gewicht AND date(file.day).weekyear = this.week AND date(file.day).year = this.year SORT Date');
- const rows = rawData.value.values;
- const chartWidth = "100%";
- const target = 64;
- const chartData = {
- width: chartWidth,
- data: {
- labels: rows.map(x => x[0]),
- datasets: [
- {
- type: 'line',
- label: 'Gewicht (kg)',
- data: rows.map(x => x[1]),
- backgroundColor: ['rgba(100, 50, 255, 0.4)'],
- borderColor: ['rgba(100, 50, 255, 1)'],
- borderWidth: 2,
- borderSkipped: false,
- fill: true,
- stepped: false,
- },
- {
- type: 'line',
- label: 'Ziel',
- data: Array(rows.length).fill(target),
- backgroundColor: ['rgba(255, 99, 132, 0.4)'],
- borderColor: ['rgba(255, 99, 132, 0.4)'],
- borderWidth: 2,
- borderSkipped: false
- },
- ],
- },
- options: {
- plugins: {
- legend: true,
- },
- scales: {
- y1: {
- type: 'linear',
- display: true,
- position: 'left',
- },
- },
- },
- }
- window.renderChart(chartData, this.container);
- ```
- ## Schlaf
- ```dataviewjs
- const data = await dv.query('TABLE WITHOUT ID file.name, schlafstart, schlafstop, schlafdauer, schlafquali FROM "10 - Daily Notes" WHERE schlafstart AND schlafstop AND date(file.day).weekyear = this.week AND date(file.day).year = this.year SORT file.name');
- const rows = data.value.values;
- const smallest = moment("2022-01-01T00:00");
- const biggest = moment("2022-01-01T24:00");
- const mid = moment("2022-01-01T24:00");
- const smallestscale = moment("2022-01-01T12:00");
- const biggestscale = moment("2022-01-03T12:00");
- let went = Array.from(rows.map(x => moment(x[0] + "T" + x[1].toString()).add(1, 'hour')));
- let awoke = Array.from(rows.map(x => moment(x[0] + "T" + x[2].toString()).add(1, 'hour')));
- went = went.map(x => x == null ? null :
- moment((x - smallest) % (biggest - smallest) + smallest));
- awoke = awoke.map(x => x == null ? null :
- moment((x - smallest) % (biggest - smallest) + smallest));
- const target = moment("2022-01-01T23:00") + 86400000;
- const sleepChart = {
- type: 'bar',
- data: {
- labels: rows.map(x => x[0]),
- datasets: [{
- label: 'Schlaf',
- data: Array.from(rows.map((x, i) => {
- var tempawoke = awoke[i];
- var tempwent = went[i];
- if (went[i] <= biggest)
- {
- tempawoke += 86400000; tempwent += 86400000;
- }
- if (went[i] < awoke[i]) { tempawoke -= 0; tempwent += 86400000; }
- tempawoke += 86400000;
- return [tempawoke, tempwent]
- })),
- backgroundColor: ['rgba(100, 50, 255, 0.4)'],
- borderColor: ['rgba(100, 50, 255, 1)'],
- borderWidth: 2,
- borderSkipped: false
- }, {
- type: 'line',
- label: 'Ziel',
- data: Array(awoke.length).fill(target),
- backgroundColor: ['rgba(255, 99, 132, 0.4)'],
- borderColor: ['rgba(255, 99, 132, 0.4)'],
- borderWidth: 2,
- borderSkipped: false
- }],
- },
- options: {
- scales: {
- y: {
- type: 'time',
- time: {
- unit: 'hour',
- displayFormats: {
- hour: 'HH:mm'
- }
- },
- min: smallest + 86400000 * 1.5,
- max: smallest + 86400000 * 2.5
- },
- },
- plugins: {
- tooltip: {
- callbacks: {
- label: function (tti) {
- var val = JSON.parse(tti.formattedValue);
- var diff = (val[1] - val[0]);
- if (diff < 0) diff = val[0] - val[1]
- var hours = Math.floor(diff / 3.6e6);
- var minutes = Math.floor((diff % 3.6e6) / 6e4);
- return [moment(val[1]).format("HH:mm") + " - " + moment(val[0]).format("HH:mm"), "Slept:" + String(hours).padStart(2, '0') + ":" + String(minutes).padStart(2, '0')];
- }
- }
- }
- }
- }
- }
- window.renderChart(sleepChart, this.container);
- ```
- ```dataviewjs
- const rawData = await dv.query('TABLE WITHOUT ID file.name as Date, schlafdauer as Dauer, schlafquali as Quali FROM "10 - Daily Notes" WHERE schlafquali AND date(file.day).weekyear = this.week AND date(file.day).year = this.year SORT Date');
- const rows = rawData.value.values;
- const chartWidth = "100%";
- const target = 420;
- const chartData = {
- width: chartWidth,
- data: {
- labels: rows.map(x => x[0]),
- datasets: [
- {
- type: 'bar',
- label: 'Qualität',
- data: rows.map(x => x[2]),
- backgroundColor: ['rgba(153, 153, 153, 0.4)'],
- borderColor: ['rgba(153, 153, 153, 1)'],
- borderWidth: 2,
- borderSkipped: false,
- fill: false,
- stepped: false,
- yAxisID: 'y2',
- },
- {
- type: 'bar',
- label: 'Dauer',
- data: rows.map(x => x[1]),
- backgroundColor: ['rgba(100, 50, 255, 0.4)'],
- borderColor: ['rgba(100, 50, 255, 1)'],
- borderWidth: 2,
- borderSkipped: false,
- fill: false,
- stepped: false,
- yAxisID: 'y1',
- },
- {
- type: 'line',
- label: 'Ziel',
- data: Array(rows.length).fill(target),
- backgroundColor: ['rgba(255, 99, 132, 0.4)'],
- borderColor: ['rgba(255, 99, 132, 0.4)'],
- borderWidth: 2,
- borderSkipped: false
- }
- ],
- },
- options: {
- plugins: {
- legend: true,
- },
- scales: {
- y1: {
- type: 'linear',
- display: true,
- position: 'left',
- },
- y2: {
- type: 'linear',
- display: true,
- position: 'right',
- },
- },
- },
- }
- this.container.style.width = "100%";
- this.container.style.margin = "20px 0px 0px 0px";
- window.renderChart(chartData, this.container);
- ```
- ## Gehen
- ### Schritte
- ```dataviewjs
- const rawData = await dv.query('TABLE WITHOUT ID file.name as Date, schritte as Schritte FROM "10 - Daily Notes" WHERE schritte AND date(file.day).weekyear = this.week AND date(file.day).year = this.year SORT Date');
- const rows = rawData.value.values;
- const chartWidth = "100%";
- const target = 4000;
- const chartData = {
- width: chartWidth,
- data: {
- labels: rows.map(x => x[0]),
- datasets: [
- {
- type: 'bar',
- label: 'Schritte',
- data: rows.map(x => x[1]),
- backgroundColor: ['rgba(100, 50, 255, 0.4)'],
- borderColor: ['rgba(100, 50, 255, 1)'],
- borderWidth: 2,
- borderSkipped: false,
- fill: false,
- stepped: false,
- },
- {
- type: 'line',
- label: 'Ziel',
- data: Array(rows.length).fill(target),
- backgroundColor: ['rgba(255, 99, 132, 0.4)'],
- borderColor: ['rgba(255, 99, 132, 0.4)'],
- borderWidth: 2,
- borderSkipped: false
- },
- ],
- },
- options: {
- plugins: {
- legend: true,
- },
- scales: {
- y1: {
- type: 'linear',
- display: true,
- position: 'left',
- },
- },
- },
- }
- this.container.style.width = chartWidth;
- this.container.style.margin = "20px 0px 0px 0px";
- window.renderChart(chartData, this.container);
- ```
- ### Sport Übersicht
- ```dataview
- TABLE WITHOUT ID
- round(sum(rows.G.distanz),2) AS "∑ km",
- round(sum(rows.G.dauer)) AS "∑ Zeit",
- round(sum(rows.G.distanz)/length(rows), 2) AS "∅ km",
- round(sum(rows.G.dauer)/length(rows)) AS "∅ Zeit",
- round(sum(rows.G.geschwindigkeit)/length(rows), 1) AS "∅ km/h",
- round(max(rows.G.puls-max)) AS "max Puls",
- round(sum(rows.G.hf-schnitt)/length(rows)) AS "∅ HF"
- FROM "10 - Daily Notes"
- WHERE sport
- AND (contains(sport.type, "Gehen")
- OR contains(sport.type, "Laufen"))
- AND date(file.day).weekyear = this.week
- AND date(file.day).year = this.year
- FLATTEN sport.gehen AS G
- GROUP BY true
- ```
- ### Sport Details
- ``` dataview
- TABLE WITHOUT ID
- link(file.name) AS "Datum",
- sport.type AS "Aktivität",
- round(G.distanz,1) AS "km",
- round(G.dauer) AS "Minuten",
- round(G.geschwindigkeit,1) AS "km/h",
- round(G.puls-max) as "max. Puls",
- round(G.hf-schnitt) as "∅ HF"
- FROM "10 - Daily Notes"
- WHERE sport
- AND (contains(sport.type, "Gehen")
- OR contains(sport.type, "Laufen"))
- AND date(file.day).weekyear = this.week
- AND date(file.day).year = this.year
- FLATTEN sport.gehen AS G
- SORT file.name DESC
- ```
Add Comment
Please, Sign In to add comment