dhniceday

Obsidian weekly template

Oct 21st, 2023
1,577
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.  
  136. ### Gesundheit Details
  137.  
  138. ``` dataview
  139. TABLE WITHOUT ID
  140.     link(file.name) AS Date,
  141.     choice(schritte >= 4000, "🟩 (" + schritte + ")",
  142.     "🟥 (" + schritte + ")" ) AS "Schritte",
  143.     choice(schlafdauer >= 420, "🟩 (" + schlafdauer + ")",
  144.     "🟥 (" + schlafdauer + ")" ) AS "Schlaf Dauer",
  145.     choice(schlafquali >= 70, "🟩 (" + schlafquali + ")", "🟥 (" + schlafquali + ")" ) AS "Schlaf Index"
  146. FROM
  147.     "10 - Daily Notes"
  148. WHERE date(file.day).weekyear  = this.week
  149. AND date(file.day).year = this.year
  150. AND schritte AND schlafdauer AND schlafquali
  151. ```
  152.  
  153. ## Gewicht
  154.  
  155. ```dataviewjs
  156.     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');
  157. const rows = rawData.value.values;
  158.  
  159. const chartWidth = "100%";
  160.  
  161. const target = 64;
  162.  
  163. const chartData = {
  164.     width: chartWidth,
  165.     data: {
  166.         labels: rows.map(x => x[0]),
  167.         datasets: [
  168.             {
  169.             type: 'line',
  170.             label: 'Gewicht (kg)',
  171.             data: rows.map(x => x[1]),
  172.             backgroundColor: ['rgba(100, 50, 255, 0.4)'],
  173.             borderColor: ['rgba(100, 50, 255, 1)'],
  174.             borderWidth: 2,
  175.             borderSkipped: false,
  176.             fill: true,
  177.             stepped: false,
  178.             },
  179.             {
  180.               type: 'line',
  181.               label: 'Ziel',
  182.               data: Array(rows.length).fill(target),
  183.               backgroundColor: ['rgba(255, 99, 132, 0.4)'],
  184.               borderColor: ['rgba(255, 99, 132, 0.4)'],
  185.               borderWidth: 2,
  186.               borderSkipped: false
  187.             },
  188.         ],
  189.     },
  190.     options: {
  191.         plugins: {
  192.             legend: true,
  193.         },
  194.         scales: {
  195.             y1: {
  196.                 type: 'linear',
  197.                 display: true,
  198.                 position: 'left',
  199.             },
  200.         },
  201.     },
  202. }
  203.  
  204. window.renderChart(chartData, this.container);
  205. ```
  206.  
  207. ## Schlaf
  208.  
  209. ```dataviewjs
  210. 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');
  211. const rows = data.value.values;
  212.  
  213. const smallest = moment("2022-01-01T00:00");
  214. const biggest = moment("2022-01-01T24:00");
  215.  
  216. const mid = moment("2022-01-01T24:00");
  217.  
  218. const smallestscale = moment("2022-01-01T12:00");
  219. const biggestscale = moment("2022-01-03T12:00");
  220.  
  221. let went = Array.from(rows.map(x => moment(x[0] + "T" + x[1].toString()).add(1, 'hour')));
  222. let awoke = Array.from(rows.map(x => moment(x[0] + "T" + x[2].toString()).add(1, 'hour')));
  223.  
  224. went = went.map(x => x == null ? null :
  225.   moment((x - smallest) % (biggest - smallest) + smallest));
  226.  
  227. awoke = awoke.map(x => x == null ? null :
  228.   moment((x - smallest) % (biggest - smallest) + smallest));
  229.  
  230. const target = moment("2022-01-01T23:00") + 86400000;
  231.  
  232.  
  233. const sleepChart = {
  234.   type: 'bar',
  235.   data: {
  236.     labels: rows.map(x => x[0]),
  237.     datasets: [{
  238.       label: 'Schlaf',
  239.       data: Array.from(rows.map((x, i) => {
  240.           var tempawoke = awoke[i];
  241.           var tempwent = went[i];
  242.  
  243.           if (went[i] <= biggest)
  244.           {
  245.             tempawoke += 86400000; tempwent += 86400000;
  246.           }
  247.           if (went[i] < awoke[i]) { tempawoke -= 0; tempwent += 86400000; }
  248.           tempawoke += 86400000;
  249.           return [tempawoke, tempwent]
  250.       })),
  251.       backgroundColor: ['rgba(100, 50, 255, 0.4)'],
  252.       borderColor: ['rgba(100, 50, 255, 1)'],
  253.       borderWidth: 2,
  254.       borderSkipped: false
  255.     }, {
  256.       type: 'line',
  257.       label: 'Ziel',
  258.       data: Array(awoke.length).fill(target),
  259.       backgroundColor: ['rgba(255, 99, 132, 0.4)'],
  260.       borderColor: ['rgba(255, 99, 132, 0.4)'],
  261.       borderWidth: 2,
  262.       borderSkipped: false
  263.     }],
  264.   },
  265.   options: {
  266.     scales: {
  267.       y: {
  268.         type: 'time',
  269.         time: {
  270.           unit: 'hour',
  271.           displayFormats: {
  272.             hour: 'HH:mm'
  273.           }
  274.         },
  275.        
  276.         min: smallest + 86400000 * 1.5,
  277.         max: smallest + 86400000 * 2.5
  278.       },
  279.     },
  280.     plugins: {
  281.       tooltip: {
  282.         callbacks: {
  283.             label: function (tti) {
  284.                 var val = JSON.parse(tti.formattedValue);
  285.                 var diff = (val[1] - val[0]);
  286.                 if (diff < 0) diff = val[0] - val[1]
  287.                 var hours = Math.floor(diff / 3.6e6);
  288.                 var minutes = Math.floor((diff % 3.6e6) / 6e4);
  289.                 return [moment(val[1]).format("HH:mm") + " - " + moment(val[0]).format("HH:mm"), "Slept:" + String(hours).padStart(2, '0') + ":" + String(minutes).padStart(2, '0')];
  290.           }
  291.         }
  292.       }
  293.     }
  294.   }
  295. }
  296.  
  297. window.renderChart(sleepChart, this.container);
  298. ```
  299.  
  300. ```dataviewjs
  301.     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');
  302. const rows = rawData.value.values;
  303.  
  304. const chartWidth = "100%";
  305.  
  306. const target = 420;
  307.  
  308. const chartData = {
  309.     width: chartWidth,
  310.     data: {
  311.         labels: rows.map(x => x[0]),
  312.         datasets: [
  313.             {
  314.             type: 'bar',
  315.             label: 'Qualität',
  316.             data: rows.map(x => x[2]),
  317.             backgroundColor: ['rgba(153, 153, 153, 0.4)'],
  318.             borderColor: ['rgba(153, 153, 153, 1)'],
  319.             borderWidth: 2,
  320.             borderSkipped: false,
  321.             fill: false,
  322.             stepped: false,
  323.             yAxisID: 'y2',
  324.             },  
  325.             {
  326.             type: 'bar',
  327.             label: 'Dauer',
  328.             data: rows.map(x => x[1]),
  329.             backgroundColor: ['rgba(100, 50, 255, 0.4)'],
  330.             borderColor: ['rgba(100, 50, 255, 1)'],
  331.             borderWidth: 2,
  332.             borderSkipped: false,
  333.             fill: false,
  334.             stepped: false,
  335.             yAxisID: 'y1',
  336.             },
  337.             {
  338.               type: 'line',
  339.               label: 'Ziel',
  340.               data: Array(rows.length).fill(target),
  341.               backgroundColor: ['rgba(255, 99, 132, 0.4)'],
  342.               borderColor: ['rgba(255, 99, 132, 0.4)'],
  343.               borderWidth: 2,
  344.               borderSkipped: false
  345.             }
  346.      
  347.         ],
  348.     },
  349.     options: {
  350.         plugins: {
  351.             legend: true,
  352.         },
  353.         scales: {
  354.             y1: {
  355.                 type: 'linear',
  356.                 display: true,
  357.                 position: 'left',
  358.             },
  359.             y2: {
  360.                 type: 'linear',
  361.                 display: true,
  362.                 position: 'right',
  363.             },
  364.         },
  365.     },
  366. }
  367.  
  368. window.renderChart(chartData, this.container);
  369. ```
  370.  
  371. ## Gehen
  372.  
  373. ### Schritte
  374.  
  375. ```dataviewjs
  376.     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');
  377. const rows = rawData.value.values;
  378.  
  379. const chartWidth = "100%";
  380.  
  381. const target = 4000;
  382.  
  383. const chartData = {
  384.     width: chartWidth,
  385.     data: {
  386.         labels: rows.map(x => x[0]),
  387.         datasets: [
  388.             {
  389.             type: 'bar',
  390.             label: 'Schritte',
  391.             data: rows.map(x => x[1]),
  392.             backgroundColor: ['rgba(100, 50, 255, 0.4)'],
  393.             borderColor: ['rgba(100, 50, 255, 1)'],
  394.             borderWidth: 2,
  395.             borderSkipped: false,
  396.             fill: false,
  397.             stepped: false,
  398.             },
  399.             {
  400.               type: 'line',
  401.               label: 'Ziel',
  402.               data: Array(rows.length).fill(target),
  403.               backgroundColor: ['rgba(255, 99, 132, 0.4)'],
  404.               borderColor: ['rgba(255, 99, 132, 0.4)'],
  405.               borderWidth: 2,
  406.               borderSkipped: false
  407.             },
  408.         ],
  409.     },
  410.     options: {
  411.         plugins: {
  412.             legend: true,
  413.         },
  414.         scales: {
  415.             y1: {
  416.                 type: 'linear',
  417.                 display: true,
  418.                 position: 'left',
  419.             },
  420.         },
  421.     },
  422. }
  423.  
  424. window.renderChart(chartData, this.container);
  425. ```
  426.  
  427. ### Sport Übersicht
  428.  
  429. ```dataview
  430. TABLE WITHOUT ID
  431.     round(sum(rows.G.distanz),2) AS "∑ km",
  432.     round(sum(rows.G.dauer)) AS "∑ Zeit",
  433.     round(sum(rows.G.distanz)/length(rows), 2) AS "∅ km",
  434.     round(sum(rows.G.dauer)/length(rows)) AS "∅ Zeit",
  435.     round(sum(rows.G.geschwindigkeit)/length(rows), 1) AS "∅ km/h",
  436.     round(max(rows.G.puls-max)) AS "max Puls",
  437.     round(sum(rows.G.hf-schnitt)/length(rows)) AS "∅ HF"
  438. FROM "10 - Daily Notes"
  439. WHERE sport
  440. AND (contains(sport.type, "Gehen")
  441. OR contains(sport.type, "Laufen"))
  442. AND date(file.day).weekyear  = this.week
  443. AND date(file.day).year = this.year
  444. FLATTEN sport.gehen AS G
  445. GROUP BY true
  446. ```
  447.  
  448. ### Sport Details
  449.  
  450. ``` dataview
  451. TABLE WITHOUT ID
  452.     link(file.name) AS "Datum",
  453.     sport.type AS "Aktivität",
  454.     round(G.distanz,1) AS "km",
  455.     round(G.dauer) AS "Minuten",
  456.     round(G.geschwindigkeit,1) AS "km/h",
  457.     round(G.puls-max) as "max. Puls",
  458.     round(G.hf-schnitt) as "∅ HF"
  459. FROM "10 - Daily Notes"
  460. WHERE sport
  461. AND (contains(sport.type, "Gehen")
  462. OR contains(sport.type, "Laufen"))
  463. AND date(file.day).weekyear  = this.week
  464. AND date(file.day).year = this.year
  465. FLATTEN sport.gehen AS G
  466. SORT file.name DESC
  467. ```
Add Comment
Please, Sign In to add comment