<commit_before>function generateUUID() {
    var d = new Date().getTime();
    var uuid = 'xxxxxxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        var r = (d + Math.random()*16)%16 | 0;
        d = Math.floor(d/16);
        return (c=='x' ? r : (r&0x7|0x8)).toString(16);
    });
    return uuid;
};

function disableForm(state){
	$("form#main-form").find(":input:not(:hidden)").attr('disabled', state)
}

$(document).ready(function() {
	getAppList();
	//post the form via ajax
	$("form#main-form").submit(function(event) {
		event.preventDefault();
		if ($("#app-list option:selected").attr("value") == 'none') {
			$("#message-box").html(''+
				'<div data-alert class="alert-box alert">'+
					 'You have to select an app type'+
				 	 '<a href="#" class="close">&times;</a>'+
		    '</div>'+
		    '');
			$(document).foundation('alert');
			return false;
		} else if (document.getElementById('data-file').value == '') {
			$("#message-box").html(''+
				'<div data-alert class="alert-box alert">'+
					 'Bad request: No file attached.'+
				 	 '<a href="#" class="close">&times;</a>'+
		    '</div>'+
			'');
			$(document).foundation('alert');
			return false;
		}

  		var formData = new FormData($(this)[0]);
  		formData.append('appID', $(this).find("#app-list option:selected").attr("appid"));
  		disableForm(true);
        var uuid = generateUUID();
        //append the progress bar to the UI
        $('#message-box').html(''+
            '<div class="progress success">'+
                '<span class="meter" style="width: 0%"></span>'+
            '</div>');
        var progressBar = $('.meter');

        function updateProgressInfo() { 
			$.getJSON('/uploadProgress/'+uuid, function(data) { 
				console.log(data);
				progressBar.css({ width: parseInt(data['progress'])+'%' });
				progressBar.text(data['state']);
				if (data['state'] == 'Done')
					window.clearInterval(window.checkProgress);
			});
        }
        
        window.checkProgress = window.setInterval(updateProgressInfo, 1000);
		$.ajax({
			url: '/download/?X-Progress-ID='+uuid,
			type: 'POST',
			data: formData,
			async: true,
			cache: false,
			contentType: false,
			processData: false,
			statusCode: {
				400: function() {
						$("#message-box").html(''+
	  					'<div data-alert class="alert-box alert">'+
	 						 'Bad request: No file attached.'+
	  					 	 '<a href="#" class="close">&times;</a>'+
					    '</div>'+
					    '');
						$(document).foundation('alert');
				}
			},
			success: function(response) {
				$("#message-box").html(''+
					'<div data-alert class="alert-box success">'+
						 'File was processed successfully'+<commit_msg>Fix for funny gunicorn workers progress checking<commit_after>function generateUUID() {
    var d = new Date().getTime();
    var uuid = 'xxxxxxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        var r = (d + Math.random()*16)%16 | 0;
        d = Math.floor(d/16);
        return (c=='x' ? r : (r&0x7|0x8)).toString(16);
    });
    return uuid;
};

function disableForm(state){
	$("form#main-form").find(":input:not(:hidden)").attr('disabled', state)
}

$(document).ready(function() {
	getAppList();
	//post the form via ajax
	$("form#main-form").submit(function(event) {
		event.preventDefault();
		if ($("#app-list option:selected").attr("value") == 'none') {
			$("#message-box").html(''+
				'<div data-alert class="alert-box alert">'+
					 'You have to select an app type'+
				 	 '<a href="#" class="close">&times;</a>'+
		    '</div>'+
		    '');
			$(document).foundation('alert');
			return false;
		} else if (document.getElementById('data-file').value == '') {
			$("#message-box").html(''+
				'<div data-alert class="alert-box alert">'+
					 'Bad request: No file attached.'+
				 	 '<a href="#" class="close">&times;</a>'+
		    '</div>'+
			'');
			$(document).foundation('alert');
			return false;
		}

  		var formData = new FormData($(this)[0]);
  		formData.append('appID', $(this).find("#app-list option:selected").attr("appid"));
  		disableForm(true);
        var uuid = generateUUID();
        //append the progress bar to the UI
        $('#message-box').html(''+
            '<div class="progress success">'+
                '<span class="meter" style="width: 0%"></span>'+
            '</div>');
        var progressBar = $('.meter');

        function updateProgressInfo() { 
			$.getJSON('/uploadProgress/'+uuid, function(data) { 
				console.log(data);
				if (window.progressLevel < parseInt(data['progress']))
					window.progressLevel = parseInt(data['progress']);
				progressBar.css({ width: window.progressLevel+'%' });
				progressBar.text(data['state']);
				if (data['state'] == 'Done')
					window.clearInterval(window.checkProgress);
			});
        }

        window.progressLevel = 0;
        window.checkProgress = window.setInterval(updateProgressInfo, 1000);
		$.ajax({
			url: '/download/?X-Progress-ID='+uuid,
			type: 'POST',
			data: formData,
			async: true,
			cache: false,
			contentType: false,
			processData: false,
			statusCode: {
				400: function() {
						$("#message-box").html(''+
	  					'<div data-alert class="alert-box alert">'+
	 						 'Bad request: No file attached.'+
	  					 	 '<a href="#" class="close">&times;</a>'+
					    '</div>'+
					    '');
						$(document).foundation('alert');
				}
			},
			success: function(response) {
				$("#message-box").html(''+
					'<div data-alert class="alert-box success">'+
						 'File was processed successfully'+
{'fraction_non_alphanumeric': 0.21210468920392583, 'fraction_numerical': 0.008178844056706653, 'mean_word_length': 3.00509461426492, 'pattern_counts': {'":': 2, '<': 38, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '717586', 'n_tokens_mistral': 2067, 'n_tokens_neox': 1745, 'n_words': 350}