You are not logged in.

#1 2017-03-31 09:35:26

limpr
Member
Registered: 2015-10-08
Posts: 12

Monitoring (and possibly enhancing) productivity with Conky

As you can see in the screenshot, I’m not really into Conky.
conkyprod.png
No weather, no CPU temp, no music. Ignore the big number on top, it’s just a stopwatch. But the "Fleiss" progress bar below tells me wether I’ve been hacking or slacking. Yes, it shows a pretty accurate percentage of real work done at my two computers over the last week or so. Here’s how.
What I need: two scripts, one for gathering data, one for processing data, and Conky. Optional: Screen Message (sm) for extra effect.
First, let’s gather data about how I spend my time. I translate books for a living, so almost all work happens between one PDF and one document in a word processor. If I name all my work files consistently, the title of the active window should echo this.

#!/bin/sh 

## Record the title of the active window with a timestamp and the name of the computer. 
ACTIVEWIN=$(xprop -id $(xprop -root _NET_ACTIVEWIN_WINDOW | cut -d ' ' -f 5) WM_NAME | cut -d '"' -f 2) 
echo $ACTIVEWIN | egrep "sm|VLC|Tux" || echo "$(date +%Y%m%d) $(date +%a) $(uname -n) $ACTIVEWIN" >> ~/Dropbox/conkyprod/conkyprodlog.txt 

## Limit logfile length to 1500 lines = limit tracked time to last 25 uptime hours. 
sed -i -e :a -e '$q;N;1501,$D;ba' ~/Dropbox/conkyprod/conkyprodlog.txt 

exit 

Note that some window titles don’t get recorded. sm is part of this setup, VLC means it’s a DVD evening, and Tux is for when my kids play Tuxpaint.
I’ll call this script conkyprodcount.sh and place it in my bin. In order to collect a big pile of recent window titles, conkyprodcount.sh needs to run every minute. So, I’ll

crontab -e

and add the following line at the end:

*/1 * * * *   export DISPLAY=:0 && /home/limpr/bin/conkyprodcount.sh >> /home/limpr/Dropbox/conkyprod/conkyproderr.txt 2>&1 

Starting now, my window title history is recorded minute by minute at /Dropbox/conkyprod/conkyprodlog.txt. When xprop throws an error, it gets logged in a separate file. All the logfiles are placed in my Dropbox folder, for easy syncing across my two computers.
Here’s the other script, ~/bin/conkyprod.sh

#!/bin/sh

## When called by Conky, this script reports the productivity percentage 
## (and takes measures accordingly).

## Count "productive" minutes and calculate the productivity percentage.
## Window titles of productive apps or files are specified in the following regex:
PRODTITLES="Scribus|Bowman|Trelby|Ding|Ersetzen|Foods"
PRODNUM=$(egrep -c $PRODTITLES ~/Dropbox/conkyprod/conkyprodlog.txt)
TOT=$(egrep -c "^2" ~/Dropbox/conkyprod/conkyprodlog.txt)
PRODPERC=$(awk "BEGIN { printf \"%.0f\n\", "$PRODNUM/$TOT*100" }")
ACTIVEWIN=$(xprop -id $(xprop -root _NET_ACTIVEWIN_WINDOW | cut -d ' ' -f 5) WM_NAME | cut -d '"' -f 2)

## Asskick option: Uncomment to close Firefox whenever
## productivity percentage lingers below a given value.
#if [ "$PRODPERC" -lt "40" ]; then
#      echo $ACTIVEWIN | egrep -v "Iceweasel" >> /dev/null || wmctrl -c iceweasel
#fi

## Nudge option: Uncomment to alert user whenever
## productivity percentage lingers below a given value
## and no work is being done.
## (sm needs to be #installed!)
#if [ "$PRODPERC" -lt "60" ]; then
#     CLOCK=$(date +%R)
#     echo $ACTIVEWIN | egrep $PRODTITLES >> /dev/null || sm -f "#eeaa33" -b "#000000" "$CLOCK
#$PRODPERC%"
#fi

## Report to Conky.
echo $PRODPERC

exit

Note the $PRODTITLES variable. It’s a regex and contains keywords for egrep to look for in in the recorded window titles.
Sidenote: In my case, the keywords are a mixture of recent project names („Bowman“), work-related apps („Trelby“) and themes („Foods“ for searching the USDA’s foods database). What about general online research? Well, since that should be kept short (I get paid by the page, not by time), I just don’t count it as productive.
Finally, I have to insert the progress bar into my conkyrc:

${execibar 480 conkyprod.sh}

This calls conkyprod.sh, turns its output into a bar and updates itself after 480 seconds (8 minutes). Note: execigraph or execigauge would’ve been fancier, but I couldn’t get them to run.
To sync across two computers, I just put all the scripts and logfiles into my Dropbox folder and redirect the paths.
That’s it. Obviously, lots of googling & copypasting were involved, but I swear I understood 95 percent of the code when I put it together about a year ago. Now, not so sure. Suggestions and other trouble welcome!
Does Conkyprod affect productivity? Well, it shatters any illusions you might have about your effort. This can be frustrating at times, and it can motivate. Of course, I can easily cheat the whole thing, but I never do so. Setting up your own accountability system makes sticking to it a matter of pride.
Next step: having the script tweet out my productivity percentage at random times...

Offline

#2 2017-03-31 17:50:17

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,028

Re: Monitoring (and possibly enhancing) productivity with Conky

@limpr

Ok everyone sing along:

I am not into conky and conky is not into me!

Conky is a love it or hate it application.

I love it, because I can get creative with it.  Being retired gives me the time to do so.

I do like what you've done with it though, which means you are into conky - a little, just doing something with it that isn't "common" and that makes your little conky "creative".

Therefore "two thumbs up"  big_smile


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#3 2017-03-31 18:34:03

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Monitoring (and possibly enhancing) productivity with Conky

limpr wrote:

As you can see in the screenshot, I’m not really into Conky.

here's a CLI solution:

#! /bin/bash
read input
printf "Fleiss: %02d" "$input"
echo -n "% "
tput rev
for ((i=0 ; i<"$input" ; i+=5 ))
do
    printf ' '
done
tput sgr0
printf '\n'

usage:

conkyprod.sh | scriptname

8)

i like your translations btw!

Offline

#4 2017-04-05 09:57:34

limpr
Member
Registered: 2015-10-08
Posts: 12

Re: Monitoring (and possibly enhancing) productivity with Conky

You guys are so nice! I hereby admit that I'm a bit into Conky.

Offline

Board footer

Powered by FluxBB