<commit_before>/*
 * This file needs to be renamed as app.js when we want to run performance tests
 * in order this to get loaded by the jxcore ready event.
 * This effectively acts as main entry point to the performance test app
*/

"use strict";

var testUtils = require("./lib/testUtils");
var fs = require('fs');
var parsedJSON = require('serveraddress.json');

testUtils.toggleRadios(true);

var CoordinatorConnector = require('./lib/CoordinatorConnector');
var TestFrameworkClient = require('./perf_tests/PerfTestFramework');

/*----------------------------------------------------------------------------------
 code for connecting to the coordinator server
 -----------------------------------------------------------------------------------*/

process.on('uncaughtException', function(err) {
    console.log("We have an uncaught exception, good bye: " + JSON.stringify(err));
    Coordinator.close();
});

process.on('unhandledRejection', function(err) {
    console.log("We have an uncaught promise rejection, good bye: " + JSON.stringify(err));
    Coordinator.close();
});

var bluetoothAddress = "";
var weHaveMadeInitialConnection= false;
var weHaveFinished = false;

var myName = "DEV" + Math.round((Math.random() * (10000)));
var Coordinator = new CoordinatorConnector();

Mobile('GetBluetoothAddress').callNative(function (err,address) {

    if(err) {
        console.log("GetBluetoothAddress returned error: " + err + ", address : " +address );
        Coordinator.close();
        return;
    }

    bluetoothAddress = address;
    console.log("Got Device Bluetooth address" + bluetoothAddress);
    Mobile('GetDeviceName').callNative(function (name) {

        myName = name + "_PT" + Math.round((Math.random() * (10000)));;
        console.log('my name is : ' + myName);
        testUtils.setMyName(myName);

        //console.log('Connect to  address : ' + parsedJSON[0].address + ' type: ' + parsedJSON[0].name);
        Coordinator.init(parsedJSON[0].address, 3000);
        console.log('attempting to connect to test coordinator');
    });
});

Coordinator.on('error', function (data) {

    //we have disconnected, thus lets not log any additional errors
    if(weHaveFinished){
        return;
    }

    var errData = JSON.parse(data);
    console.log('Error:' + data + ' : ' + errData.type +  ' : ' + errData.data);

    if(errData.type == "connect_error") {
        testUtils.printNetworkInfo();

        if(weHaveMadeInitialConnection){
            weHaveMadeInitialConnection = false;
            testUtils.reFreshWifi();
        }
    }
  testUtils.logMessageToScreen('Client error: ' + errData.type);
});

/*----------------------------------------------------------------------------------
 code for handling test communications
 -----------------------------------------------------------------------------------*/
var TestFramework = new TestFrameworkClient(myName);<commit_msg>added code that does not require iOs to give bluetooth address<commit_after>/*
 * This file needs to be renamed as app.js when we want to run performance tests
 * in order this to get loaded by the jxcore ready event.
 * This effectively acts as main entry point to the performance test app
*/

"use strict";

var testUtils = require("./lib/testUtils");
var fs = require('fs');
var parsedJSON = require('serveraddress.json');

testUtils.toggleRadios(true);

var CoordinatorConnector = require('./lib/CoordinatorConnector');
var TestFrameworkClient = require('./perf_tests/PerfTestFramework');

/*----------------------------------------------------------------------------------
 code for connecting to the coordinator server
 -----------------------------------------------------------------------------------*/

process.on('uncaughtException', function(err) {
    console.log("We have an uncaught exception, good bye: " + JSON.stringify(err));
    Coordinator.close();
});

process.on('unhandledRejection', function(err) {
    console.log("We have an uncaught promise rejection, good bye: " + JSON.stringify(err));
    Coordinator.close();
});

var bluetoothAddress = "";
var weHaveMadeInitialConnection= false;
var weHaveFinished = false;

var myName = "DEV" + Math.round((Math.random() * (10000)));
var Coordinator = new CoordinatorConnector();

if(jxcore.utils.OSInfo().isAndroid) {
    Mobile('GetBluetoothAddress').callNative(function (err, address) {
        if (err) {
            console.log("GetBluetoothAddress returned error: " + err + ", address : " + address);
            Coordinator.close();
            return;
        }

        bluetoothAddress = address;
        console.log("Got Device Bluetooth address" + bluetoothAddress);
        Mobile('GetDeviceName').callNative(function (name) {

            myName = name + "_PT" + Math.round((Math.random() * (10000)));
            ;
            console.log('my name is : ' + myName);
            testUtils.setMyName(myName);

            //console.log('Connect to  address : ' + parsedJSON[0].address + ' type: ' + parsedJSON[0].name);
            Coordinator.init(parsedJSON[0].address, 3000);
            console.log('attempting to connect to test coordinator');
        });
    });
}else{
    bluetoothAddress = "C0:FF:FF:EE:42:00";
    Mobile('GetDeviceName').callNative(function (name) {
        myName = name + "_PT" + Math.round((Math.random() * (10000)));
        ;
        console.log('my name is : ' + myName);
        testUtils.setMyName(myName);

        //console.log('Connect to  address : ' + parsedJSON[0].address + ' type: ' + parsedJSON[0].name);
        Coordinator.init(parsedJSON[0].address, 3000);
        console.log('attempting to connect to test coordinator');
    });
}

Coordinator.on('error', function (data) {

    //we have disconnected, thus lets not log any additional errors
    if(weHaveFinished){
        return;
    }

    var errData = JSON.parse(data);
    console.log('Error:' + data + ' : ' + errData.type +  ' : ' + errData.data);

    if(errData.type == "connect_error") {
        testUtils.printNetworkInfo();

        if(weHaveMadeInitialConnection){
            weHaveMadeInitialConnection = false;
            testUtils.reFreshWifi();
        }
    }
  testUtils.logMessageToScreen('Client error: ' + errData.type);
});

/*----------------------------------------------------------------------------------
 code for handling test communications
 -----------------------------------------------------------------------------------*/
var TestFramework = new TestFrameworkClient(myName);
{'fraction_non_alphanumeric': 0.22404791154791154, 'fraction_numerical': 0.007831695331695332, 'mean_word_length': 2.264661654135338, 'pattern_counts': {'":': 0, '<': 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': '2340378', 'n_tokens_mistral': 1738, 'n_tokens_neox': 1668, 'n_words': 419}