This is a script made to work nodejs. It requires node-canvas. It uses data from minute-agent
Created
October 25, 2012 20:30
-
-
Save tmcw/3955198 to your computer and use it in GitHub Desktop.
Simpler, Faster Minute Visualization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Canvas = require('canvas'), | |
fs = require('fs'); | |
var keystrokes = fs.readFileSync('../keystrokes_all.log', 'utf8'); | |
var lines = keystrokes.split('\n').slice(1); | |
var width = 1024 * 2, height = 768 * 2; | |
var c = new Canvas(width, height); | |
var ctx = c.getContext('2d'); | |
ctx.fillStyle = '#000'; | |
ctx.fillRect(0, 0, width, height); | |
var gaps = {}; | |
var days = []; | |
function secs(d) { | |
return (d.getHours() * 60 * 60) + | |
(d.getMinutes() * 60) + | |
(d.getSeconds()); | |
} | |
function stamp(d) { | |
return d.getDate() + ',' + d.getMonth() + '-' + d.getYear(); | |
} | |
var days = {}; | |
for (var i = 0; i < lines.length; i++) { | |
var t = new Date(+lines[i].split(',')[0] * 1000); | |
var v = +lines[i].split(',')[1]; | |
var s = stamp(t); | |
if (!days[s]) days[s] = []; | |
days[s].push([secs(t), v]); | |
} | |
var full = (60 * 60 * 24); | |
function sy(x) { | |
return Math.floor((x / full) * height); | |
} | |
var ndays = Object.keys(days).length; | |
function sx(x) { | |
return (x / ndays) * width; | |
} | |
var wid = 5; | |
var scale = ['#111', | |
'#223', | |
'#336', | |
'#45a', | |
'#76e', | |
'#99f', | |
'#fcf', | |
'#faf']; | |
var dayn = 0; | |
for (var d in days) { | |
var day = days[d]; | |
for (var t = 0; t < day.length; t++) { | |
var v = day[t][1]; | |
var sv = Math.max(0, Math.min(Math.sqrt(v) /5, 6)); | |
ctx.fillStyle = scale[sv]; | |
ctx.fillRect(~~sx(dayn), ~~sy(day[t][0]), wid, 1); | |
} | |
dayn++; | |
} | |
fs.writeFileSync('basically.png', c.toBuffer()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment