Beeminding time spent reviewing Anki cards

At one point I wanted to Beemind total time spent reviewing Anki cards, which IIRC isn’t something that the integration supports. The Anki app shows the time spent today, so I knew that information was already in there, but

  • I sometimes forgot to enter data on a given day, and there wasn’t an obvious way to see how much time I’d spent on it in a past day

  • If I remembered to enter data during a day, I might review more cards later, so the datapoint would need to be updated - inconvenient

  • This also pushed me towards doing the data entry later which made me more likely to forget entirely

So I looked into how Anki comes up with that number for time spent, and wound up building this script:


sqlite3 ~/Library/Application\ Support/Anki2/User\ 1/collection.anki2 -column "SELECT ROUND(CAST(SUM(time) AS FLOAT)/3600000, 2), date(id / 1000, 'unixepoch') as date FROM revlog WHERE date > '2025-04-02' GROUP BY date ORDER BY date;" | sed -r 's/([0-9\.]+) +([0-9]+)-([0-9]+)-([0-9]+)/\2 \3 \4 \1 \"anki\"/'

The 2025-04-02 there is the start date; when I run this, I replace that with the date I last ran it, so as to not duplicate data points from last time. The rest of the sql code is basically totalling up card review times for each day, and the sed command transforms the output into a format that I can paste into the ‘Advanced Entry’ on the Beeminder website.

Edit: it’s giving times in fractions of an hour because that’s how I set up the goal (for reasons outside the scope of this post); if you want a number in minutes, you can of course just change the divisor.

Obviously this is still partly manual and could be automated or streamlined further, but it lets me enter data for a bunch of days in one go, so I think I’ve pretty much picked the low handing fruit here

…and despite having searched the forum for a way to do this before building my own, it was only afterward that I found this post, which might just be entirely better than what I came up with, but I’m posting here anyway just on the off chance someone finds it useful.

5 Likes

That’s great! Thank you for sharing.

If you change your goal to custom with an aggregation method of ‘max’, then you can not worry about creating duplicate datapoints, or about studying more cards after having made the entries.

If you’re confident that you’ll run this at least every few days, then you could replace the hardcoded date with DATE('now', '-7 day') to get the last week’s worth of figures.

1 Like

Those are some good ideas.
I don’t think they fit my use case (it’s actually going into a goal that’s counting time spent on several related activities, and I enter some of the others manually) but for anyone Beeminding specifically Anki time in the future the aggregation method of ‘max’ sounds more convenient.

I had considered setting up a script to pipe the results from this into that Beeminder CLI someone made, and then having a cron job run that, but currently I do it on no fixed schedule.

1 Like