February 09, 2021 Stardate: 74575.1 Tagged as: Arbtt Python
I’m applying for a graduate program and in the meantime, while my application is being considered, I’ve started building out my LaTeX thesis template and workflow. I know it’s premature but I haven’t played with LaTeX since writing my Master’s Thesis nearly 15 years ago and wanted to reacquaint myself. After a couple of days, I was thinking to myself, “man, after the end of this I’m going to have a bunch of hours racked up.” So that thought experiment led me to look at time tracking software.
The one I thought was the “best” was arbtt, automated, rule-based time tracker.
Installation was very easy.
sudo apt update
sudo apt-get install arbtt
Tell Ubuntu to start the daemon automatically on system start
cp /usr/share/doc/arbtt/examples/arbtt-capture.desktop ~/.config/autostart/
Go ahead and manually start the daemon
(arbtt-capture &)
And create your categorize.cfg file
~/.arbtt/categorize.cfg
That’s it
This is where the magic is. arbtt
tracks X properties like window title, class, and running programs, and you write rules to classify those strings. You can get as detailed as you want. For example, you can say “If Firefox is the active window (i.e. mouse or keyboard is working within it) and the title of the tab contains the word Twitter, than label all that accumulated time as Web_Twitter”. Something like that. Then you can apply regular expressions and complicated logic to figure out exactly what you want.
For a start, here are my “rules” in the categorization.cfg
file.
-- A rule that probably everybody wants. Being inactive for over a minute
-- causes this sample to be ignored by default.
$idle > 60 ==> tag inactive,
-- Simple rule that just tags the current program
--tag Program:$current.program,
--tag Title:$current.title,
-- PYTHON
$program == ["Spyder"] ==> tag python,
current window
-- THESIS
$program == "evince" &&
( current window $title =~ /dissertation/ ) ==> tag thesis,
current window
$program == ["code"] ==> tag thesis,
current window
$program =~ /install4j/ ||
( current window $title =~ /yEd/ ) ==> tag thesis,
current window
-- WEB BROWSER
$title =~ [/LinkedIn/, /Twitter/] ==> tag Web:socialmedia,
current window
$program == "Navigator" &&
current window !(current window $title =~ [/LinkedIn/, /Twitter/]) ==> tag Web:web_browsing,
I’m basically tracking three things; how much time I’m coding Python, working on my thesis, and wasting on social media. I was able to do this by just looking at the example file and trial-and-error. Then I can view the results:
joe@Praimfaya:~$ arbtt-stats
Processing data [================================================================================] 100%
Total time per tag
==================_____________Tag_|______Time_|_Percentage_
Web:web_browsing | 1h33m00s | 27.43
python | 45m00s | 13.27
thesis | 12m00s | 3.54
Web:socialmedia | 7m00s | 2.06
Cool!
Of course, I will take it too far. There is an add-on names arbtt-graph that will take the data collected and serve a webpage with it all graphed out. Installation consisted of cloning the github repo and configuring the scripts. The workflow is to run the update
bash script which dumps the arbtt-stats data into .csv
files and then runs a python script to process the data and manipulate it into a json
file. Then you run a python script that simply initiates a web server to display the html files from the “render” folder.
I ran into two problems that needed to be fixed.
timestats.sh
and update would get ran, a server is started on localhost, and a firefox tab is opened to the right page. The problem was all the files in arbtt-graph used relative paths so if I called from a random terminal directory it would barf again. I fixed by going into both python and bash scripts and changing to a absolute paths. This needs to be cleaned up and changed to directory variables because any change to the location and everything is screwed up again. But I was glad everything (arbtt-stats and -graph) was working so I left it alone.Here’s what it looks like with my nominal setup.