Created
November 14, 2018 01:59
-
-
Save benwaffle/59f8a06df01c806321b6b8f47fd4981f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 assert = require('assert') | |
const process = require('process') | |
const files = fs.readdirSync('.').filter(x => x.endsWith('.csv')) | |
const text = files.map(f => fs.readFileSync(f).toString()) | |
const events = [].concat(...text.map(content => content.split('\r\n').slice(6, -1).map(x => x.split(',')))) | |
const EMAIL = 2 | |
const NAME = 5 | |
const CWID = 8 | |
const cwid2email = {} | |
const email2cwid = {} | |
events.map(line => { | |
if (line[CWID] === '""') | |
return | |
if (cwid2email[line[CWID]]) | |
assert(cwid2email[line[CWID]] == line[EMAIL]) | |
else | |
cwid2email[line[CWID]] = line[EMAIL] | |
}) | |
events.map(line => { | |
if (line[EMAIL] === '""') | |
return | |
if (email2cwid[line[EMAIL]]) | |
assert(email2cwid[line[EMAIL]] == line[CWID]) | |
else | |
email2cwid[line[EMAIL]] = line[CWID] | |
}) | |
// console.log(cwid2email) | |
// console.log(email2cwid) | |
const attended = {} | |
events.forEach(line => { | |
let id = line[CWID] | |
if (id === '""') { | |
id = email2cwid[line[EMAIL]] | |
} | |
if (id === '""') { | |
if (line[EMAIL] !== '""') | |
id = line[EMAIL] | |
else { | |
console.log('bad', line) | |
return; | |
} | |
} | |
if (attended[id]) | |
attended[id]++ | |
else | |
attended[id] = 1; | |
}) | |
const voters = Object.entries(attended).filter(([key, value]) => value >= files.length/2) | |
console.log(voters.map(([id, count]) => [cwid2email[id] || id, count])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment