<commit_before>/**
 * Created by Peter_000 on 3/23/14.
 */

$(document).ready(function() {


    var listener = new window.keypress.Listener();

    function add_keypress_with_logs(keypress){
        var logs = new Array()
        function add_keypress(keypress) {

        }
        return function(keypress){add_keypress(keypress)}
    }
    // create simple example of how to store state
    var listOfMoves = new Array()

    listener.simple_combo("up", function(listOfMoves) {
        console.log("You pressed up");
        listOfMoves.push("up")
    });

    listener.simple_combo("down", function(listOfMoves) {
        console.log("You pressed down");
        listOfMoves.push("down")
    });

    listener.simple_combo("right", function(){function handle_right(listOfMoves) {
        console.log("You pressed right");
        listOfMoves.push("right")
    }}());

    listener.simple_combo("left", function(listOfMoves) {
        console.log("You pressed left")
        listOfMoves.push("left")
    });

    listener.simple_combo("i", function(listOfMoves) {
        console.log("printing out history:")
        console.log(listOfMoves.toString())
    });

    // first step, call /new to get board

    JSONBoard = {
        "nrows": 4,
        "tiles": [
            {"position": {"col": 2, "row": 0}, "value": 1},
            {"position": {"col": 3, "row": 2}, "value": 1},
            {"position": {"col": 0, "row": 1}, "value": 1},
            {"position": {"col": 0, "row": 2}, "value": 2},
            {"position": {"col": 2, "row": 2}, "value": 1},
            {"position": {"col": 1, "row": 0}, "value": 1},
            {"position": {"col": 0, "row": 3}, "value": 2}],
        "next_tile": {"value": 3},
        "ncols": 4
    }
    //drawBoard(JSONBoard)
    function postToUrl(theUrl, boardStateJson, onSuccessFcn){
        // Abstracting the ajax call to POST to webservice as this
        // was somewhat fussy to get working.
        $.ajax({
        type: "POST",
        url: theUrl,
        data: JSON.stringify(boardStateJson, null, '\t'),
        contentType: 'application/json;charset=UTF-8',
        success: onSuccessFcn});
    }

    console.log(JSON.stringify(JSONBoard))
    postToUrl('/move/up', JSONBoard, function(result){drawBoard(result)})

    /*
    d3.json('/move/up',JSONBoard, function(jsonData) {
            drawBoardFcn(jsonData);
    });
    */

    function drawBoard(JSONBoard) {
        console.log(JSONBoard)
        var ncols = JSONBoard['ncols']
        var nrows = JSONBoard['nrows']
        var tiles = JSONBoard['tiles'].slice()

        var xPosFn = function(d) { return d.position.col }
        var yPosFn = function(d) { return d.position.row }
        var sizeFn = function(d) { return d.value*3 }<commit_msg>victorious in creating an object to maintain state! created a simple key logger object.<commit_after>/**
 * Created by Peter_000 on 3/23/14.
 */

$(document).ready(function() {
    var listener = new window.keypress.Listener();

    function Logger(name){
        var logs = new Array();
        var logName = name;
        this.addKeypress = function add_keypress(keypress) {
            logs.push(keypress);
        }
        this.getLogs = function get_logs(){
            return logs;
        }
    }

    var theLog = new Logger('myTestLogger');

    logAnUp = function(){
        console.log("you pressed up");
        theLog.addKeypress('up')
    };

    logADown = function(){
        console.log("you pressed dow");
        theLog.addKeypress('down')
    };

    logARight = function(){
        console.log("you pressed right");
        theLog.addKeypress('right')
    };
    logALeft = function(){
        console.log("you pressed left");
        theLog.addKeypress('left')
    };

    printOutLog = function(){
        console.log(theLog.getLogs().toString())
    }

    // create simple example of how to store state

    listener.simple_combo("up", logAnUp);

    listener.simple_combo("down", logADown);

    listener.simple_combo("right", logARight);

    listener.simple_combo("left", logALeft);

    listener.simple_combo("i", printOutLog);

    // first step, call /new to get board

    JSONBoard = {
        "nrows": 4,
        "tiles": [
            {"position": {"col": 2, "row": 0}, "value": 1},
            {"position": {"col": 3, "row": 2}, "value": 1},
            {"position": {"col": 0, "row": 1}, "value": 1},
            {"position": {"col": 0, "row": 2}, "value": 2},
            {"position": {"col": 2, "row": 2}, "value": 1},
            {"position": {"col": 1, "row": 0}, "value": 1},
            {"position": {"col": 0, "row": 3}, "value": 2}],
        "next_tile": {"value": 3},
        "ncols": 4
    }
    //drawBoard(JSONBoard)
    function postToUrl(theUrl, boardStateJson, onSuccessFcn){
        // Abstracting the ajax call to POST to webservice as this
        // was somewhat fussy to get working.
        $.ajax({
        type: "POST",
        url: theUrl,
        data: JSON.stringify(boardStateJson, null, '\t'),
        contentType: 'application/json;charset=UTF-8',
        success: onSuccessFcn});
    }

    console.log(JSON.stringify(JSONBoard))
    postToUrl('/move/up', JSONBoard, function(result){drawBoard(result)})

    /*
    d3.json('/move/up',JSONBoard, function(jsonData) {
            drawBoardFcn(jsonData);
    });
    */

    function drawBoard(JSONBoard) {
        //console.log(JSONBoard)
        var ncols = JSONBoard['ncols']
        var nrows = JSONBoard['nrows']
        var tiles = JSONBoard['tiles'].slice()

        var xPosFn = function(d) { return d.position.col }
        var yPosFn = function(d) { return d.position.row }
        var sizeFn = function(d) { return d.value*3 }
{'fraction_non_alphanumeric': 0.16320111829460074, 'fraction_numerical': 0.012231347195526822, 'mean_word_length': 2.4295985620131817, 'pattern_counts': {'":': 66, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3199732', 'n_tokens_mistral': 1847, 'n_tokens_neox': 1746, 'n_words': 421}