<commit_before>'use strict';

var escapeNonWordsRegexp = /[_\W]+/g // precompile regex
function escapeNonWords(s) {
    return s.replace(escapeNonWordsRegexp, "-");
}

var socket = io();
var plots = {}; // Map of sensor -> chart
var rawlist = {};

//Variables used for the canvas.
var x_pos = 0;
var y_pos = 0;
var blocksize = 20;
var ball_size = 6;
var offset = ball_size/2; //Moves the ball object into center
//TODO: Find a dynamic offset value, maybe derive from c.height & c.width
var c, ctx, blocksize, ball;

setInterval(function() {
    for (var m in plots) {
        var plot = plots[m];
        if (typeof plot.redraw === "undefined") {
            continue
        }
        plot.redraw();
    }
}, 500);

var updateSidebarValue = _.throttle(function(nameVal, pkt) {
	document.getElementById(nameVal).innerHTML = pkt.value.toFixed(2);
}, 1);

socket.on('data', function(pkts){
	for (var i = 0; i < pkts.length; i++) {
		var pkt = pkts[i];

		if (~pkt.name.indexOf("request log")) {
			console.log(pkt);
			//var csvString = csvRows.join("\n");
			//var a = document.createElement('a');
			//a.href = 'data:attachment/csv;base64,' + btoa(csvString);
			//a.target = '_blank';
			//a.download = 'LogData.csv';

			//document.body.appendChild(a);

			//a.click();
		}
		else{
			var escapedName = escapeNonWords(pkt.name);
			var nameVal = escapedName + '-val';
			if (pkt.name in rawlist) {
				// In all case we need to update the sidebar raw value
				updateSidebarValue(nameVal, pkt);
			};

			if ((~pkt.name.indexOf("GX") || ~pkt.name.indexOf("GY")) && "GX" in plots) {
				update_g_plot(pkt);	//Update the g-force plot
			} else if (pkt.name in plots) {
				// Update the plot
				var shift = plots[pkt.name].series[0].data.length > 400;
				plots[pkt.name].series[0].addPoint(pkt.value, false, shift);
			} else {
				// Element does not exists, create it
				if (~pkt.name.indexOf("GX") || ~pkt.name.indexOf("GY")){
					create_g_plot();
				} else {
					//Element is a standard line plot
					if ($('#' + nameVal).length === 0) {
						$('#rawlist').append(
							'<tr id="'+ escapedName + '" class="ui-state-default" onclick="create_line_plot(\'' + pkt.name + '\', ' + pkt.value + ')">' +
							'<td>'+pkt.name+'</td>'+
							'<td id="' + nameVal + '">'+pkt.value.toFixed(2) +'</td>'+
							'</tr>'
						);
						rawlist[pkt.name] = pkt;
					}
				}
			}
		}
		$(function() {
			$("#plots").sortable();
			$("#plots").disableSelection();
		});
	}
});

function is_in_circle(x) {
    x = x/4;                            //Only every 4th is a new pixel
    var y = Math.floor(x/ball_size);    //New line for every ball_size pixels
    x = x%ball_size;
    var dist_center = Math.sqrt(Math.pow(ball_size/2 - x, 2) + Math.pow(ball_size/2 - y, 2)); //Euclidian distance to center
    if (dist_center >= ball_size/2.5) {
        return false;
    } else {
        return true;
    }
}

function update_g_plot(packet){
	if (~packet.name.indexOf("GX")) {
        x_pos = packet.value;
    } else {
    //GY-event is usually sent directly after GX-event
    //so we do not update at both events
        y_pos = packet.value;
        ctx.clearRect(0,0,c.width,c.height);                                                //Clear the canvas
        ctx.stroke();                                                                       //Apply grid colors again
        ctx.putImageData(ball, c.width/2 + x_pos*blocksize - offset, c.height/2 + y_pos*blocksize - offset);  //Place ball object
    }
}

function create_g_plot() {
	//Element is a G-force graph - only make on GX event.
	//GX, GY is a html5 canvas element
	$('#plots').append('<canvas class="ui-state-default" id="GX"/>');
	c = document.getElementById("GX");
	ctx = c.getContext("2d");
	ctx.strokeStyle = "lightgrey";
	plots["GX"] = ctx; //Store canvas context in plots so it can be used out of scope.

	//Make the grid
	for (var i = 0; i < c.width/2; i+=blocksize) {
	    ctx.moveTo(c.width/2 + i, 0)
	    ctx.lineTo(c.width/2 + i, c.height)
	    ctx.moveTo(c.width/2 - i, 0)
	    ctx.lineTo(c.width/2 - i, c.height)
	};<commit_msg>G-sensor is now off by default and can be toggled on from the sidebar.<commit_after>'use strict';

var escapeNonWordsRegexp = /[_\W]+/g // precompile regex
function escapeNonWords(s) {
    return s.replace(escapeNonWordsRegexp, "-");
}

var socket = io();
var plots = {}; // Map of sensor -> chart
var rawlist = {};

//Variables used for the canvas.
var x_pos = 0;
var y_pos = 0;
var blocksize = 20;
var ball_size = 6;
var offset = ball_size/2; //Moves the ball object into center
//TODO: Find a dynamic offset value, maybe derive from c.height & c.width
var c, ctx, blocksize, ball;

setInterval(function() {
    for (var m in plots) {
        var plot = plots[m];
        if (typeof plot.redraw === "undefined") {
            continue
        }
        plot.redraw();
    }
}, 500);

var updateSidebarValue = _.throttle(function(nameVal, pkt) {
	document.getElementById(nameVal).innerHTML = pkt.value.toFixed(2);
}, 1);

socket.on('data', function(pkts){
	for (var i = 0; i < pkts.length; i++) {
		var pkt = pkts[i];

		if (~pkt.name.indexOf("request log")) {
			console.log(pkt);
			//var csvString = csvRows.join("\n");
			//var a = document.createElement('a');
			//a.href = 'data:attachment/csv;base64,' + btoa(csvString);
			//a.target = '_blank';
			//a.download = 'LogData.csv';

			//document.body.appendChild(a);

			//a.click();
		}
		else{
			var escapedName = escapeNonWords(pkt.name);
			var nameVal = escapedName + '-val';
			if (pkt.name in rawlist) {
				// In all case we need to update the sidebar raw value
				updateSidebarValue(nameVal, pkt);
			};

			if ((pkt.name === "GX" || pkt.name === "GY") && "GX" in plots) {
				update_g_plot(pkt);	//Update the g-force plot
			} else if (pkt.name in plots) {
				// Update the plot
				var shift = plots[pkt.name].series[0].data.length > 400;
				plots[pkt.name].series[0].addPoint(pkt.value, false, shift);
			} else {
				// Element does not exists, create it
				var showPlotFunc = onclick = 'create_line_plot';
				if (pkt.name === "GX" || pkt.name === "GY") {
					showPlotFunc = 'create_g_plot';
				}

				//Element is a standard line plot
				if ($('#' + nameVal).length === 0) {
					$('#rawlist').append(
						'<tr id="'+ escapedName + '" class="ui-state-default" onclick="'+showPlotFunc+'(\'' + pkt.name + '\', ' + pkt.value + ')">' +
						'<td>'+pkt.name+'</td>'+
						'<td id="' + nameVal + '">'+pkt.value.toFixed(2) +'</td>'+
						'</tr>'
					);
					rawlist[pkt.name] = pkt;
				}
			}
		}
		$(function() {
			$("#plots").sortable();
			$("#plots").disableSelection();
		});
	}
});

function is_in_circle(x) {
    x = x/4;                            //Only every 4th is a new pixel
    var y = Math.floor(x/ball_size);    //New line for every ball_size pixels
    x = x%ball_size;
    var dist_center = Math.sqrt(Math.pow(ball_size/2 - x, 2) + Math.pow(ball_size/2 - y, 2)); //Euclidian distance to center
    if (dist_center >= ball_size/2.5) {
        return false;
    } else {
        return true;
    }
}

function update_g_plot(packet){
	if (~packet.name.indexOf("GX")) {
        x_pos = packet.value;
    } else {
    //GY-event is usually sent directly after GX-event
    //so we do not update at both events
        y_pos = packet.value;
        ctx.clearRect(0,0,c.width,c.height);                                                //Clear the canvas
        ctx.stroke();                                                                       //Apply grid colors again
        ctx.putImageData(ball, c.width/2 + x_pos*blocksize - offset, c.height/2 + y_pos*blocksize - offset);  //Place ball object
    }
}

function create_g_plot() {
	//Element is a G-force graph - only make on GX event.
	//GX, GY is a html5 canvas element
	$('#plots').append('<canvas class="ui-state-default" id="G-plot"/>');
	c = document.getElementById("G-plot");
	ctx = c.getContext("2d");
	ctx.strokeStyle = "lightgrey";
	plots["GX"] = ctx; //Store canvas context in plots so it can be used out of scope.

	//Make the grid
	for (var i = 0; i < c.width/2; i+=blocksize) {
	    ctx.moveTo(c.width/2 + i, 0)
	    ctx.lineTo(c.width/2 + i, c.height)
	    ctx.moveTo(c.width/2 - i, 0)
	    ctx.lineTo(c.width/2 - i, c.height)
	};
{'fraction_non_alphanumeric': 0.17016148469510725, 'fraction_numerical': 0.010363943118823812, 'mean_word_length': 2.4335953661563923, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '325776', 'n_tokens_mistral': 3188, 'n_tokens_neox': 2883, 'n_words': 741}