Skip to content

Instantly share code, notes, and snippets.

@mcampa
Last active December 7, 2017 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mcampa/60b5d15fd3f9fbc9b51cc9389ce6f147 to your computer and use it in GitHub Desktop.
Save mcampa/60b5d15fd3f9fbc9b51cc9389ce6f147 to your computer and use it in GitHub Desktop.
cabana_fingerprint.js
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