dhniceday

Obsidian weekly note template

Oct 1st, 2023
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ---
  2. week: {{date:w}}
  3. year: {{date:gggg}}
  4. ---
  5.  
  6.  
  7. # {{date:[Week] ww [-] MMM gggg}}
  8.  
  9. ## Journal
  10.  
  11. ``` dataview
  12. LIST log
  13. FROM "10 - Daily Notes"
  14. WHERE log
  15. AND date(file.day).weekyear  = this.week
  16. AND date(file.day).year = this.year
  17. ```
  18.  
  19. ## Gesundheit
  20.  
  21. ``` dataviewjs
  22. async function getGoalAverage(nDays) {
  23.  
  24.     //console.log('nbDays: ' + nbDays);
  25.  
  26.     const kpiIcons = ['🦶', '🕗', '📈']
  27.     const goals = [4000, 420, 70];
  28.    
  29.     const qryWeekAverage = await dv.query(`
  30.     TABLE WITHOUT ID
  31.         round(sum(rows.schritte) / `+nDays+`) as "Schritte",
  32.         round(sum(rows.schlafdauer) / `+nDays+`) as "SchlafDauer",
  33.         round(sum(rows.schlafquali) / `+nDays+`) as "SchlafIndex"
  34.     FROM "10 - Daily Notes"
  35.     WHERE schritte
  36.     AND date(file.day).weekyear  = this.week
  37.     AND date(file.day).year = this.year
  38.     GROUP BY true
  39.     `)
  40.    
  41. var schritte = qryWeekAverage.value.values[0][0];
  42. var dauer = qryWeekAverage.value.values[0][1];
  43. var index = qryWeekAverage.value.values[0][2];
  44.  
  45. var rDauer = 0;
  46. var summary = '';
  47.  
  48. if (schritte == null) {schritte='-';}
  49. if (dauer == null) {
  50.     dauer = '-';
  51. } else {
  52.     dauer = Math.round(dauer / 60 * 10) / 10;
  53. }
  54. if (index == null) {index='-';}
  55.  
  56. // Gewicht
  57.  
  58. 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 `)
  59.  
  60. var datum = qryGewicht.value.values[0][0]
  61. var gewicht = qryGewicht.value.values[0][1]
  62.  
  63. summary = `*Schritte (/Tag):* **${schritte}**
  64. *Schlafen (/Tag):* **${dauer}** Stunden (**${index}**)
  65. *Gewicht am ${datum}:* **${gewicht}** kg`;
  66.  
  67. dv.paragraph(summary);
  68.  
  69. //************
  70.  
  71.    
  72.     let wAvg = qryWeekAverage.value.values;
  73.     let wAvgTable = [];
  74.     let tmpTable = [];
  75.    
  76.     for (let r of wAvg) {
  77.         for (var i = 0; i < goals.length; i++) {
  78.             const stat = r[i];
  79.             const goal = goals[i];
  80.             const kpiName = kpiIcons[i];
  81.            
  82.             const percentOfGoal = Math.round(stat * 100 / goal);
  83.             let progressBar = '<progress value="' + percentOfGoal + '" max="100"></progress>'
  84.  
  85.             tmpTable.push(kpiName);
  86.             tmpTable.push(stat);
  87.             tmpTable.push(goal);
  88.             tmpTable.push(percentOfGoal);
  89.             tmpTable.push(progressBar);
  90.    
  91.             wAvgTable.push(tmpTable);
  92.             tmpTable = [];
  93.         }
  94.     }
  95.    
  96.     // === Output ===
  97.     var out = '';
  98.  
  99.     // Table
  100.  
  101.     out = out + '||||\n';
  102.     out = out + '|---|---|\n';
  103.     for (let r of wAvgTable) {
  104.             let kpi = r[0];
  105.             let actual = r[1];
  106.             let target = r[2];
  107.             let percent = r[3];
  108.             let bar = r[4];
  109.  
  110.             out = out + '|' + kpi + '|' + bar + '|\n';
  111.     }
  112.    
  113.     dv.span(out);
  114.    
  115. } // end: function
  116.  
  117. // *******************
  118. // Execute main function
  119. // *******************
  120.  
  121. const qryNbDays = await dv.query(`
  122.     TABLE WITHOUT ID
  123.         length(rows)
  124.     FROM "10 - Daily Notes"
  125.     WHERE schritte
  126.     AND date(file.day).weekyear  = this.week
  127.     AND date(file.day).year = this.year
  128.     GROUP BY true
  129.     `);
  130.    
  131. let nbDays = qryNbDays.value.values[0][0];
  132.  
  133. getGoalAverage(nbDays);
  134.  
  135. this.container.style.width = "100%";
  136. this.container.style.margin = "auto";
  137. ```
  138.  
  139. ### Gesundheit Details
  140.  
  141. ``` dataview
  142. TABLE WITHOUT ID
  143.     link(file.name) AS Date,
  144.     choice(schritte >= 4000, "🟩 (" + schritte + ")",
  145.     "🟥 (" + schritte + ")" ) AS "Schritte",
  146.     choice(schlafdauer >= 420, "🟩 (" + schlafdauer + ")",
  147.     "🟥 (" + schlafdauer + ")" ) AS "Schlaf Dauer",
  148.     choice(schlafquali >= 70, "🟩 (" + schlafquali + ")", "🟥 (" + schlafquali + ")" ) AS "Schlaf Index"
  149. FROM
  150.     "10 - Daily Notes"
  151. WHERE date(file.day).weekyear  = this.week
  152. AND date(file.day).year = this.year
  153. AND schritte AND schlafdauer AND schlafquali
  154. ```
  155.  
  156. ## Gewicht
  157.  
  158. ```dataviewjs
  159.     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');
  160. const rows = rawData.value.values;
  161.  
  162. const chartWidth = "100%";
  163.  
  164. const target = 64;
  165.  
  166. const chartData = {
  167.     width: chartWidth,
  168.     data: {
  169.         labels: rows.map(x => x[0]),
  170.         datasets: [
  171.             {
  172.             type: 'line',
  173.             label: 'Gewicht (kg)',
  174.             data: rows.map(x => x[1]),
  175.             backgroundColor: ['rgba(100, 50, 255, 0.4)'],
  176.             borderColor: ['rgba(100, 50, 255, 1)'],
  177.             borderWidth: 2,
  178.             borderSkipped: false,
  179.             fill: true,
  180.             stepped: false,
  181.             },
  182.             {
  183.               type: 'line',
  184.               label: 'Ziel',
  185.               data: Array(rows.length).fill(target),
  186.               backgroundColor: ['rgba(255, 99, 132, 0.4)'],
  187.               borderColor: ['rgba(255, 99, 132, 0.4)'],
  188.               borderWidth: 2,
  189.               borderSkipped: false
  190.             },
  191.         ],
  192.     },
  193.     options: {
  194.         plugins: {
  195.             legend: true,
  196.         },
  197.         scales: {
  198.             y1: {
  199.                 type: 'linear',
  200.                 display: true,
  201.                 position: 'left',
  202.             },
  203.         },
  204.     },
  205. }
  206.  
  207. window.renderChart(chartData, this.container);
  208. ```
  209.  
  210. ## Schlaf
  211.  
  212. ```dataviewjs
  213. 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');
  214. const rows = data.value.values;
  215.  
  216. const smallest = moment("2022-01-01T00:00");
  217. const biggest = moment("2022-01-01T24:00");
  218.  
  219. const mid = moment("2022-01-01T24:00");
  220.  
  221. const smallestscale = moment("2022-01-01T12:00");
  222. const biggestscale = moment("2022-01-03T12:00");
  223.  
  224. let went = Array.from(rows.map(x => moment(x[0] + "T" + x[1].toString()).add(1, 'hour')));
  225. let awoke = Array.from(rows.map(x => moment(x[0] + "T" + x[2].toString()).add(1, 'hour')));
  226.  
  227. went = went.map(x => x == null ? null :
  228.   moment((x - smallest) % (biggest - smallest) + smallest));
  229.  
  230. awoke = awoke.map(x => x == null ? null :
  231.   moment((x - smallest) % (biggest - smallest) + smallest));
  232.  
  233. const target = moment("2022-01-01T23:00") + 86400000;
  234.  
  235.  
  236. const sleepChart = {
  237.   type: 'bar',
  238.   data: {
  239.     labels: rows.map(x => x[0]),
  240.     datasets: [{
  241.       label: 'Schlaf',
  242.       data: Array.from(rows.map((x, i) => {
  243.           var tempawoke = awoke[i];
  244.           var tempwent = went[i];
  245.  
  246.           if (went[i] <= biggest)
  247.           {
  248.             tempawoke += 86400000; tempwent += 86400000;
  249.           }
  250.           if (went[i] < awoke[i]) { tempawoke -= 0; tempwent += 86400000; }
  251.           tempawoke += 86400000;
  252.           return [tempawoke, tempwent]
  253.       })),
  254.       backgroundColor: ['rgba(100, 50, 255, 0.4)'],
  255.       borderColor: ['rgba(100, 50, 255, 1)'],
  256.       borderWidth: 2,
  257.       borderSkipped: false
  258.     }, {
  259.       type: 'line',
  260.       label: 'Ziel',
  261.       data: Array(awoke.length).fill(target),
  262.       backgroundColor: ['rgba(255, 99, 132, 0.4)'],
  263.       borderColor: ['rgba(255, 99, 132, 0.4)'],
  264.       borderWidth: 2,
  265.       borderSkipped: false
  266.     }],
  267.   },
  268.   options: {
  269.     scales: {
  270.       y: {
  271.         type: 'time',
  272.         time: {
  273.           unit: 'hour',
  274.           displayFormats: {
  275.             hour: 'HH:mm'
  276.           }
  277.         },
  278.        
  279.         min: smallest + 86400000 * 1.5,
  280.         max: smallest + 86400000 * 2.5
  281.       },
  282.     },
  283.     plugins: {
  284.       tooltip: {
  285.         callbacks: {
  286.             label: function (tti) {
  287.                 var val = JSON.parse(tti.formattedValue);
  288.                 var diff = (val[1] - val[0]);
  289.                 if (diff < 0) diff = val[0] - val[1]
  290.                 var hours = Math.floor(diff / 3.6e6);
  291.                 var minutes = Math.floor((diff % 3.6e6) / 6e4);
  292.                 return [moment(val[1]).format("HH:mm") + " - " + moment(val[0]).format("HH:mm"), "Slept:" + String(hours).padStart(2, '0') + ":" + String(minutes).padStart(2, '0')];
  293.           }
  294.         }
  295.       }
  296.     }
  297.   }
  298. }
  299.  
  300. window.renderChart(sleepChart, this.container);
  301. ```
  302.  
  303. ```dataviewjs
  304.     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');
  305. const rows = rawData.value.values;
  306.  
  307. const chartWidth = "100%";
  308.  
  309. const target = 420;
  310.  
  311. const chartData = {
  312.     width: chartWidth,
  313.     data: {
  314.         labels: rows.map(x => x[0]),
  315.         datasets: [
  316.             {
  317.             type: 'bar',
  318.             label: 'Qualität',
  319.             data: rows.map(x => x[2]),
  320.             backgroundColor: ['rgba(153, 153, 153, 0.4)'],
  321.             borderColor: ['rgba(153, 153, 153, 1)'],
  322.             borderWidth: 2,
  323.             borderSkipped: false,
  324.             fill: false,
  325.             stepped: false,
  326.             yAxisID: 'y2',
  327.             },  
  328.             {
  329.             type: 'bar',
  330.             label: 'Dauer',
  331.             data: rows.map(x => x[1]),
  332.             backgroundColor: ['rgba(100, 50, 255, 0.4)'],
  333.             borderColor: ['rgba(100, 50, 255, 1)'],
  334.             borderWidth: 2,
  335.             borderSkipped: false,
  336.             fill: false,
  337.             stepped: false,
  338.             yAxisID: 'y1',
  339.             },
  340.             {
  341.               type: 'line',
  342.               label: 'Ziel',
  343.               data: Array(rows.length).fill(target),
  344.               backgroundColor: ['rgba(255, 99, 132, 0.4)'],
  345.               borderColor: ['rgba(255, 99, 132, 0.4)'],
  346.               borderWidth: 2,
  347.               borderSkipped: false
  348.             }
  349.      
  350.         ],
  351.     },
  352.     options: {
  353.         plugins: {
  354.             legend: true,
  355.         },
  356.         scales: {
  357.             y1: {
  358.                 type: 'linear',
  359.                 display: true,
  360.                 position: 'left',
  361.             },
  362.             y2: {
  363.                 type: 'linear',
  364.                 display: true,
  365.                 position: 'right',
  366.             },
  367.         },
  368.     },
  369. }
  370.  
  371. this.container.style.width = "100%";
  372. this.container.style.margin = "20px 0px 0px 0px";
  373. window.renderChart(chartData, this.container);
  374. ```
  375.  
  376. ## Gehen
  377.  
  378. ### Schritte
  379.  
  380. ```dataviewjs
  381.     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');
  382. const rows = rawData.value.values;
  383.  
  384. const chartWidth = "100%";
  385.  
  386. const target = 4000;
  387.  
  388. const chartData = {
  389.     width: chartWidth,
  390.     data: {
  391.         labels: rows.map(x => x[0]),
  392.         datasets: [
  393.             {
  394.             type: 'bar',
  395.             label: 'Schritte',
  396.             data: rows.map(x => x[1]),
  397.             backgroundColor: ['rgba(100, 50, 255, 0.4)'],
  398.             borderColor: ['rgba(100, 50, 255, 1)'],
  399.             borderWidth: 2,
  400.             borderSkipped: false,
  401.             fill: false,
  402.             stepped: false,
  403.             },
  404.             {
  405.               type: 'line',
  406.               label: 'Ziel',
  407.               data: Array(rows.length).fill(target),
  408.               backgroundColor: ['rgba(255, 99, 132, 0.4)'],
  409.               borderColor: ['rgba(255, 99, 132, 0.4)'],
  410.               borderWidth: 2,
  411.               borderSkipped: false
  412.             },
  413.         ],
  414.     },
  415.     options: {
  416.         plugins: {
  417.             legend: true,
  418.         },
  419.         scales: {
  420.             y1: {
  421.                 type: 'linear',
  422.                 display: true,
  423.                 position: 'left',
  424.             },
  425.         },
  426.     },
  427. }
  428.  
  429. this.container.style.width = chartWidth;
  430. this.container.style.margin = "20px 0px 0px 0px";
  431. window.renderChart(chartData, this.container);
  432. ```
  433.  
  434. ### Sport Übersicht
  435.  
  436. ```dataview
  437. TABLE WITHOUT ID
  438.     round(sum(rows.G.distanz),2) AS "∑ km",
  439.     round(sum(rows.G.dauer)) AS "∑ Zeit",
  440.     round(sum(rows.G.distanz)/length(rows), 2) AS "∅ km",
  441.     round(sum(rows.G.dauer)/length(rows)) AS "∅ Zeit",
  442.     round(sum(rows.G.geschwindigkeit)/length(rows), 1) AS "∅ km/h",
  443.     round(max(rows.G.puls-max)) AS "max Puls",
  444.     round(sum(rows.G.hf-schnitt)/length(rows)) AS "∅ HF"
  445. FROM "10 - Daily Notes"
  446. WHERE sport
  447. AND (contains(sport.type, "Gehen")
  448. OR contains(sport.type, "Laufen"))
  449. AND date(file.day).weekyear  = this.week
  450. AND date(file.day).year = this.year
  451. FLATTEN sport.gehen AS G
  452. GROUP BY true
  453. ```
  454.  
  455. ### Sport Details
  456.  
  457. ``` dataview
  458. TABLE WITHOUT ID
  459.     link(file.name) AS "Datum",
  460.     sport.type AS "Aktivität",
  461.     round(G.distanz,1) AS "km",
  462.     round(G.dauer) AS "Minuten",
  463.     round(G.geschwindigkeit,1) AS "km/h",
  464.     round(G.puls-max) as "max. Puls",
  465.     round(G.hf-schnitt) as "∅ HF"
  466. FROM "10 - Daily Notes"
  467. WHERE sport
  468. AND (contains(sport.type, "Gehen")
  469. OR contains(sport.type, "Laufen"))
  470. AND date(file.day).weekyear  = this.week
  471. AND date(file.day).year = this.year
  472. FLATTEN sport.gehen AS G
  473. SORT file.name DESC
  474. ```
Add Comment
Please, Sign In to add comment