summaryrefslogtreecommitdiff
path: root/client/data.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2019-08-05 02:06:29 +0200
committerJules Laplace <julescarbon@gmail.com>2019-08-05 02:06:29 +0200
commit626c348af622b9bb66000d1a49dbe007131649ef (patch)
tree59127e1e69a209c1f0823050c17979cd5253d312 /client/data.js
sonifications
Diffstat (limited to 'client/data.js')
-rw-r--r--client/data.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/client/data.js b/client/data.js
new file mode 100644
index 0000000..855da4a
--- /dev/null
+++ b/client/data.js
@@ -0,0 +1,37 @@
+const files = [
+ // "gun_violence",
+ "mass_shootings_from_columbine",
+ "firearms_manufactured",
+ "ar_15_2016_18",
+]
+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 }