Created
January 24, 2024 15:00
-
-
Save WebInspectInc/27b5bf5c82feb461970651a4fc9cecda to your computer and use it in GitHub Desktop.
Summarizing books read with DataviewJS in Obsidian
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```dataviewjs | |
const query = 'outgoing([[]]) AND #books'; | |
const total = | |
dv | |
.pages(query) | |
.filter(item => item | |
.hasOwnProperty('pages')) | |
.values | |
.reduce((sum, item) => sum + item.pages, 0); | |
const booknum = dv.pages(query).length; | |
let rating = | |
dv | |
.pages(query) | |
.filter(item => item | |
.hasOwnProperty('rating')) | |
.values | |
.reduce((sum, item) => sum + item.rating, 0); | |
rating = (rating / booknum).toFixed(2); | |
dv.paragraph(`Number of books: ${booknum}`); | |
dv.paragraph(`Average rating: ${rating}`); | |
dv.paragraph(`Total pages read: ${total}`); | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I include this script in a note titled "Books read in YYYY", and I link to any book that I completed reading in said year.
Each book note includes a #books tag, and at least two properties: rating (0-5) and pages. This script will then output something like: