<commit_before>(function(ext) {
    
    var firstTime = true;
    var boolean = true;
    var jsonObject = null;
    var xScale = 280;
    var yScale = 210;
    var zScale = 200;
    var status = 0;
    
    alert("BEFORE CLICKING OK: Make sure you have have followed the instructions in Kinect2Scratch");
    
    var wsImpl = window.WebSocket || window.MozWebSocket;
     
    console.log("connecting to server ..");

    // create a new websocket and connect
    window.ws = new wsImpl('ws://localhost:8181/');
    
    // when data is comming from the server, this method is called
    ws.onmessage = function (evt) {
        jsonObject = JSON.parse(evt.data);
            if(jsonObject.bodies == '')
            {
                status = 1;
            } else
            {
                status = 2;
            }
    };

    // when the connection is established, this method is called
    ws.onopen = function () {
        console.log('.. connection open');
    };

    // when the connection is closed, this method is called
    ws.onclose = function () {
        console.log('.. connection closed');
        status = 0;
    };

    // Cleanup function when the extension is unloaded
    ext._shutdown = function() {};
    

    // Status reporting code
    // Use this to report missing hardware, plugin or unsupported browser
    ext._getStatus = function() {
        if(status == 0)
        {
            return {status: 0, msg: 'Kinect is not connected to Scratch'};
            //polling function for auto-reconnect should go here
        }
        if(status == 1)
        {
            return {status: 1, msg: 'Kinect is connected, but is not detecting any bodies'};
        }
        if(status == 2)
        {
            return {status: 2, msg: 'Kinect is sending body data'};
        }
        
    };
    
        // Block and block menu descriptions
    var descriptor = {
        blocks: [
            ['', 'My First Block', 'my_first_block'],
            ['r', '%n ^ %n', 'power', 2, 3],
            ['r', '%m.k body 1 sensor value', 'k', 'Head X'],
            ['r', '%m.k body 2 sensor value', 'k1', 'Head X'],
            ['r', '%m.l %m.k1 %m.x', 'joints', 'Body 1', 'Head', 'x'],
            ['', 'restart local connection', 'restart'],
            ['', 'Create connection to %s', 'ipconnect', '0.0.0.0'],
            ['', 'test block', 'test_block'],
            ['b', 'connected', 'connected'],
            ['b', '%m.l tracked', 'tracked', 'Body 1'],
            ['', 'console.log %n', 'write'],
            ['', 'bad only %n', 'writeB'],
            ['r', '%m.l id', 'l', 'Body 1'],
            ['r', '%m.l Left Handstate', 'lhandd', 'Body 1'],
            ['b', '%m.l Left Handstate is %m.n', 'lhand', 'Body 1', 'Closed'],
            ['b', '%m.l Right Handstate is %m.n', 'rhand', 'Body 1', 'Closed']
        ],
        
        menus: {
        k: ['Left Ankle X', 'Left Ankle Y', 'Right Ankle X', 'Right Ankle Y', 'Left Elbow X', 'Left Elbow Y', 'Right Elbow X', 'Right Elbow Y', 'Left Foot X', 'Left Foot Y', 'Right Foot X', 'Right Foot Y', 'Left Hand X', 'Left Hand Y', 'Right Hand X', 'Right Hand Y', 'Left Hand Tip X', 'Left Hand Tip Y', 'Right Hand Tip X', 'Right Hand Tip Y', 'Head X', 'Head Y', 'Left Hip X', 'Left Hip Y', 'Right Hip X', 'Right Hip Y', 'Left Knee X', 'Left Knee Y', 'Right Knee X', 'Right Knee Y', 'Neck X', 'Neck Y', 'Left Shoulder X', 'Left Shoulder Y', 'Right Shoulder X', 'Right Shoulder Y', 'Spine Base X', 'Spine Base Y', 'Spine Middle X', 'Spine Middle Y', 'Spine Shoulder X', 'Spine Shoulder Y', 'Left Thumb X', 'Left Thumb Y', 'Right Thumb X', 'Right Thumb Y', 'Left Wrist X', 'Left Wrist Y', 'Right Wrist X', 'Right Wrist Y'],
	    k1: ['Left Ankle', 'Right Ankle', 'Left Elbow', 'Right Elbow', 'Left Foot', 'Right Foot', 'Left Hand', 'Right Hand', 'Left Hand Tip', 'Right Hand Tip', 'Head', 'Left Hip', 'Right Hip', 'Left Knee', 'Right Knee', 'Neck', 'Left Shoulder', 'Right Shoulder', 'Spine Base', 'Spine Middle', 'Spine Shoulder', 'Left Thumb', 'Right Thumb', 'Left Wrist', 'Right Wrist'],
        l: ['Body 1', 'Body 2', 'Body 3', 'Body 4', 'Body 5', 'Body 6'],
        n: ['Unknown', 'Not Tracked', 'Open', 'Closed', 'Lasso'],
        x: ['x', 'y', 'z'],
    }
    };

	ext.my_first_block = function() {
        console.log("My first block");
    };
    
    //restarts the client side of the server
    ext.restart = function() {
        console.log("connecting to local server ..");
        window.ws = new wsImpl('ws://localhost:8181/');
    };
    
    ext.ipconnect = function(s) {
        console.log("connecting to "+s+' ..');
        window.ws = new wsImpl('ws://'+s+':8181/');
    }
	
    ext.power = function(base, exponent) {
        return Math.pow(base, exponent);
    };
    
    ext.test_block = function() {
        console.log(jsonObject.bodies[0].joints[3].x*xScale);
    };
    
    //True if scratch is receiving the kinect (but not necessarily data)
        ext.connected = function()
    {
        if(status == 0){
            return false;
        }
        
        if(status == 1 || 2){
            return true;<commit_msg>Try closing old connection before starting new one<commit_after>(function(ext) {
    
    var firstTime = true;
    var boolean = true;
    var jsonObject = null;
    var xScale = 280;
    var yScale = 210;
    var zScale = 200;
    var status = 0;
    
    alert("BEFORE CLICKING OK: Make sure you have have followed the instructions in Kinect2Scratch");
    
    var wsImpl = window.WebSocket || window.MozWebSocket;
     
    console.log("connecting to server ..");

    // create a new websocket and connect
    window.ws = new wsImpl('ws://localhost:8181/');
    
    // when data is comming from the server, this method is called
    ws.onmessage = function (evt) {
        jsonObject = JSON.parse(evt.data);
            if(jsonObject.bodies == '')
            {
                status = 1;
            } else
            {
                status = 2;
            }
    };

    // when the connection is established, this method is called
    ws.onopen = function () {
        console.log('.. connection open');
    };

    // when the connection is closed, this method is called
    ws.onclose = function () {
        console.log('.. connection closed');
        status = 0;
    };

    // Cleanup function when the extension is unloaded
    ext._shutdown = function() {};
    

    // Status reporting code
    // Use this to report missing hardware, plugin or unsupported browser
    ext._getStatus = function() {
        if(status == 0)
        {
            return {status: 0, msg: 'Kinect is not connected to Scratch'};
            //polling function for auto-reconnect should go here
        }
        if(status == 1)
        {
            return {status: 1, msg: 'Kinect is connected, but is not detecting any bodies'};
        }
        if(status == 2)
        {
            return {status: 2, msg: 'Kinect is sending body data'};
        }
        
    };
    
        // Block and block menu descriptions
    var descriptor = {
        blocks: [
            ['', 'My First Block', 'my_first_block'],
            ['r', '%n ^ %n', 'power', 2, 3],
            ['r', '%m.k body 1 sensor value', 'k', 'Head X'],
            ['r', '%m.k body 2 sensor value', 'k1', 'Head X'],
            ['r', '%m.l %m.k1 %m.x', 'joints', 'Body 1', 'Head', 'x'],
            ['', 'restart local connection', 'restart'],
            ['', 'Create connection to %s', 'ipconnect', '0.0.0.0'],
            ['', 'test block', 'test_block'],
            ['b', 'connected', 'connected'],
            ['b', '%m.l tracked', 'tracked', 'Body 1'],
            ['', 'console.log %n', 'write'],
            ['', 'bad only %n', 'writeB'],
            ['r', '%m.l id', 'l', 'Body 1'],
            ['r', '%m.l Left Handstate', 'lhandd', 'Body 1'],
            ['b', '%m.l Left Handstate is %m.n', 'lhand', 'Body 1', 'Closed'],
            ['b', '%m.l Right Handstate is %m.n', 'rhand', 'Body 1', 'Closed']
        ],
        
        menus: {
        k: ['Left Ankle X', 'Left Ankle Y', 'Right Ankle X', 'Right Ankle Y', 'Left Elbow X', 'Left Elbow Y', 'Right Elbow X', 'Right Elbow Y', 'Left Foot X', 'Left Foot Y', 'Right Foot X', 'Right Foot Y', 'Left Hand X', 'Left Hand Y', 'Right Hand X', 'Right Hand Y', 'Left Hand Tip X', 'Left Hand Tip Y', 'Right Hand Tip X', 'Right Hand Tip Y', 'Head X', 'Head Y', 'Left Hip X', 'Left Hip Y', 'Right Hip X', 'Right Hip Y', 'Left Knee X', 'Left Knee Y', 'Right Knee X', 'Right Knee Y', 'Neck X', 'Neck Y', 'Left Shoulder X', 'Left Shoulder Y', 'Right Shoulder X', 'Right Shoulder Y', 'Spine Base X', 'Spine Base Y', 'Spine Middle X', 'Spine Middle Y', 'Spine Shoulder X', 'Spine Shoulder Y', 'Left Thumb X', 'Left Thumb Y', 'Right Thumb X', 'Right Thumb Y', 'Left Wrist X', 'Left Wrist Y', 'Right Wrist X', 'Right Wrist Y'],
	    k1: ['Left Ankle', 'Right Ankle', 'Left Elbow', 'Right Elbow', 'Left Foot', 'Right Foot', 'Left Hand', 'Right Hand', 'Left Hand Tip', 'Right Hand Tip', 'Head', 'Left Hip', 'Right Hip', 'Left Knee', 'Right Knee', 'Neck', 'Left Shoulder', 'Right Shoulder', 'Spine Base', 'Spine Middle', 'Spine Shoulder', 'Left Thumb', 'Right Thumb', 'Left Wrist', 'Right Wrist'],
        l: ['Body 1', 'Body 2', 'Body 3', 'Body 4', 'Body 5', 'Body 6'],
        n: ['Unknown', 'Not Tracked', 'Open', 'Closed', 'Lasso'],
        x: ['x', 'y', 'z'],
    }
    };

	ext.my_first_block = function() {
        console.log("My first block");
    };
    
    //restarts the client side of the server
    ext.restart = function() {
        console.log("connecting to local server ..");
        window.ws = new wsImpl('ws://localhost:8181/');
    };
    
    ext.ipconnect = function(s) {
        window.ws.close();
        console.log("connecting to "+s+' ..');
        window.ws = new wsImpl('ws://'+s+':8181/');
    }
	
    ext.power = function(base, exponent) {
        return Math.pow(base, exponent);
    };
    
    ext.test_block = function() {
        console.log(jsonObject.bodies[0].joints[3].x*xScale);
    };
    
    //True if scratch is receiving the kinect (but not necessarily data)
        ext.connected = function()
    {
        if(status == 0){
            return false;
        }
        
        if(status == 1 || 2){
            return true;
{'fraction_non_alphanumeric': 0.16883242823894493, 'fraction_numerical': 0.011636927851047323, 'mean_word_length': 2.1567187021732477, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2925164', 'n_tokens_mistral': 3376, 'n_tokens_neox': 3214, 'n_words': 1139}