summaryrefslogtreecommitdiff
path: root/client/data.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/data.js')
-rw-r--r--client/data.js22
1 files changed, 14 insertions, 8 deletions
diff --git a/client/data.js b/client/data.js
index 4eab9d3..733d3bf 100644
--- a/client/data.js
+++ b/client/data.js
@@ -1,26 +1,32 @@
const files = [
- "housing-costs-and-income-inequality",
- "income-inequality-over-time",
- "shares-of-wealth",
- "weekly-earnings",
- "household-wealth",
+ // "gun_violence",
+ "mass_shootings",
]
+const parse = require('csv-parse')
const dataPromises = files.map(name => {
return fetch('./data/' + name + '.csv').then(rows => {
return rows.text()
}).then(text => {
- let lines = text.split('\n').map(line => line.split(','))
+ return new Promise((resolve, reject) => {
+ parse(text, {}, (err, lines) => resolve(lines))
+ })
+ }).then(lines => {
+ console.log(name, lines)
const h = lines.shift()
return {
- name: name.replace(/-/g, ' '),
+ name: name.replace(/_/g, ' '),
h,
lines: lines.filter(s => !!s)
}
})
})
const allPromises = Promise.all(dataPromises).then(data => {
- return data.reduce((a,b) => { a[b.name.replace(/-/g, '_')] = b; return a }, {})
+ return data.reduce((a,b) => {
+ console.log(b)
+ a[b.name.replace(/-/g, '_')] = b
+ return a
+ }, {})
})
const load = () => {
return allPromises