summaryrefslogtreecommitdiff
path: root/client/data.js
blob: d48ccaab3ccbc7e66a94e917b7e7cafb61a1825d (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
const files = [
  // "gun_violence",
  "mass_shootings",
  "gun_violence_by_month",
]
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 }