<commit_before>/*global $ MIDI */
var sat_data,
    notes = [],
    piano_minor = [0, 3, 7, 12, 15, 19, 24, 27, 31, 36, 39, 43, 48, 51, 55, 60, 63, 67, 72, 75, 79, 84, 87, 91, 96, 99, 103, 108, 111, 115, 120, 123, 127],
    drums = [36];

function getRandomArbitary(min, max) {
    return Math.floor(Math.random() * (max - min) + min);
}

var playNoteAt = function(n) {
    $.each(notes, function(i, e) {
        var note_data = e[0],
            note_instrument = e[1];
        var velocity = getRandomArbitary(0, 127);
        var value = note_data[n];
        if (note_instrument == "acoustic_grand_piano") {
            value = value + MIDI.pianoKeyOffset;
            MIDI.programChange(0, 0);
        } else {
            MIDI.programChange(0, 118);
        }
        MIDI.noteOn(0, value, velocity);
    });
};

var playMusic = function () {
    var n = 0;
    playNoteAt(n);
    n = (n + 1) % 16;
    setTimeout(playMusic, 250);
};

var fetch_satellites = function() {
    $.get('/ajax/satellites', function(data) {
        sat_data = data;
        play_satellites();
    });
};

setInterval(fetch_satellites, 1000);

var arrayOf = function(n, times) {
    Array.apply(null, new Array(times)).map(Number.prototype.valueOf,n);
};

var play_satellites = function() {
    notes = [];
    var note_buckets = piano_minor.length - 1,
        note_bucket_width = (sat_data.max_velocity - sat_data.min_velocity) / note_buckets,
        tempo_buckets = 4,
        tempo_bucket_width = (sat_data.max_range - sat_data.min_range) / tempo_buckets;

    $.each(sat_data.satellites, function(i, sat) {
        var note_bucket = Math.floor((Math.abs(sat.velocity) - sat_data.min_velocity) / note_bucket_width),
            tempo_bucket = Math.floor((sat.range - sat_data.min_range) / tempo_bucket_width);
        var note;

        var instrument = "acoustic_grand_piano";
        var this_note = piano_minor[note_bucket];
        if (Math.random() < 0.15) {
            this_note = 36 + getRandomArbitary(0, 25);
            instrument = "synth_drum";
        }
        if (tempo_bucket == 4) {
            note = Array.apply(null, new Array(16)).map(Number.prototype.valueOf,this_note);
        } else if (tempo_bucket == 3) {
            note = [this_note, -1,this_note, -1,this_note, -1,this_note, -1,this_note, -1,this_note, -1,this_note, -1,this_note, -1];
        } else if (tempo_bucket == 2) {
            note = [this_note, -1,-1,-1,this_note, -1,-1,-1,this_note, -1,-1,-1,this_note, -1,-1,-1];<commit_msg>fix issue when there is only one satellite<commit_after>/*global $ MIDI */
var sat_data,
    notes = [],
    piano_minor = [0, 3, 7, 12, 15, 19, 24, 27, 31, 36, 39, 43, 48, 51, 55, 60, 63, 67, 72, 75, 79, 84, 87, 91, 96, 99, 103, 108, 111, 115, 120, 123, 127],
    drums = [36];

function getRandomArbitary(min, max) {
    return Math.floor(Math.random() * (max - min) + min);
}

var playNoteAt = function(n) {
    $.each(notes, function(i, e) {
        var note_data = e[0],
            note_instrument = e[1];
        var velocity = getRandomArbitary(0, 127);
        var value = note_data[n];
        if (note_instrument == "acoustic_grand_piano") {
            value = value + MIDI.pianoKeyOffset;
            MIDI.programChange(0, 0);
        } else {
            MIDI.programChange(0, 118);
        }
        MIDI.noteOn(0, value, velocity);
    });
};

var playMusic = function () {
    var n = 0;
    playNoteAt(n);
    n = (n + 1) % 16;
    setTimeout(playMusic, 250);
};

var fetch_satellites = function() {
    $.get('/ajax/satellites', function(data) {
        sat_data = data;
        play_satellites();
    });
};

setInterval(fetch_satellites, 1000);

var arrayOf = function(n, times) {
    Array.apply(null, new Array(times)).map(Number.prototype.valueOf,n);
};

var play_satellites = function() {
    notes = [];
    var note_buckets = piano_minor.length - 1,
        note_bucket_width = (sat_data.max_velocity - sat_data.min_velocity) / note_buckets,
        tempo_buckets = 4,
        tempo_bucket_width = (sat_data.max_range - sat_data.min_range) / tempo_buckets;

    $.each(sat_data.satellites, function(i, sat) {
        var note_bucket = Math.floor((Math.abs(sat.velocity) - sat_data.min_velocity) / note_bucket_width) || 1,
            tempo_bucket = Math.floor((sat.range - sat_data.min_range) / tempo_bucket_width) || 1;
        var note;

        var instrument = "acoustic_grand_piano";
        var this_note = piano_minor[note_bucket];
        if (Math.random() < 0.15) {
            this_note = 36 + getRandomArbitary(0, 25);
            instrument = "synth_drum";
        }
        if (tempo_bucket == 4) {
            note = Array.apply(null, new Array(16)).map(Number.prototype.valueOf,this_note);
        } else if (tempo_bucket == 3) {
            note = [this_note, -1,this_note, -1,this_note, -1,this_note, -1,this_note, -1,this_note, -1,this_note, -1,this_note, -1];
        } else if (tempo_bucket == 2) {
            note = [this_note, -1,-1,-1,this_note, -1,-1,-1,this_note, -1,-1,-1,this_note, -1,-1,-1];
{'fraction_non_alphanumeric': 0.15311572700296736, 'fraction_numerical': 0.05222551928783383, 'mean_word_length': 2.590909090909091, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1953918', 'n_tokens_mistral': 2034, 'n_tokens_neox': 1815, 'n_words': 386}