Advertisement
dhniceday

Untitled

Nov 24th, 2022
725
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.22 KB | Software | 0 0
  1. ```dataviewjs
  2.  
  3. // - sum of all evergreen notes
  4. const qrySum = await dv.query(`
  5. TABLE WITHOUT ID
  6.     length(rows.file.link) as L
  7. FROM #evergreen
  8. FLATTEN L
  9. GROUP BY true                      
  10. `)
  11.  
  12. const sum = qrySum.value.values;
  13.  
  14. // - get sum of evergreen notes by topic
  15. const qryList = await dv.query(`
  16. TABLE  length(rows.file.link) as Count
  17. FROM #evergreen
  18. GROUP BY topic as Topic
  19. SORT topic
  20. `)
  21.  
  22. // - calculate percentage for each topic
  23.  
  24. // headers
  25. qryList.value.headers.push("Percentage")
  26. qryList.value.headers.push("Graphical")
  27.  
  28. for (let r of qryList.value.values) {
  29.  
  30.     // Percentage
  31.     let percentOfQty = Math.round(r[1] * 100 / sum * 10) / 10
  32.     percentOfQty = percentOfQty.toFixed(1)
  33.     r.push(percentOfQty);  
  34.  
  35.     // Progress
  36.     let progressBar = '<progress value="' + percentOfQty + '" max="100"></progress>'
  37.     r.push(progressBar);
  38. };
  39.  
  40. removeColumn('Count');
  41. removeColumn('Percentage')
  42.  
  43. dv.table(qryList.value.headers, qryList.value.values)
  44.  
  45. /* -------------------------------------- */
  46.  
  47. function removeColumn(col) {
  48.     const index = qryList.value.headers.indexOf(col);
  49.     if (index > -1) {
  50.         qryList.value.headers.splice(index, 1);
  51.        
  52.         for (let r of qryList.value.values) {
  53.             r.splice(index, 1)
  54.         }
  55.     }
  56. }
  57. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement