redgoose.ca

Visualising Workrave data

If you've never heard of Workrave, it's an application that among other things helps prevent Repetitive Strain Injury (RSI) by prompting you to take mini breaks. When I first started using it I kept the breaks on, but slowly curtailed those (even though I know I really shouldn't!). Nothing worse than being in flow and getting interrupted to take a break!

That said, I did end up leaving Workrave running in the background for two reasons.

First, it logs your activity so you can determine when you started your day and based on that decide when to end it--very important! In lots of cases I've lost track of time at work and then turned to Workrave as a reminder.

Also, since Workrave is logging your activity (key clicks, mouse clicks, etc.) you can use it to view your stats for the day which is kinda neat.

Here's what the last 3 years of "work" at Kanetix looks like.


I used the following PHP code to parse the data I wanted out of the historystats log file generated by Workrave into a JSON object and used Flot to make a pretty chart.

public function parse_historystats(){
		$file = "historystats";
		$lines = file($file);

		$data = array(
			array(
				"label"	=> "mouse clicks",
				"data"	=> array()
			),
			array(
				"label"	=> "keystrokes",
				"data"	=> array()
			)
		);
		
		$time = "";
		
		foreach ($lines as $line_num => $line) {
			if (preg_match("/^D\s(\d+)\s(\d+)\s(\d+)/",$line,$m)) {
				// is a date line, parse date

				$day = $m[1];
				$month = $m[2] + 1;
				$year = $m[3] + 1900;
				
				$time = strtotime("$year-$month-$day UTC");
			} else if (preg_match("/^m.*?(\d+)\s(\d+)\s*$/",$line,$m)) {
				// is a stats line, parse stats
				
				$dow = date("w",$time);
				if ($dow == 0 || $dow == 6 || $m[1] == 0) {
					continue;
				}

				// mouse clicks
				array_push($data[0]["data"],array($time*1000,$m[1]));

				// key clicks
				array_push($data[1]["data"],array($time*1000,$m[2]));
			}
		}

		return json_encode($data);
	}

Comments

Thank you, your article helped me.

Eric Nitler - Thursday September 19, 2013

Say something






Textile Help

Hello

My name is Tariq. I am a twenty something website developer based in Toronto, Canada, working at kanetix doing what I love to do. Yeppers, I like turtles and get on (the TTC) daily.

Popular Posts

Subscribe

RSS Feed