-
-
Save energee/1b8159e6acae991c79c4b26fe56f3e45 to your computer and use it in GitHub Desktop.
cabana fingerprint
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 messages = content | |
.split('\n') | |
.map(line => line.trim()) | |
.filter(line => line.length > 0 && line !== 'time,addr,bus,data') | |
.map(line => line.split(',')) | |
.map(msg => ({ | |
addr: parseInt(msg[1]), | |
bus: parseInt(msg[2]), | |
data: msg[3].replace(/0+$/, '') | |
})) | |
.filter(msg => msg.bus === 0); | |
const lengths = {}; | |
for (let msg of messages) { | |
const len = Math.ceil(msg.data.length / 2); | |
if (len === 0) { | |
continue; | |
} | |
lengths[msg.addr] = Math.max(lengths[msg.addr] || 0, len); | |
} | |
const fingerprint = Object.keys(lengths) | |
.map(key => key + ': ' + lengths[key]) | |
.join(', '); | |
console.log(fingerprint); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment