Skip to content

Instantly share code, notes, and snippets.

@stuartf
Created July 13, 2016 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuartf/a8f14ef70813022ec758dba8b9a82df3 to your computer and use it in GitHub Desktop.
Save stuartf/a8f14ef70813022ec758dba8b9a82df3 to your computer and use it in GitHub Desktop.
var fs = require('fs');
var readline = require('readline');
var log = [];
// Set up to read the log line by line
var rd = readline.createInterface({
input: fs.createReadStream('./gtx-edx-events-2016-07-11.log'),
output: process.stdout,
terminal: false
});
// Parse each line as JSON
rd.on('line', function(line) {
log.push(JSON.parse(line));
});
// When we have all the lines parsed we can start querying them
rd.on('close', function() {
var matches = 0;
// Check each line for matches
for(var i = 0; i < log.length; i++) {
// Particular user pauses a video
if (log[i].username === 'malekmalke' && log[i].event_type === 'pause_video') {
matches++;
}
}
console.log(matches);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment