blob: b608483af2ad515cd2577774721e0029d79eef28 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
const files = [
// "gun_violence",
"mass_shootings_from_columbine",
"gun_violence_by_month",
"firearms_manufactured",
]
const parse = require('csv-parse')
const dataPromises = files.map(name => {
return fetch('./data/' + name + '.csv').then(rows => {
return rows.text()
}).then(text => {
return new Promise((resolve, reject) => {
parse(text, {}, (_, lines) => resolve(lines))
})
}).then(lines => {
// console.log(name, lines)
const h = lines.shift()
return {
name,
h,
lines: lines.filter(s => !!s)
}
})
})
const allPromises = Promise.all(dataPromises).then(data => {
return data.reduce((a,b) => {
// console.log(b)
a[b.name] = b
return a
}, {})
})
const load = () => {
return allPromises
}
export { load }
|