Last active
December 7, 2017 16:00
-
-
Save mcampa/60b5d15fd3f9fbc9b51cc9389ce6f147 to your computer and use it in GitHub Desktop.
cabana_fingerprint.js
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
const fs = require('fs'); | |
const content = fs.readFileSync('./data.csv', 'utf8'); | |
const data = content.trim() | |
.split('\n') | |
.filter(l => l) | |
.map(l => l.split(',')) | |
.map(row => ({ time: row[0], id: row[1], bus: row[2], message: row[3] })) | |
const lengths = {}; | |
data.forEach(row => { | |
let length = row.message.replace(/0+$/, '').length; | |
if (length % 2 === 1) { | |
length++; | |
} | |
length = length / 2; | |
if (!lengths[row.id]) { | |
lengths[row.id] = 0; | |
} | |
if (length > lengths[row.id]) { | |
lengths[row.id] = length; | |
} | |
}); | |
let fingerprint = Object.keys(lengths).map(id => { | |
return `${id}L: ${lengths[id]}`; | |
}); | |
console.log(fingerprint.join(', ')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment