<commit_before>$('.date').datetimepicker({
	format: "DD/MM/YYYY HH:mm:ss"
});

$('button.btn-success').click(function() {
	findAndLoadDataChart();
});

$("<link/>", {
    rel: "stylesheet",
    type: "text/css",
    href: "resources/konker/css/pretty-json.css"
}).appendTo("head");
$.getScript( "resources/konker/scripts/json.formatter.js");

$('#exportCsv').click(function(e) {
	loadCSV();
});

function loadCSV() {
	$.ajax({
		context : this,
        type : "GET",
        url : urlTo('/visualization/csv/download'),
        contentType: "application/json",
        dataType: "json",
        timeout : 100000,
        data: $('#visualizationForm').serialize(),
        beforeSend : function(xhrObj) {
        },
        success : function(data) {
        },
        complete : function(data) {
        	$('#bufferCsv').attr('href', 'data:text/csv;charset=utf8,' + encodeURIComponent(data.responseText))
        		.attr('download', 'Events.csv');
        	$('#bufferCsv')[0].click()
        }
    });
}

function autoRefreshDataChart() {
    if (!$('#device').val() === false &&
        !$('#channel').val() === false &&
        !$('#metric').val() === false) {
        findAndLoadDataChart();		
    }
}

function findAndLoadDataChart() {
	var url = urlTo('/visualization/load/');
    $.ajax({
        context : this,
        type : "GET",
        url : url,
        dataType: "html",
        timeout : 100000,
        data: $('#visualizationForm').serialize(),
        beforeSend : function() {
            showElement('#loading');
        },
        success : function(data) {
            var result;
            try {
                result = jQuery.parseJSON(data);
            } catch (e) {

            }

        	if (result.length > 0 && result[0].message != null) {
        		$('div .alert.alert-danger').removeClass('hide');
        		$('div .alert.alert-danger li').html(result[0].message);
        		$('#exportCsv').addClass('hide');
        	} else {
        		$('div .alert.alert-danger').addClass('hide');
        		
        		var tableData = "";
        		$.each(result, function(index, value) {
        			var json = JSON.stringify(value.payload).replace(/\\/g, '');
        			json = json.replace(/\"{/g, '{');
        			json = json.replace(/\}"/g, '}');
        			tableData = tableData + '<tr><td>'+value.timestampFormated+'</td><td class="json-data">'+json+'</td></tr>';
        		});
        		$("#data-event table tbody").html(tableData);
        		formatJson($("#isJsonFormatted").attr("checked"));
        		
        		if (result.length != 0) {
        			$('#exportCsv').removeClass('hide');
        		} 
        	}

        	graphService.update($('#metrics select').val(),result);
        },
        complete : function() {
            hideElement('#loading');
        }
    });
}

var myInterval;<commit_msg>[KRMVP-396] - bug fixed<commit_after>$('.date').datetimepicker({
	format: "DD/MM/YYYY HH:mm:ss"
});

$('button.btn-success').click(function() {
	findAndLoadDataChart();
});

$("<link/>", {
    rel: "stylesheet",
    type: "text/css",
    href: "resources/konker/css/pretty-json.css"
}).appendTo("head");
$.getScript( "resources/konker/scripts/json.formatter.js");

$('#exportCsv').click(function(e) {
	loadCSV();
});

function loadCSV() {
	$.ajax({
		context : this,
        type : "GET",
        url : urlTo('/visualization/csv/download'),
        contentType: "application/json",
        dataType: "json",
        timeout : 100000,
        data: $('#visualizationForm').serialize(),
        beforeSend : function(xhrObj) {
        },
        success : function(data) {
        },
        complete : function(data) {
        	$('#bufferCsv').attr('href', 'data:text/csv;charset=utf8,' + encodeURIComponent(data.responseText))
        		.attr('download', 'Events.csv');
        	$('#bufferCsv')[0].click()
        }
    });
}

function autoRefreshDataChart() {
    if (!$('#device').val() === false &&
        !$('#channel').val() === false &&
        !$('#metric').val() === false) {
        findAndLoadDataChart();		
    }
}

function findAndLoadDataChart() {
	var url = urlTo('/visualization/load/');
    $.ajax({
        context : this,
        type : "GET",
        url : url,
        dataType: "html",
        timeout : 100000,
        data: $('#visualizationForm').serialize(),
        beforeSend : function() {
            showElement('#loading');
        },
        success : function(data) {
            var result;
            try {
                result = jQuery.parseJSON(data);
            } catch (e) {

            }

        	if (result.length > 0 && result[0].message != null) {
        		$('div .alert.alert-danger').removeClass('hide');
        		$('div .alert.alert-danger li').html(result[0].message);
        		$('#exportCsv').addClass('hide');
        	} else {
        		$('div .alert.alert-danger').addClass('hide');
        		
        		var tableData = "";
        		$.each(result, function(index, value) {
        			var json = value.payload;
        			tableData = tableData + '<tr><td>'+value.timestampFormated+'</td><td class="json-data">'+json+'</td></tr>';
        		});
        		$("#data-event table tbody").html(tableData);
        		formatJson($("#isJsonFormatted").attr("checked"));
        		
        		if (result.length != 0) {
        			$('#exportCsv').removeClass('hide');
        		} 
        	}

        	graphService.update($('#metrics select').val(),result);
        },
        complete : function() {
            hideElement('#loading');
        }
    });
}

var myInterval;
{'fraction_non_alphanumeric': 0.1994245639273512, 'fraction_numerical': 0.007013127135407301, 'mean_word_length': 2.154849688031764, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3228391', 'n_tokens_mistral': 1773, 'n_tokens_neox': 1721, 'n_words': 261}