summaryrefslogtreecommitdiff
path: root/client/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/index.js')
-rw-r--r--client/index.js197
1 files changed, 186 insertions, 11 deletions
diff --git a/client/index.js b/client/index.js
index fd40bb4..c1b740b 100644
--- a/client/index.js
+++ b/client/index.js
@@ -8,6 +8,7 @@ import {
midi_init,
play_note,
play_sequence,
+ play_interval_sequence,
export_pattern_as_midi,
note_values,
MidiWriter,
@@ -46,11 +47,86 @@ const mass_fields = [
return a
}, {})
+const gv_fields = [
+ "incident_id", "date",
+ "state", "city_or_county", "address",
+ "n_killed", "n_injured",
+ "incident_url", "source_url", "incident_url_fields_missing",
+ "congressional_district",
+ "gun_stolen", "gun_type", "incident_characteristics",
+ "latitude", "location_description", "longitude",
+ "n_guns_involved",
+ "notes",
+ "participant_age", "participant_age_group", "participant_gender", "participant_name", "participant_relationship", "participant_status", "participant_type",
+ "sources",
+ "state_house_district", "state_senate_district"
+].reduce((a,b,i) => {
+ a[b] = i
+ return a
+}, {})
+
+const year_days_by_month = [
+ 31, 28, 31, 30,
+ 31, 30, 31, 31,
+ 30, 31, 30, 31,
+ 0
+].reduce((a, b, i) => {
+ if (i === 0) {
+ return [b]
+ }
+ return a.concat(a[i-1] + b)
+}, [])
+
let i = 0, max_i = 0, mass_i = 0
let datasets = {}, dataset = {}, bounds = {}, diff = []
let play_fn = play_sequence
data.load().then(lists => {
console.log(lists)
+ 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
+ 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]),
+ ]
+ }).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 fm = lists.firearms_manufactured
datasets['Firearms Manufactured'] = {}
datasets['Firearms Manufactured'].name = 'Firearms Manufactured'
@@ -72,6 +148,7 @@ data.load().then(lists => {
datasets["Mass Shootings"] = lists.mass_shootings_from_columbine
datasets["Mass Shootings"].name = "Mass Shootings"
datasets["Mass Shootings"].pedal = true
+ datasets["Mass Shootings"].isMass = true
datasets["Mass Shootings"].play_fn = play_mass_shootings
const lines = datasets["Mass Shootings"].lines.reverse()
const [min_y, ...rest_a] = lines[0][mass_fields.date].split('/')
@@ -108,18 +185,24 @@ data.load().then(lists => {
// ]
function play_mass_shootings(i, bounds, diff, note_time, channel="all", exporting) {
- const { rows, min, max } = bounds
- const y = 0
- const x = i % rows[0].length
- const n = rows[y][x]
+ const { min, max } = bounds
const total = dataset.dates.length
let pedal_note
- let notes = [], midi_notes = [], cases = [], timings
+ let notes = [], midi_notes = []
+ let cases = []
+ let timings
+ let week = Math.floor((i+8)/4) % 4
// 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])
notes.push(dataset.lines[0][mass_i])
- cases.push(dataset.data[mass_i][mass_fields.date] + ' ' + dataset.data[mass_i][mass_fields.case] +
- ", " + dataset.data[mass_i][mass_fields.fatalities] + ' dead, ' + dataset.data[mass_i][mass_fields.injured] + ' injured')
+ if (dataset.isMass) {
+ cases.push(dataset.data[mass_i][mass_fields.date] + ' ' + dataset.data[mass_i][mass_fields.case] +
+ ", " + dataset.data[mass_i][mass_fields.fatalities] + ' dead, ' + dataset.data[mass_i][mass_fields.injured] + ' injured')
+ } else {
+ cases.push(dataset.labels[mass_i])
+ // console.log(dataset.labels[mass_i])
+ }
// console.log('push case', dataset.data[mass_i][mass_fields.date] + ' ' + dataset.data[mass_i][mass_fields.case])
mass_i += 1
}
@@ -149,8 +232,100 @@ function play_mass_shootings(i, bounds, diff, note_time, channel="all", exportin
midi_notes.push(play_note( norm(notes[3], min, max) * nx.multiply.value, 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))
+ 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))
+ timings = [22, 21, 21, 22, 21, 21]
+ break
+ case 7:
+ midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value, 16, channel, exporting, 0))
+ midi_notes.push(play_note( norm(notes[1], min, max) * nx.multiply.value, 16, channel, exporting, 16))
+ midi_notes.push(play_note( norm(notes[2], min, max) * nx.multiply.value, 16, channel, exporting, 32))
+ midi_notes.push(play_note( norm(notes[3], min, max) * nx.multiply.value, 16, channel, exporting, 48))
+ midi_notes.push(play_note( norm(notes[4], min, max) * nx.multiply.value, 22, channel, exporting, 64))
+ midi_notes.push(play_note( norm(notes[5], min, max) * nx.multiply.value, 21, channel, exporting, 86))
+ midi_notes.push(play_note( norm(notes[6], min, max) * nx.multiply.value, 21, channel, exporting, 107))
+ timings = [16, 16, 16, 16, 22, 21, 21]
+ break
+ case 8:
+ midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value, 16, channel, exporting, 0))
+ midi_notes.push(play_note( norm(notes[1], min, max) * nx.multiply.value, 16, channel, exporting, 16))
+ midi_notes.push(play_note( norm(notes[2], min, max) * nx.multiply.value, 16, channel, exporting, 32))
+ midi_notes.push(play_note( norm(notes[3], min, max) * nx.multiply.value, 16, channel, exporting, 48))
+ midi_notes.push(play_note( norm(notes[4], min, max) * nx.multiply.value, 16, channel, exporting, 64))
+ midi_notes.push(play_note( norm(notes[5], min, max) * nx.multiply.value, 16, channel, exporting, 80))
+ midi_notes.push(play_note( norm(notes[6], min, max) * nx.multiply.value, 16, channel, exporting, 96))
+ midi_notes.push(play_note( norm(notes[7], min, max) * nx.multiply.value, 16, channel, exporting, 112))
+ timings = [16, 16, 16, 16, 16, 16, 16, 16]
+ break
+ case 9:
+ midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value, 11, channel, exporting, 0))
+ midi_notes.push(play_note( norm(notes[1], min, max) * nx.multiply.value, 11, channel, exporting, 11))
+ midi_notes.push(play_note( norm(notes[2], min, max) * nx.multiply.value, 10, channel, exporting, 22))
+ midi_notes.push(play_note( norm(notes[3], min, max) * nx.multiply.value, 16, channel, exporting, 32))
+ midi_notes.push(play_note( norm(notes[4], min, max) * nx.multiply.value, 16, channel, exporting, 48))
+ midi_notes.push(play_note( norm(notes[5], min, max) * nx.multiply.value, 16, channel, exporting, 64))
+ midi_notes.push(play_note( norm(notes[6], min, max) * nx.multiply.value, 16, channel, exporting, 80))
+ midi_notes.push(play_note( norm(notes[7], min, max) * nx.multiply.value, 16, channel, exporting, 96))
+ midi_notes.push(play_note( norm(notes[8], min, max) * nx.multiply.value, 16, channel, exporting, 112))
+ timings = [11, 11, 10, 16, 16, 16, 16, 16, 16]
+ break
+ case 10:
+ midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value, 11, channel, exporting, 0))
+ midi_notes.push(play_note( norm(notes[1], min, max) * nx.multiply.value, 11, channel, exporting, 11))
+ midi_notes.push(play_note( norm(notes[2], min, max) * nx.multiply.value, 10, channel, exporting, 22))
+ midi_notes.push(play_note( norm(notes[3], min, max) * nx.multiply.value, 11, channel, exporting, 32))
+ midi_notes.push(play_note( norm(notes[4], min, max) * nx.multiply.value, 11, channel, exporting, 43))
+ midi_notes.push(play_note( norm(notes[5], min, max) * nx.multiply.value, 10, channel, exporting, 54))
+ midi_notes.push(play_note( norm(notes[6], min, max) * nx.multiply.value, 16, channel, exporting, 64))
+ midi_notes.push(play_note( norm(notes[7], min, max) * nx.multiply.value, 16, channel, exporting, 80))
+ midi_notes.push(play_note( norm(notes[8], min, max) * nx.multiply.value, 16, channel, exporting, 96))
+ midi_notes.push(play_note( norm(notes[9], min, max) * nx.multiply.value, 16, channel, exporting, 112))
+ timings = [11, 11, 10, 11, 11, 10, 16, 16, 16, 16]
+ break
+ case 11:
+ midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value, 11, channel, exporting, 0))
+ midi_notes.push(play_note( norm(notes[1], min, max) * nx.multiply.value, 11, channel, exporting, 11))
+ midi_notes.push(play_note( norm(notes[2], min, max) * nx.multiply.value, 10, channel, exporting, 22))
+ midi_notes.push(play_note( norm(notes[3], min, max) * nx.multiply.value, 11, channel, exporting, 32))
+ midi_notes.push(play_note( norm(notes[4], min, max) * nx.multiply.value, 11, channel, exporting, 43))
+ midi_notes.push(play_note( norm(notes[5], min, max) * nx.multiply.value, 10, channel, exporting, 54))
+ midi_notes.push(play_note( norm(notes[6], min, max) * nx.multiply.value, 11, channel, exporting, 64))
+ midi_notes.push(play_note( norm(notes[7], min, max) * nx.multiply.value, 11, channel, exporting, 75))
+ midi_notes.push(play_note( norm(notes[8], min, max) * nx.multiply.value, 10, channel, exporting, 86))
+ midi_notes.push(play_note( norm(notes[9], min, max) * nx.multiply.value, 16, channel, exporting, 96))
+ midi_notes.push(play_note( norm(notes[10], min, max) * nx.multiply.value, 16, channel, exporting, 112))
+ timings = [11, 11, 10, 11, 11, 10, 11, 11, 10, 16, 16]
+ break
+ case 12:
+ midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value, 11, channel, exporting, 0))
+ midi_notes.push(play_note( norm(notes[1], min, max) * nx.multiply.value, 11, channel, exporting, 11))
+ midi_notes.push(play_note( norm(notes[2], min, max) * nx.multiply.value, 10, channel, exporting, 22))
+ midi_notes.push(play_note( norm(notes[3], min, max) * nx.multiply.value, 11, channel, exporting, 32))
+ midi_notes.push(play_note( norm(notes[4], min, max) * nx.multiply.value, 11, channel, exporting, 43))
+ midi_notes.push(play_note( norm(notes[5], min, max) * nx.multiply.value, 10, channel, exporting, 54))
+ midi_notes.push(play_note( norm(notes[6], min, max) * nx.multiply.value, 11, channel, exporting, 64))
+ midi_notes.push(play_note( norm(notes[7], min, max) * nx.multiply.value, 11, channel, exporting, 75))
+ midi_notes.push(play_note( norm(notes[8], min, max) * nx.multiply.value, 10, channel, exporting, 86))
+ midi_notes.push(play_note( norm(notes[9], min, max) * nx.multiply.value, 11, channel, exporting, 96))
+ midi_notes.push(play_note( norm(notes[10], min, max) * nx.multiply.value, 11, channel, exporting, 107))
+ midi_notes.push(play_note( norm(notes[11], min, max) * nx.multiply.value, 10, channel, exporting, 118))
+ timings = [11, 11, 10, 11, 11, 10, 11, 11, 10, 11, 11, 10]
+ break
}
- const pedal_freq = scales.current().index(nx.pedal_tone.value, nx.octave.value)
+ const pedal_freq = scales.current().index(nx.pedal_tone.value + week, nx.octave.value)
pedal_note = get_midi_note_for_frequency(pedal_freq)
if (!exporting) {
kalimba.play(pedal_freq, -12)
@@ -182,7 +357,7 @@ function get_midi_note_for_frequency(freq){
midi_note = Math.floor(midi_note)
if (midi_note > 127) return 0
const note = Tone.Frequency(Math.floor(midi_note), "midi").toNote()
-console.log(freq, midi_note, note)
+ // console.log(freq, midi_note, note)
return note
}
@@ -195,8 +370,8 @@ function play_next(){
playTimeout = setTimeout(play_next, note_time)
let [new_i, notes, timings] = play_fn(i, bounds, diff, note_time)
if (dataset.labels) {
- const j = Math.floor(i / bounds.rows[0].length)
- document.querySelector('#cases').innerHTML = dataset.labels[j]
+ // const j = Math.floor(i / bounds.rows[0].length)
+ // document.querySelector('#cases').innerHTML = dataset.labels[j]
}
i = new_i