Need help to Modify Dataviewjs table for Readwise

What I’m trying to do

I am using the Readwise plugin to import all my highlights. I have tagged each note with a property to implement Tiago Forte’s progressive summarization process. You don’t need to read the article, but wanted to include a link to it for anyone who might be interested in what I’m referring to.

I have some dataviewjs code to surface a random note from all the notes in my Readwise folder.

let docs = dv.pages('"Readwise"');
var randos = (docs) => {return docs.sort(() => .5 - Math.random()).slice(0,10);}

dv.table(["Note", "Date Modified", "Progress"], randos(docs)
  .sort(k => k.summary_progress, 'asc')
  .map(d => [d.file.link, d.file.mday, d.summary_progress] ))	

I want to limit the randomization to just one of the Progress types. The code I’m using is L1, L2, etc.

I’ll be incorporating this query in a MOC that has each level separated out.

Things I have tried

I have:

  1. googled
  2. read documentation
  3. Searched forum
  4. trial and error

UPDATE:

I was able to update the code to randomize on a specific property in a specified folder.

let docs = dv.pages('"5 - Readwise"').filter(doc => doc.summary_progress === 'L1_Notes');
var randos = (docs) => {return docs.sort(() => .5 - Math.random()).slice(0,10);}

dv.table(["Note", "Date Modified", "Progress"], randos(docs)
  .sort(k => k.summary_progress, 'asc')
  .map(d => [d.file.link, moment(d.file.mday).format('MMM DD, YYYY'), d.summary_progress] ))

THE PART STILL NOT WORKING
I am unable to restrict the query to files with dates older than 15 days prior.

The goal is resurface older Readwise notes rather than do a long scroll.

This is the code I need help with.

let docs = dv.pages('"5 - Readwise"').filter(doc => doc.summary_progress === 'L1_Notes' && moment().diff(doc.mday, 'days') > 15);
var randos = (docs) => {return docs.sort(() => .5 - Math.random()).slice(0,10);}

dv.table(["Note", "Date Modified", "Progress"], randos(docs)
  .sort(k => k.summary_progress, 'asc')
  .map(d => [d.file.link, moment(d.file.mday).format('MMM DD, YYYY'), d.summary_progress] ))

This part just isn’t working: && moment().diff(doc.mday, 'days') > 10);

UPDATE 2:

After more trial and error, I found the following:

  1. In a regular dataview query it’s easier to target a property that is a string. But, I don’t know how to code that in my js query.
  2. When I changed the property of a test note from date modified to date_modified I got the result I’m looking for by targeting doc.date_modified.

The problem is I’m using templates. All my templates have date modified. And I’d really like to not have to manually change all of my 2-word properties. I’m already processing my notes and don’t want to loose what I’ve done to do a resync with Readwise and get duplicates.

Does obsidian have a find and replace function across a vault?

UPDATE 3

After much trial and error and testing, I think I have figured out the code.

  1. My property type is a string. (Which is what caused this long journey.)
  2. I can now target the string (which is a property type date) with the code below.
  3. I am also sorting on two columns. a) The level of the summarization process, b) the date the file has been modified.
  4. I am not using Obsidian’s default modification date because then this will never work. I use the Linter plugin to update the modified date on a manual save.

FINAL CODE

let docs = dv.pages('"5 - Readwise"').filter(doc => moment().diff(moment(doc["date modified"]), 'days') > 10);
var randos = (docs) => {return docs.sort(() => .5 - Math.random()).slice(0,10);}

dv.table(["Note", "Date Modified", "Progress"], randos(docs)
  .sort(k => k.summary_progress, 'asc')
  .sort(s => s.date_modified, 'asc')
  .map(d => [d.file.link, moment(d["date modified"]).format('MMM DD, YYYY'), d.summary_progress] ))

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.