diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-11-23 19:33:41 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-11-23 19:33:41 +0100 |
| commit | 6fc8743f68648857ccef703bc4f2290b2cdac061 (patch) | |
| tree | 00b5b3afc0e0a2f2e808fe36c5cd4565b84d9310 /client/index.js | |
| parent | c1c058c662109696fda78b8512aebfd197974b5e (diff) | |
media sonification
Diffstat (limited to 'client/index.js')
| -rw-r--r-- | client/index.js | 78 |
1 files changed, 62 insertions, 16 deletions
diff --git a/client/index.js b/client/index.js index 13f3558..cfe5832 100644 --- a/client/index.js +++ b/client/index.js @@ -82,21 +82,37 @@ let datasets = {}, dataset = {}, bounds = {}, diff = [] let play_fn = play_sequence data.load().then(lists => { console.log(lists) + + let fmedia = lists.media + let mediaLines = [] + for (var i = 0; i < fmedia.lines.length; i++) { + mediaLines.push(fmedia.lines[i]) + // if ((i % 7) == 6) { + // mediaLines.push([i, 0, 0]) + // } + } + datasets['Media'] = {} + datasets['Media'].name = 'Media after Parkland' + datasets['Media'].play_fn = play_sequence + datasets['Media'].h = fmedia.h.slice(1, 5) + datasets['Media'].labels = mediaLines.map(l => l.slice(0, 1).map(n => (n/7).toFixed(1))) + datasets['Media'].lines = mediaLines.map(l => l.slice(1,3).map(n => Math.log10(n+1))) + datasets['Media'].onPick = () => { + nx.offset.value = -6 + nx.multiply.value = 20 + document.querySelector('#scale').value = '0' + scales.pick(0) + } + const ar15 = lists.ar_15_2016_18 datasets['AR-15 2016-18'] = {} datasets['AR-15 2016-18'].name = 'AR-15 (2016-18)' datasets['AR-15 2016-18'].pedal = true datasets['AR-15 2016-18'].play_fn = play_mass_shootings - // datasets['AR-15 2016-18'].lines = ar15.lines.map(l => { - const ar_lines = ar15.lines.map(l => { if (l[gv_fields.incident_characteristics].match('Shots Fired - No Injuries')) { return null } - // console.log(l[gv_fields.n_killed], l[gv_fields.n_injured]) - // if (l[gv_fields.n_killed] < 1) return null - // if (l[gv_fields.n_killed] < 2 && l[gv_fields.n_injured] < 2) return null - // return [l[gv_fields.n_killed], l[gv_fields.n_injured]].map(n => Math.log(Math.log(n+1)+1)) if (l[gv_fields.n_killed] + l[gv_fields.n_injured] < 4) return null const [y, m, d] = l[gv_fields.date].split('-') if (parseInt(y) > 2017) return null @@ -104,7 +120,7 @@ data.load().then(lists => { const mm = year_days_by_month[parseInt(m)] const dd = Math.floor(parseInt(d)) + 14 const date = Math.floor((yy + mm + dd) / 7) - console.log(date, y, m, d) + // console.log(date, y, m, d) let total = l[gv_fields.n_killed] + l[gv_fields.n_injured] if (l[gv_fields.n_killed] === 0) { total = - l[gv_fields.n_injured] @@ -117,17 +133,44 @@ data.load().then(lists => { l[gv_fields.n_injured], ] }).filter(n => !!n) - - // console.log(a) -// console.log(ar_lines) - // datasets['AR-15 2016-18'].data = datasets['AR-15 2016-18'].dates = ar_lines.map(a => a[0]) datasets['AR-15 2016-18'].dates.push(ar_lines.length) datasets['AR-15 2016-18'].lines = [ar_lines.map(a => a[1])] datasets['AR-15 2016-18'].labels = ar_lines.map(a => a[2]) - // datasets['AR-15 2016-18'].max_i = 3 * 12 + 4 - console.log(ar_lines.length) + const schools = lists.school_shootings + datasets['School Shootings 2016-18'] = {} + datasets['School Shootings 2016-18'].name = 'School Shootings (2016-18)' + datasets['School Shootings 2016-18'].pedal = true + datasets['School Shootings 2016-18'].play_fn = play_mass_shootings + const school_lines = schools.lines.map(l => { + if (l[gv_fields.incident_characteristics].match('Shots Fired - No Injuries')) { + return null + } + if (l[gv_fields.n_killed] + l[gv_fields.n_injured] < 4) return null + const [y, m, d] = l[gv_fields.date].split('-') + if (parseInt(y) > 2017) return null + const yy = (parseInt(y) - 2016) * 365 + const mm = year_days_by_month[parseInt(m)] + const dd = Math.floor(parseInt(d)) + 14 + const date = Math.floor((yy + mm + dd) / 7) + // console.log(date, y, m, d) + let total = l[gv_fields.n_killed] + l[gv_fields.n_injured] + if (l[gv_fields.n_killed] === 0) { + total = - l[gv_fields.n_injured] + } + return [ + date, + Math.log(Math.log(total + 10) + 1), + "** !!, $$, {} killed, [] injured".replace('**', l[gv_fields.date]).replace('!!', l[gv_fields.city_or_county]).replace('$$', l[gv_fields.state]).replace('{}', l[gv_fields.n_killed]).replace('[]', l[gv_fields.n_injured]), + l[gv_fields.n_killed], + l[gv_fields.n_injured], + ] + }).filter(n => !!n) + datasets['School Shootings 2016-18'].dates = school_lines.map(a => a[0]) + datasets['School Shootings 2016-18'].dates.push(school_lines.length) + datasets['School Shootings 2016-18'].lines = [school_lines.map(a => a[1])] + datasets['School Shootings 2016-18'].labels = school_lines.map(a => a[2]) const fm = lists.firearms_manufactured datasets['Firearms Manufactured'] = {} @@ -406,6 +449,9 @@ function pick_dataset(key){ diff = get_diff_bounds(bounds.rows) play_fn = dataset.play_fn max_i = dataset.max_i || (bounds.rows.length * bounds.rows[0].length) + if (dataset.onPick) { + dataset.onPick() + } } /* build and bind the UI */ @@ -522,13 +568,13 @@ function ready() { document.querySelector('.loading').classList.remove('loading') + document.querySelector('#scale').value = '14' + scales.pick(14) + const initial_dataset = decodeURIComponent(window.location.hash.substr(1)) || 'Mass Shootings' document.querySelector('#dataset').value = initial_dataset pick_dataset(initial_dataset) - document.querySelector('#scale').value = '14' - scales.pick(14) - // play_next() } |
