Created
December 23, 2014 11:03
-
-
Save kotarou3/1d37dce7682a992946e1 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env nodejs | |
var x = []; | |
var y = []; | |
var buffer = ""; | |
require("child_process").spawn("evemu-record", {stdio: [process.stdin, "pipe", process.stderr]}).stdout.on("data", function (data) { | |
buffer += data.toString(); | |
if (buffer.indexOf("\n") >= 0) { | |
var lines = buffer.split("\n"); | |
buffer = lines.pop(); | |
for (var l = 0; l < lines.length; ++l) { | |
var match = lines[l].match(/ ABS_([XY]) +([0-9]+)$/); | |
if (!match) | |
continue; | |
if (match[1] === "X") | |
x.push(parseInt(match[2])); | |
else if (match[1] === "Y") | |
y.push(parseInt(match[2])); | |
} | |
} | |
}); | |
process.on("SIGINT", function () { | |
var avgX = x.reduce(function (avg, x, n) { return avg + (x - avg) / (n + 1); }, 0); | |
var avgY = y.reduce(function (avg, y, n) { return avg + (y - avg) / (n + 1); }, 0); | |
console.log("Counted:", x.length, y.length); | |
console.log("Average:", avgX, avgY); | |
console.log("Max:", Math.max.apply(Math, x), Math.max.apply(Math, y)); | |
console.log("Min:", Math.min.apply(Math, x), Math.min.apply(Math, y)); | |
process.exit(0); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment