<commit_before>/*
 * Function that sets up the home screen.
 */
'use strict';

// Call this function when the page loads (the "ready" event)
$(document).ready(function() {
	initializePage();
})

/*
 * Function that is called when the document is ready.
 */
function initializePage() {
	var self = this;

	var color0 = [0,95,150],
		color1 = [0,255,132];
	var historyLimit = 15000, // Show the last 15 seconds in the graph
		idealBreathingPeriod = 6000,
		activeLineColor = [255,255,255],
		idealLineColor = [0,255,132],
		resultLineColor = [255,255,255],
		lineWidth = 2,
		progressLimit = 10; // The number of days that sould fit into the progress graph
	
	var breathCanvas = new BreathCanvas();
	var breathGraph = new BreathGraph();
	var breathResults = new BreathResults();
	var breathProgress = new BreathProgress();
	
	breathCanvas.init(color0, color1);
	breathGraph.init(historyLimit,activeLineColor,lineWidth,idealBreathingPeriod,idealLineColor);
	breathResults.init(historyLimit*2,resultLineColor,lineWidth);
	breathProgress.init(progressLimit,activeLineColor,lineWidth);

	var $contentPages = $('.content-page');

	breathGraph.onStart(function() {
		$('#active-finish-button').attr('disabled', false);
	});
	
	breathCanvas.bind(function(y) {
		breathGraph.appendData.call(breathGraph,y);
	});

	breathProgress.bind(function(session) { // Bind session click event
		$contentPages.hide();
		$("#results-page").show();
		breathResults.populate.call(breathResults, session.data, session.date);
	});
	
	breathResults.backButton(function() {
		$contentPages.hide();
		$("#progress-page").show();
	});

	breathResults.saveData(function(data) {
		

		var guide = $("#guidanceCheckbox");
		var guidance = "false";
		if (guide.length) {
			guidance = "true";
		}
		
		var json = {"data": data, "guidance": guidance};
		console.log(json);
		$.post('/breathingsession/new', json, function(response) {
			$contentPages.hide();
			$("#progress-page").show();
			if (response !== undefined && response.message) {
				breathProgress.showMessage(response.message);
			} else {
				breathProgress.updateSessions.call(breathProgress, true);
			}
		});
	});

	var $userMenu = $('#loggedInUser .menu');
	var menuVisible = false;
	var closeMenu = function(){
		$userMenu.clearQueue().slideUp(100);
		console.log('closing');
		menuVisible = false;
	}
	$('.page-content').click(function(){if(menuVisible)closeMenu()});
	$('#loggedInUser .handle').click(function() {
		if (menuVisible) {
			closeMenu();
		} else {
			menuVisible = true;
			$userMenu.clearQueue().slideDown(100);
		}
	});

	$(".start-button").on("click", function(e) {
		// google analytics
		ga("send", "event", "start", "click");
		$contentPages.hide();
		$('#active-finish-button').attr('disabled', true);
		$("#active-page").show(0, function() {
			breathCanvas.start.call(breathCanvas);
			breathGraph.start.call(breathGraph);
		});
	});

	$(".finish-button").on("click", function(e) {
		$contentPages.hide();
		breathCanvas.stop.call(breathCanvas);
		var data = breathGraph.stop.call(breathGraph);
		$("#results-page").show();
		breathResults.populate.call(breathResults,data);
	});

	$(".home-button, .quit-button, .back-button").on("click", function(e) {
		$contentPages.hide();
		$("#start-page").show();
	});

	$(".help-button").on("click", function(e) {
		// google analytics
		ga("send", "event", "help", "click");
		$contentPages.hide();
		$("#help-page").show();
	});

	$(".progress-button").on("click", function(e) {
		$contentPages.hide();
		$("#progress-page").show();
		breathProgress.updateSessions.call(breathProgress, false);<commit_msg>Adds ga event for quit button.<commit_after>/*
 * Function that sets up the home screen.
 */
'use strict';

// Call this function when the page loads (the "ready" event)
$(document).ready(function() {
	initializePage();
})

/*
 * Function that is called when the document is ready.
 */
function initializePage() {
	var self = this;

	var color0 = [0,95,150],
		color1 = [0,255,132];
	var historyLimit = 15000, // Show the last 15 seconds in the graph
		idealBreathingPeriod = 6000,
		activeLineColor = [255,255,255],
		idealLineColor = [0,255,132],
		resultLineColor = [255,255,255],
		lineWidth = 2,
		progressLimit = 10; // The number of days that sould fit into the progress graph
	
	var breathCanvas = new BreathCanvas();
	var breathGraph = new BreathGraph();
	var breathResults = new BreathResults();
	var breathProgress = new BreathProgress();
	
	breathCanvas.init(color0, color1);
	breathGraph.init(historyLimit,activeLineColor,lineWidth,idealBreathingPeriod,idealLineColor);
	breathResults.init(historyLimit*2,resultLineColor,lineWidth);
	breathProgress.init(progressLimit,activeLineColor,lineWidth);

	var $contentPages = $('.content-page');

	breathGraph.onStart(function() {
		$('#active-finish-button').attr('disabled', false);
	});
	
	breathCanvas.bind(function(y) {
		breathGraph.appendData.call(breathGraph,y);
	});

	breathProgress.bind(function(session) { // Bind session click event
		$contentPages.hide();
		$("#results-page").show();
		breathResults.populate.call(breathResults, session.data, session.date);
	});
	
	breathResults.backButton(function() {
		$contentPages.hide();
		$("#progress-page").show();
	});

	breathResults.saveData(function(data) {
		

		var guide = $("#guidanceCheckbox");
		var guidance = "false";
		if (guide.length) {
			guidance = "true";
		}
		
		var json = {"data": data, "guidance": guidance};
		console.log(json);
		$.post('/breathingsession/new', json, function(response) {
			$contentPages.hide();
			$("#progress-page").show();
			if (response !== undefined && response.message) {
				breathProgress.showMessage(response.message);
			} else {
				breathProgress.updateSessions.call(breathProgress, true);
			}
		});
	});

	var $userMenu = $('#loggedInUser .menu');
	var menuVisible = false;
	var closeMenu = function(){
		$userMenu.clearQueue().slideUp(100);
		console.log('closing');
		menuVisible = false;
	}
	$('.page-content').click(function(){if(menuVisible)closeMenu()});
	$('#loggedInUser .handle').click(function() {
		if (menuVisible) {
			closeMenu();
		} else {
			menuVisible = true;
			$userMenu.clearQueue().slideDown(100);
		}
	});

	$(".start-button").on("click", function(e) {
		// google analytics
		ga("send", "event", "start", "click");
		$contentPages.hide();
		$('#active-finish-button').attr('disabled', true);
		$("#active-page").show(0, function() {
			breathCanvas.start.call(breathCanvas);
			breathGraph.start.call(breathGraph);
		});
	});

	$(".finish-button").on("click", function(e) {
		$contentPages.hide();
		breathCanvas.stop.call(breathCanvas);
		var data = breathGraph.stop.call(breathGraph);
		$("#results-page").show();
		breathResults.populate.call(breathResults,data);
	});

	$(".home-button, .back-button").on("click", function(e) {
		$contentPages.hide();
		$("#start-page").show();
	});

	$(".quit-button").on("click", function(e) {
		$contentPages.hide();
		ga('send', 'event', 'quit_button', 'click');
		$("#start-page").show();
	});

	$(".help-button").on("click", function(e) {
		// google analytics
		ga("send", "event", "help", "click");
		$contentPages.hide();
		$("#help-page").show();
	});

	$(".progress-button").on("click", function(e) {
		$contentPages.hide();
		ga('send', 'event', 'progress_screen', 'opened');
		$("#progress-page").show();
		breathProgress.updateSessions.call(breathProgress, false);
{'fraction_non_alphanumeric': 0.18970627863109674, 'fraction_numerical': 0.017246025330099703, 'mean_word_length': 4.821960784313726, 'pattern_counts': {'":': 4, '<': 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': '462318', 'n_tokens_mistral': 2712, 'n_tokens_neox': 2423, 'n_words': 451}