Created
July 13, 2016 15:33
-
-
Save stuartf/a8f14ef70813022ec758dba8b9a82df3 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
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