Dataview and/or other plugins for mood/sleep/dream tracking?

I have a lot of daily notes, and I use the Tracker plug-in to give me monthly views on sleep quality, my mood for the day, and a few other metrics/habits. For #sleep, I use values 1 to 5 to describe how well I slept the night before, like this:

#sleep:3

(No spaces.)

I also use a tag to describe any dreams I can remember. The #dream tag doesn’t have a value, but a daily note will either have that tag or not. If it has the tag, there’s also a description of the dream(s) in the same block of text.

Is it possible in Dataview (or anything else?) to query notes that have the #dream tag and group them by the value next to the #sleep tag, so I can see possible interactions between sleep quality and the kinds of dreams I have?

I started looking at Dataview but saw that there’s metadata to add, etc. Since I have a lot of notes, I don’t want to go back and do that. But maybe my scenario is simple enough that I don’t need to?

(I also have a #mood tag with a value to describe my mood for the day. I’d like to work that in as well, but the mood value is actually on the note for the day before, so I need to figure out how to bring it forward or reference it as something like #yesterdaymood: in today’s daily note. Maybe I can’t avoid doing that manually on all of my archived notes, but I’d love ideas on how to automate that through the daily note template moving forward.)

I have some ideas on journalling and tracking here, which may be useful to you. Unfortunately both my ideas aren’t working properly yet. But the concept of using inline dataview fields might help you - it might be a bit more specific compared with using #sleep tags.

I generally use tags to tell me what type of note it is (#journal/daily, #task, #type/podcast/ep, #type/article). Then I can use dataview to select FROM these tags (e.g. from all daily journals, podcast episodes. And call up the relevant field sleep:: 3.

But perhaps you are already ahead of me in this sense! Good luck!

DataView can definitely do something like this.

You could have a single page that as the DataView code and have it pull all that data for you. By default, it uses the front-matter data but you can add some JavaScript that’ll do it for you instead.

I’ll poke around in my Vault and see if I can’t get something working and post it back here.

Okay, I poked around for a bit and it looks like DV doesn’t handle semi-colons in the tag name. If your tag was something like #sleep/3, then the following script would work well.

I tried it with #sleep:3 and it would only pick up the sleep portion of the tag :confused:

const pages = dv.pages()
const tags = {}
const tagsArr = []

for (const page of pages) {
  if (page.tags) {
    for (const tag of page.tags) {
      const existing = tags[tag]
      if (existing) {
        tags[tag].count++
      } else tags[tag] = { name: tag, count: 1 }
    }
  }
}

for (const key of Object.keys(tags)) {
  tagsArr.push([tags[key].name, tags[key].count])
}

dv.table(['Name', 'Count'], tagsArr)

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