I’m coming from org-roam and the only thing I’m really missing is tracking my work hours. My current idea is the following:
In my daily notes I would create something along the lines of…
Then build a dataview/tracker query the fetches these time ranges and sums up my hours.
As I’m not familiar with JS/yaml, I’m struggling to understand the datatypes that are allowed in this frontmatter thingy. How would date ranges look like?
What I’m trying to do
In org-roam I can clock in and clock out of every headline/task. Using the tags on these headlines I can then build a time sheet (my todos have the top level tag #work and then split into projects). Example:
** TODO Example Task :work:
:LOGBOOK:
CLOCK: [2022-11-01 Tue 00:12]--[2022-11-01 Tue 00:22] => 0:10
:END:
I suggest a mix of DQL and DVJS (an alternative way for js dumbs like me):
// query for values per file
const query = `TABLE WITHOUT ID key AS "Day", rows.Time AS "work time", sum(rows.Time) as "total by day"
FROM #Daily
WHERE work
FLATTEN work AS W
FLATTEN date(split(W, " -- ")[1]) - date(split(W, " -- ")[0]) AS Time
GROUP BY file.link`
// executing the query and return results
let DQL = await dv.tryQuery(query);
// divider line
const hrArray = Array(3).fill('<hr style="padding:0; margin:0 -10px; border-top: 1px solid var(--background-modifier-border)">');
// query for global total
const query2 = `TABLE WITHOUT ID "**TOTAL**", " ", "**" + sum(rows.TT) + "**"
FROM #Daily
WHERE work
FLATTEN work AS W
FLATTEN date(split(W, " -- ")[1]) - date(split(W, " -- ")[0]) AS Time
GROUP BY file.link
FLATTEN rows.Time as TT
GROUP BY true`
// executing the global query and return results
let DQLglobal = await dv.tryQuery(query2);
// add lines and global values for the first query
DQL.values.push(hrArray)
DQL.values.push(DQLglobal.values.flatMap(r => r))
DQL.values.push(hrArray)
// render the final table
dv.table(DQL.headers, DQL.values);
// hide count number in first column
this.container.querySelectorAll(".table-view-table tr:first-of-type th:first-of-type > span.small-text")[0].style.visibility = "hidden";
Would you mind sharing that templater template? Additionally, does that mean you always have to navigate to the daily note before inserting the time? (would be neat to do it with a small overlay from anywhere)
I think it would be super valuable if you could write this up/make a quick video about it. I think I can make it work with the 2 questions above, but from what I’ve found googling, there isn’t really anything out there… So would be very helpful for beginners
I do it from the daily note because that’s where I work from. But it would be 100% doable to write a Templater script the modifies the current daily note from a popup prompt, rather than having to open the note.
Additionally, does that mean you always have to navigate to the daily note before inserting the time? (would be neat to do it with a small overlay from anywhere)
To automate this from anywhere in Obsidian, look at QuickAdd plugin, specifically its Capture functionality. You can use it to set up macro commands that you can fire up by pressing CTRL+P → your command, and it allows you to insert any text anywhere into any note, among other things. This Youtube tutorial by the plugin’s author goes into much more detail. You can then combine it with Dataview or anything else, really.
It’s a bit of a rabbit hole, but you can make very quick and powerful commands with this.