<commit_before>'use strict';

$(function() {
    var points = 0;
    var $pointContainer = $('.points');
    var keypressed = 'key-';
    var $container = $('.container');
    var $square = $('.key-selector');
    // array of objects: {score, speed, message, points}
    var speeds = [
        {score: 0, speed: 800, message: '', points: 1},
        {score: 5, speed: 750, message: 'You\'ve got it!', points: 2},
        {score: 20, speed: 695, message: 'Keep going!', points: 5},
        {score: 70, speed: 630, message: 'You\'re doing great!', points: 7},
        {score: 150, speed: 570, message: 'You rock!', points: 10},
        {score: 300, speed: 520, message: 'Don\'t stop!', points: 12},
        {score: 500, speed: 490, message: 'Tricky!', points: 15},
        {score: 760, speed: 470, message: 'Great!', points: 17},
        {score: 1100, speed: 455, message: 'I like your style!', points: 20},
        {score: 1500, speed: 420, message: 'Awesome!', points: 22},
        {score: 2000, speed: 400, message: 'Yeah!!', points: 25},
        {score: 2700, speed: 385, message: 'How do you do that?', points: 27},
        {score: 3500, speed: 370, message: '...how?', points: 30},
        {score: 4300, speed: 360, message: 'Don\'t ever stop!!', points: 32},
        {score: 5500, speed: 350, message: 'I\'m really impressed.', points: 35},
        {score: 7000, speed: 340, message: 'Arrow hero!', points: 40},
        {score: 10000, speed: 330, message: 'You\'re really still here?', points: 40},
        {score: 10500, speed: 320, message: 'That\'s impressive!', points: 40}
    ];
    var current = speeds[0];
    var difficulty = 1;
    var started = false;
    var maxLife = 5000;
    var currentLife = maxLife;
    // array of objects: {delay, started, interval}
    var scheduledSpawns = [];

    function updatePoints(pts) {
        if (pts < 1) {
            pts = 1;
        }
        pts = Math.floor(pts);
        points += pts;
        $square.addClass('bump');
        $pointContainer
            .html(points)
            .addClass('bump')
            .on('webkitAnimationEnd oanimationend msAnimationEnd animationend', function() {
                $pointContainer.removeClass('bump');
                $square.removeClass('bump');
            })
        ;
        var $ding = $('<div class="ding">+'+pts+'</div>');
        $ding.on('webkitAnimationEnd oanimationend msAnimationEnd animationend', function() {
            $(this).remove();
        });
        $square.append($ding);
    }

    function updateSpeed() {
        var oldSpeed = current;
        for (var i in speeds) {
            var _speed = speeds[i];
            if (points >= _speed.score) {
                current = _speed;
            } else if (points < _speed.score) {
                break;
            }
        }
        if (current.speed !== oldSpeed.speed) {
            // Speed changed !
            $('.level-message')
                .text(current.message)
                .addClass('show')
                .on('webkitAnimationEnd oanimationend msAnimationEnd animationend', function() {
                    $(this).removeClass('show');
                });
        }
    }

    function spawnRandomKey(obj) {
        if (started !== 'paused') { // running or ended
            removeScheduledSpawn(obj);
        }

        if (started === 'end' || started === 'paused' || started === 'restart') {
            return;
        }

        var arr = ['up', 'left', 'down', 'right'];
        var $elem = $('<div class="key key-'+arr[Math.floor(Math.random()*arr.length)]+'"></div>');
        $elem.on('webkitAnimationEnd oanimationend msAnimationEnd animationend', function() {

            if (started === 'end' || started === 'restart') {
                return;
            }

            if ($(this).hasClass(keypressed) || 1) {
                currentLife += 200;
                if (currentLife > maxLife) {
                    currentLife = maxLife;
                }
                updatePoints(current.points);
            } else {
                currentLife -= 1000;
                $square
                    .addClass('bad')<commit_msg>Replaced incremental speed function with an array of defined speed/score<commit_after>'use strict';

$(function() {
    var points = 0;
    var $pointContainer = $('.points');
    var keypressed = 'key-';
    var $container = $('.container');
    var $square = $('.key-selector');
    // array of objects: {score, speed, message, points}
    var speeds = [
        {score: 0, speed: 800, message: '', points: 1},
        {score: 5, speed: 750, message: 'You\'ve got it!', points: 2},
        {score: 20, speed: 695, message: 'Keep going!', points: 5},
        {score: 70, speed: 630, message: 'You\'re doing great!', points: 7},
        {score: 150, speed: 570, message: 'You rock!', points: 10},
        {score: 300, speed: 520, message: 'Don\'t stop!', points: 12},
        {score: 500, speed: 490, message: 'Tricky!', points: 15},
        {score: 760, speed: 470, message: 'Great!', points: 17},
        {score: 1100, speed: 455, message: 'I like your style!', points: 20},
        {score: 1500, speed: 420, message: 'Awesome!', points: 22},
        {score: 2000, speed: 400, message: 'Yeah!!', points: 25},
        {score: 2700, speed: 385, message: 'How do you do that?', points: 27},
        {score: 3500, speed: 370, message: '...how?', points: 30},
        {score: 4300, speed: 360, message: 'Don\'t ever stop!!', points: 32},
        {score: 5500, speed: 350, message: 'I\'m really impressed.', points: 35},
        {score: 7000, speed: 340, message: 'Arrow hero!', points: 40},
        {score: 10000, speed: 330, message: 'You\'re really still here?', points: 40},
        {score: 10500, speed: 320, message: 'That\'s impressive!', points: 40}
    ];
    var current = speeds[0];
    var difficulty = 1;
    var started = false;
    var maxLife = 5000;
    var currentLife = maxLife;
    // array of objects: {delay, started, interval}
    var scheduledSpawns = [];

    function updatePoints(pts) {
        if (pts < 1) {
            pts = 1;
        }
        pts = Math.floor(pts);
        points += pts;
        $square.addClass('bump');
        $pointContainer
            .html(points)
            .addClass('bump')
            .on('webkitAnimationEnd oanimationend msAnimationEnd animationend', function() {
                $pointContainer.removeClass('bump');
                $square.removeClass('bump');
            })
        ;
        var $ding = $('<div class="ding">+'+pts+'</div>');
        $ding.on('webkitAnimationEnd oanimationend msAnimationEnd animationend', function() {
            $(this).remove();
        });
        $square.append($ding);
    }

    function updateSpeed() {
        var oldSpeed = current;
        for (var i in speeds) {
            var _speed = speeds[i];
            if (points >= _speed.score) {
                current = _speed;
            } else if (points < _speed.score) {
                break;
            }
        }
        if (current.speed !== oldSpeed.speed) {
            // Speed changed !
            $('.level-message')
                .text(current.message)
                .addClass('show')
                .on('webkitAnimationEnd oanimationend msAnimationEnd animationend', function() {
                    $(this).removeClass('show');
                });
        }
    }

    function spawnRandomKey(obj) {
        if (started !== 'paused') { // running or ended
            removeScheduledSpawn(obj);
        }

        if (started === 'end' || started === 'paused' || started === 'restart') {
            return;
        }

        var arr = ['up', 'left', 'down', 'right'];
        var $elem = $('<div class="key key-'+arr[Math.floor(Math.random()*arr.length)]+'"></div>');
        $elem.on('webkitAnimationEnd oanimationend msAnimationEnd animationend', function() {

            if (started === 'end' || started === 'restart') {
                return;
            }

            if ($(this).hasClass(keypressed)) {
                currentLife += 200;
                if (currentLife > maxLife) {
                    currentLife = maxLife;
                }
                updatePoints(current.points);
            } else {
                currentLife -= 1000;
                $square
                    .addClass('bad')
{'fraction_non_alphanumeric': 0.1591235632183908, 'fraction_numerical': 0.03891283524904215, 'mean_word_length': 1.950547509713882, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '565519', 'n_tokens_mistral': 2729, 'n_tokens_neox': 2355, 'n_words': 689}