I use Dataview to track activity time, in this case work out time.
For example, an inline field such as:
WorkoutDuration:: 60 min
I use DataviewJS to display a table of workouts for the last 7 days and sum the workout durations for the time period and display the result. See the table and result below for total duration.
Note that the sum of “total workout duration” is incorrect. If I remove the “min” label in the inline fields, the result will be correct, 395 minutes in the case below. However, I would like to leave the “min” label for convenience of display in other tables.
The Dataview array containing the data type “duration” is acted upon by the “reduce” method to produce the “total workout duration” result. Using this method on an array with durations rather than numbers seems to be the issue, but at this point I am out of my depth. I played with converting between dataview and js arrays as mentioned in the Dataview documentation, thinking I might change the array from “durations” to “numbers”, if that makes sense, but this just caused errors.
The code and result are shown below. Any insights are appreciated.
dv.table(["Date", "Workout", "Duration"], dv.pages('"Daily Notes/2022"')
.sort(k => k.file.link, "desc")
.slice(0,7)
.map(b => [b.file.link, b.WorkoutLog, b.WorkoutDuration]))
dv.paragraph("total workout duration " + dv.pages('"Daily Notes/2022"').WorkoutDuration.array().sort(k => k.link, "desc").slice(0,7).reduce((acc, val) => acc + val, 0).toFixed(2))