Skip to content

Instantly share code, notes, and snippets.

@benwaffle
Created November 14, 2018 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benwaffle/59f8a06df01c806321b6b8f47fd4981f to your computer and use it in GitHub Desktop.
Save benwaffle/59f8a06df01c806321b6b8f47fd4981f to your computer and use it in GitHub Desktop.
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