diff options
Diffstat (limited to 'client')
| -rw-r--r-- | client/data.js | 1 | ||||
| -rw-r--r-- | client/index.js | 85 |
2 files changed, 51 insertions, 35 deletions
diff --git a/client/data.js b/client/data.js index ed1695b..fbeb2c5 100644 --- a/client/data.js +++ b/client/data.js @@ -5,6 +5,7 @@ const files = [ "firearms_manufactured", "ar_15_2016_18", "media", + "school_shootings", ] const parse = require('csv-parse') diff --git a/client/index.js b/client/index.js index cfe5832..f78c0cc 100644 --- a/client/index.js +++ b/client/index.js @@ -98,7 +98,7 @@ data.load().then(lists => { 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.offset.value = -13 nx.multiply.value = 20 document.querySelector('#scale').value = '0' scales.pick(0) @@ -139,25 +139,33 @@ data.load().then(lists => { datasets['AR-15 2016-18'].labels = ar_lines.map(a => a[2]) 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 + datasets['School Shootings 2015-18'] = {} + datasets['School Shootings 2015-18'].name = 'School Shootings (2015-18)' + datasets['School Shootings 2015-18'].pedal = true + datasets['School Shootings 2015-18'].play_fn = play_mass_shootings + datasets['School Shootings 2015-18'].onPick = () => { + nx.offset.value = -2 + nx.multiply.value = 11 + nx.pedal_tone.value = -8 + document.querySelector('#scale').value = '0' + scales.pick(0) + } 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 + if (parseInt(y) > 2018) return null + if (parseInt(y) < 2015) return null + const yy = (parseInt(y) - 2015) * 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] + total = l[gv_fields.n_injured] - 4 } return [ date, @@ -167,10 +175,10 @@ data.load().then(lists => { 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]) + datasets['School Shootings 2015-18'].dates = school_lines.map(a => a[0]) + datasets['School Shootings 2015-18'].dates.push(school_lines.length) + datasets['School Shootings 2015-18'].lines = [school_lines.map(a => a[1])] + datasets['School Shootings 2015-18'].labels = school_lines.map(a => a[2]) const fm = lists.firearms_manufactured datasets['Firearms Manufactured'] = {} @@ -236,7 +244,12 @@ function play_mass_shootings(i, bounds, diff, note_time, channel="all", exportin let notes = [], midi_notes = [] let cases = [] let timings - let week = Math.floor((i+8)/4) % 4 + let week = Math.floor((i)/4) % 4 + let year = Math.floor((i - (4*4*3)) / 48) // + 2 + console.log(year) + let yy = -year + if (year > 0) year += 1 + let this_one = 0 // console.log(i, mass_i, dataset.dates[mass_i], channel, exporting) while (i >= dataset.dates[mass_i] && mass_i < total) { // console.log(i, dataset.dates[mass_i]) @@ -250,48 +263,50 @@ function play_mass_shootings(i, bounds, diff, note_time, channel="all", exportin } // console.log('push case', dataset.data[mass_i][mass_fields.date] + ' ' + dataset.data[mass_i][mass_fields.case]) mass_i += 1 + this_one += 1 + if (this_one >= 4) break } switch (notes.length) { default: case 0: break case 1: - midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value, 128, channel, exporting, 0)) + midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value + yy, 128, channel, exporting, 0)) timings = [128] break case 2: - midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value, 64, channel, exporting, 0)) - midi_notes.push(play_note( norm(notes[1], min, max) * nx.multiply.value, 64, channel, exporting, 64)) + midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value + yy, 64, channel, exporting, 0)) + midi_notes.push(play_note( norm(notes[1], min, max) * nx.multiply.value + yy, 64, channel, exporting, 64)) timings = [64, 64] break case 3: - midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value, 43, channel, exporting, 0)) - midi_notes.push(play_note( norm(notes[1], min, max) * nx.multiply.value, 43, channel, exporting, 43)) - midi_notes.push(play_note( norm(notes[2], min, max) * nx.multiply.value, 42, channel, exporting, 85)) + midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value + yy, 43, channel, exporting, 0)) + midi_notes.push(play_note( norm(notes[1], min, max) * nx.multiply.value + yy, 43, channel, exporting, 43)) + midi_notes.push(play_note( norm(notes[2], min, max) * nx.multiply.value + yy, 42, channel, exporting, 85)) timings = [43, 43 ,42] break case 4: - midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value, 32, channel, exporting, 0)) - midi_notes.push(play_note( norm(notes[1], min, max) * nx.multiply.value, 32, channel, exporting, 32)) - midi_notes.push(play_note( norm(notes[2], min, max) * nx.multiply.value, 32, channel, exporting, 64)) - midi_notes.push(play_note( norm(notes[3], min, max) * nx.multiply.value, 32, channel, exporting, 96)) + midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value + yy, 32, channel, exporting, 0)) + midi_notes.push(play_note( norm(notes[1], min, max) * nx.multiply.value + yy, 32, channel, exporting, 32)) + midi_notes.push(play_note( norm(notes[2], min, max) * nx.multiply.value + yy, 32, channel, exporting, 64)) + midi_notes.push(play_note( norm(notes[3], min, max) * nx.multiply.value + yy, 32, channel, exporting, 96)) timings = [32, 32, 32, 32] break case 5: - midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value, 22, channel, exporting, 0)) - midi_notes.push(play_note( norm(notes[1], min, max) * nx.multiply.value, 21, channel, exporting, 22)) - midi_notes.push(play_note( norm(notes[2], min, max) * nx.multiply.value, 21, channel, exporting, 43)) - midi_notes.push(play_note( norm(notes[3], min, max) * nx.multiply.value, 32, channel, exporting, 64)) - midi_notes.push(play_note( norm(notes[4], min, max) * nx.multiply.value, 32, channel, exporting, 96)) + midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value + yy, 22, channel, exporting, 0)) + midi_notes.push(play_note( norm(notes[1], min, max) * nx.multiply.value + yy, 21, channel, exporting, 22)) + midi_notes.push(play_note( norm(notes[2], min, max) * nx.multiply.value + yy, 21, channel, exporting, 43)) + midi_notes.push(play_note( norm(notes[3], min, max) * nx.multiply.value + yy, 32, channel, exporting, 64)) + midi_notes.push(play_note( norm(notes[4], min, max) * nx.multiply.value + yy, 32, channel, exporting, 96)) timings = [22, 21, 21, 32, 32] break case 6: - midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value, 22, channel, exporting, 0)) - midi_notes.push(play_note( norm(notes[1], min, max) * nx.multiply.value, 21, channel, exporting, 22)) - midi_notes.push(play_note( norm(notes[2], min, max) * nx.multiply.value, 21, channel, exporting, 43)) - midi_notes.push(play_note( norm(notes[3], min, max) * nx.multiply.value, 22, channel, exporting, 64)) - midi_notes.push(play_note( norm(notes[4], min, max) * nx.multiply.value, 21, channel, exporting, 86)) - midi_notes.push(play_note( norm(notes[5], min, max) * nx.multiply.value, 21, channel, exporting, 107)) + midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value + yy, 22, channel, exporting, 0)) + midi_notes.push(play_note( norm(notes[1], min, max) * nx.multiply.value + yy, 21, channel, exporting, 22)) + midi_notes.push(play_note( norm(notes[2], min, max) * nx.multiply.value + yy, 21, channel, exporting, 43)) + midi_notes.push(play_note( norm(notes[3], min, max) * nx.multiply.value + yy, 22, channel, exporting, 64)) + midi_notes.push(play_note( norm(notes[4], min, max) * nx.multiply.value + yy, 21, channel, exporting, 86)) + midi_notes.push(play_note( norm(notes[5], min, max) * nx.multiply.value + yy, 21, channel, exporting, 107)) timings = [22, 21, 21, 22, 21, 21] break case 7: @@ -370,7 +385,7 @@ function play_mass_shootings(i, bounds, diff, note_time, channel="all", exportin timings = [11, 11, 10, 11, 11, 10, 11, 11, 10, 11, 11, 10] break } - const pedal_freq = scales.current().index(nx.pedal_tone.value + week, nx.octave.value) + const pedal_freq = scales.current().index(nx.pedal_tone.value - week + 4 - year, nx.octave.value) pedal_note = get_midi_note_for_frequency(pedal_freq) if (!exporting) { kalimba.play(pedal_freq, -12) |
