Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.