<commit_before>$(document).ready(function () {

    /**
     * Constants
     */

    var parties = $('.party');
    var valuesList = <%= Value.all.to_json %>   // JSON data from Rails app
    var pairings = <%= Pairing.all.to_json %>;
    var score = timer = xyz = 0;
    var updateInterval = 7000;

    /**
     * Event listeners
     */

    /* Starting the game */
    $('#startGame').on('click', function(e) {

        e.preventDefault();
        console.info("Launching game. Good luck!");

        $(this).attr('disabled', true);
        $('#resetGame').attr('disabled', false);

        try {
            init();
        } catch (err) {
            console.error("init() failed. Reason: " + err);
        }

        gameLoop = setInterval(function () {
            updateValues()
        }, updateInterval);

        return false;
    });

    /* Resetting the game */
    $('#resetGame').on('click', function(e) {

        e.preventDefault();

        if (confirm("Tämä nollaa pelin. Oletko varma?")) {
            console.info("Resetting game.");
            clearInterval(gameLoop);
            window.location.reload();
        }

        return false;
    });

    /**
     * Init function setups the game and necessary elements.
     */

    var randomValuePosition = function() {

        /* Generate random number from 1..55 */
        var num = Math.floor((Math.random() * 56));
        var randObj = {
            name: valuesList[pairings[num].value_id-1].name,
            id: pairings[num].value_id,
            position: pairings[num].position
        };

        return randObj;
    };

    var init = function () {

        console.info("Initializing game...");

        initialValues();

        var pValues = $('.value');

        if (pValues.length > 0) {
            pValues.draggable();
            parties.droppable({
                drop: valueDropped
            });
        } else {
            console.warn("No values set!");
        }
    };

    var updateValues = function () {
        xyz++;
        if ($('.value').length < 10) {
            generateNewValues(randomValuePosition());
            $('.value').draggable();
        } else {
            gameOver();
        }
        if(xyz%5==0)
            updateInterval = updateInterval * 0.8;
        gameLoop = setInterval(function () {
            updateValues()
        }, updateInterval);
    };

    var initialValues = function (n) {

        var amount = n || 3;

        for (var i = 0; i < amount; i++)
            generateNewValues(randomValuePosition());
    }

    var generateNewValues = function (content) {

        var x = icon = '';

        if (content.position == 1) {
            x = 'right';
            icon = 'fa-thumbs-up';
        } else if (content.position == -1) {
            x = 'wrong';
            icon = 'fa-thumbs-down';
        }

        var pValues = $('.arvot')
            .append('<li> ' + content.name + '</li>')

        pValues.find('li').last()
            .addClass("value " + x + " fa " + icon)
            .attr("data-id", content.id)
            .attr("data-position", String(content.position));
    };

    /**
     * Call when value is dropped on party image
     */

    var valueDropped = function(event, ui) {

        if (typeof event !== 'undefined' && typeof ui !== 'undefined') {

            var party_id = event.target.id;
            var value_id = ui.draggable.data("id");
            var value_position = ui.draggable.data("position");
            var newScore = 0;
            if (partyAgreesWith(value_id, party_id, value_position)) {
                newScore++;
            }
            else {
                newScore--;
                updateValues();
            }

            ui.draggable.remove();
            changeScore(newScore);
        }
    };

    var partyAgreesWith = function (value_id, party_id, position) {

        for (var i = 0; i < pairings.length; i++) {

            if (pairings[i].value_id == value_id
                && pairings[i].party_id == party_id
                && pairings[i].position == position) {
                    return true;
            }
        }

        return false;
    };

    var gameOver = function () {

        var gameOverScreen = $('#gameOver');
        var score = $('#score').data('points');
        $('#finalscore').text(score);
        gameOverScreen.on('hide.bs.modal', function() {
            window.location.reload();
        });

        /* End game and display a nice modal */
        gameOverScreen.modal({
            backdrop: 'static',
            keyboard: false
        });

    };

    var changeScore = function (points) {

        if (points !== 0) {

            var score = $('#score');
            var currentPoints = score.data('points');

            currentPoints += points;

            score.text(currentPoints).data('points', currentPoints);
        }

    };

});<commit_msg>Nopeutus<commit_after>$(document).ready(function () {

    /**
     * Constants
     */

    var parties = $('.party');
    var valuesList = <%= Value.all.to_json %>   // JSON data from Rails app
    var pairings = <%= Pairing.all.to_json %>;
    var score = timer = xyz = 0;
    var updateInterval = 7000;
    var gameLoop;

    /**
     * Event listeners
     */

    /* Starting the game */
    $('#startGame').on('click', function(e) {

        e.preventDefault();
        console.info("Launching game. Good luck!");

        $(this).attr('disabled', true);
        $('#resetGame').attr('disabled', false);

        try {
            init();
        } catch (err) {
            console.error("init() failed. Reason: " + err);
        }

        gameLoop = setInterval(function () {
            updateValues()
        }, updateInterval);

        return false;
    });

    /* Resetting the game */
    $('#resetGame').on('click', function(e) {

        e.preventDefault();

        if (confirm("Tämä nollaa pelin. Oletko varma?")) {
            console.info("Resetting game.");
            clearInterval(gameLoop);
            window.location.reload();
        }

        return false;
    });

    /**
     * Init function setups the game and necessary elements.
     */

    var randomValuePosition = function() {

        /* Generate random number from 1..55 */
        var num = Math.floor((Math.random() * 56));
        var randObj = {
            name: valuesList[pairings[num].value_id-1].name,
            id: pairings[num].value_id,
            position: pairings[num].position
        };

        return randObj;
    };

    var init = function () {

        console.info("Initializing game...");

        initialValues();

        var pValues = $('.value');

        if (pValues.length > 0) {
            pValues.draggable();
            parties.droppable({
                drop: valueDropped
            });
        } else {
            console.warn("No values set!");
        }
    };

    var updateValues = function () {
        xyz++;
        if ($('.value').length < 10) {
            generateNewValues(randomValuePosition());
            $('.value').draggable();
        } else {
            gameOver();
        }
        if(xyz%5==0)
            updateInterval = updateInterval * 0.5;
        clearInterval(gameLoop);
        gameLoop = setInterval(function () {
            updateValues()
        }, updateInterval);
    };

    var initialValues = function (n) {

        var amount = n || 3;

        for (var i = 0; i < amount; i++)
            generateNewValues(randomValuePosition());
    }

    var generateNewValues = function (content) {

        var x = icon = '';

        if (content.position == 1) {
            x = 'right';
            icon = 'fa-thumbs-up';
        } else if (content.position == -1) {
            x = 'wrong';
            icon = 'fa-thumbs-down';
        }

        var pValues = $('.arvot')
            .append('<li> ' + content.name + '</li>')

        pValues.find('li').last()
            .addClass("value " + x + " fa " + icon)
            .attr("data-id", content.id)
            .attr("data-position", String(content.position));
    };

    /**
     * Call when value is dropped on party image
     */

    var valueDropped = function(event, ui) {

        if (typeof event !== 'undefined' && typeof ui !== 'undefined') {

            var party_id = event.target.id;
            var value_id = ui.draggable.data("id");
            var value_position = ui.draggable.data("position");
            var newScore = 0;
            if (partyAgreesWith(value_id, party_id, value_position)) {
                newScore++;
            }
            else {
                newScore--;
                updateValues();
            }

            ui.draggable.remove();
            changeScore(newScore);
        }
    };

    var partyAgreesWith = function (value_id, party_id, position) {

        for (var i = 0; i < pairings.length; i++) {

            if (pairings[i].value_id == value_id
                && pairings[i].party_id == party_id
                && pairings[i].position == position) {
                    return true;
            }
        }

        return false;
    };

    var gameOver = function () {

        var gameOverScreen = $('#gameOver');
        var score = $('#score').data('points');
        $('#finalscore').text("Pisteet:" + score);
        gameOverScreen.on('hide.bs.modal', function() {
            window.location.reload();
        });

        /* End game and display a nice modal */
        gameOverScreen.modal({
            backdrop: 'static',
            keyboard: false
        });

    };

    var changeScore = function (points) {

        if (points !== 0) {

            var score = $('#score');
            var currentPoints = score.data('points');

            currentPoints += points;

            score.text(currentPoints).data('points', currentPoints);
        }

    };

});
{'fraction_non_alphanumeric': 0.14720452937013448, 'fraction_numerical': 0.00505510059650187, 'mean_word_length': 1.581419624217119, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, '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': '3426921', 'n_tokens_mistral': 2845, 'n_tokens_neox': 2676, 'n_words': 606}