|
// This file will parse testPilot's heatmap data and extract the occurances |
|
// of the different types of error messages. |
|
// For example: "Server not found", "Connection reset", "Untrusted connection", etc |
|
|
|
// The results will be outputted to the file specified in OUTPUT_FILE. |
|
// NOTE: This will not aggregate error messages in different locales. |
|
// For example, "Server not found" and "Servidor no encontrado" will be two different errors. |
|
|
|
const FILE = "testpilot_heatmap17_10.json"; |
|
const NETERROR_EVENT_NAME = "404 page"; |
|
const OUTPUT_FILE = "output.json"; |
|
|
|
var fs = require('fs'), |
|
readline = require('readline'); |
|
|
|
var rd = readline.createInterface({ |
|
input: fs.createReadStream(FILE), |
|
output: process.stdout, |
|
terminal: false |
|
}); |
|
|
|
var netErrors = {}; |
|
var readOnce = false; |
|
|
|
rd.on('line', function(line) { |
|
var userData = convertDataLineToObject(line); |
|
userData && userData.events.forEach(function(event){ |
|
// Example of representation of an event: |
|
// [1, "404 page", "The connection was reset", "pageload", 1355916017671] |
|
|
|
if(event[1] == NETERROR_EVENT_NAME) { |
|
netErrors[event[2]] = netErrors[event[2]] ? netErrors[event[2]] + 1 : 1; |
|
} |
|
}); |
|
}); |
|
|
|
rd.on('close', function(){ |
|
var jsonString = JSON.stringify(netErrors, null, "\t"); |
|
fs.writeFile(OUTPUT_FILE, jsonString, function(err) { |
|
if(err) { |
|
console.log(err); |
|
} else { |
|
console.log("The file was saved to " + OUTPUT_FILE); |
|
} |
|
}); |
|
}); |
|
|
|
var convertDataLineToObject = function(line) { |
|
// Each line of our data file consists of a GUID and a JSON string represting the user's data. |
|
// These are delimetered by a tab. |
|
// For example: <guid> <json> |
|
// We will need to remove the GUID in order to convert the JSON string into an object. |
|
|
|
var firstCurly = line.indexOf("{"); |
|
if(firstCurly < 0) { |
|
return null; |
|
} |
|
|
|
var jsonString = line.slice(firstCurly); |
|
var obj = JSON.parse(jsonString); |
|
|
|
return obj; |
|
} |