<commit_before>var Device = require('utils/Device');
var Log = require('utils/Log');
var Quizzes = require('objects/Quizzes');
var Tests = require('objects/Tests');
var Tutorials = require('objects/Tutorials');
var User = require('objects/User');
var UserAttempt = require('objects/UserAttempt');

var MAX_TESTS = 5;

var _attempt;
var _lesson;
var _tests;
var _tutorials;
var _view;
var _user = User.getUser();

function display_tutorial(tutorial) {
	_view = Alloy.createController('lessons/tutorial', {parent: $, tutorial: tutorial});
	
	$.content.removeAllChildren();
	$.content.add(_view.getView());
	
	$.btnContinue.removeEventListener('click', $.advance);
	$.btnContinue.addEventListener('click', $.advance);
}

function display_quiz(quiz) {
	_view = Alloy.createController('lessons/quiz', {parent: $, quiz: quiz, type: "quiz", attempt: _attempt});
	
	$.content.removeAllChildren();
	$.content.add(_view.getView());
	
	$.btnContinue.removeEventListener('click', $.advance);
}

function display_test(test) {
	_view = Alloy.createController('lessons/quiz', {parent: $, quiz: test, type: "test", attempt: _attempt});
	
	$.content.removeAllChildren();
	$.content.add(_view.getView());
	
	$.btnContinue.removeEventListener('click', $.advance);
}

function display_outoflives() {
	_view = Alloy.createController('lessons/outoflives', {parent: $});
	
	$.content.removeAllChildren();
	$.content.add(_view.getView());
	
	$.btnContinue.removeEventListener('click', $.advance);
}

function display_completed() {
	_view = Alloy.createController('lessons/completed', {parent: $, attempt: _attempt, user: _user});
	
	$.content.removeAllChildren();
	$.content.add(_view.getView());
	
	$.btnContinue.removeEventListener('click', $.advance);
}

function display_results() {
	_view = Alloy.createController('lessons/results', {parent: $, attempt: _attempt, user: _user});
	
	$.content.removeAllChildren();
	$.content.add(_view.getView());
	
	$.btnContinue.removeEventListener('click', $.advance);
}

function start(attempt) {
	_attempt = attempt;
	
	display_tutorial(_tutorials[0]);
	$.stats();
}

function check_load(attempt) {
	if (attempt === undefined) {
		UserAttempt.create(_lesson.id, start);
	} else {
		_attempt = attempt;
		
		if (_attempt.is_completed) {
			display_completed();
		}
		else if (_attempt.lives <= 0) {
			display_outoflives();
			$.stats();
		} else {
			if (_attempt.progress.flow == "quizzes") {
				_attempt.progress.flow = "tutorials";
			}
			
			load(_attempt);
		}
	}
}

function load(attempt) {
	_attempt = attempt;

	switch (_attempt.progress.flow) {
		case "tutorials":
			display_tutorial(_tutorials[_attempt.progress.position]);
			break;
		case "quizzes":
			Quizzes.getQuiz(_tutorials[_attempt.progress.position].id, display_quiz);
			break;
		case "tests":
			display_test(_tests[_attempt.progress.position]);
			break;
		case "results":
			display_results();
			break;
		default:
			Log.info("Invalid flow: " + _attempt.progress.flow);
	}
	
	$.stats();
}

exports.restart = function() {
	Tests.randomize(_lesson.id);
	UserAttempt.create(_lesson.id, start);
};

exports.advance = function() {
	if (_attempt.lives > 0) {
		if (_attempt.progress.flow == "tutorials") {
			_attempt.progress.flow = "quizzes";
		} else if (_attempt.progress.flow == "quizzes") {
			if (_attempt.progress.position + 1 < _tutorials.length) {
				_attempt.progress.flow = "tutorials";
				_attempt.progress.position = _attempt.progress.position + 1;
			} else {
				_attempt.progress.flow = "tests";
				_attempt.progress.position = 0;
			}
		} else if (_attempt.progress.flow == "tests") {
			if (_attempt.progress.position + 1 < _tests.length && _attempt.progress.position + 1 < MAX_TESTS) {
				_attempt.progress.position = _attempt.progress.position + 1;
			} else {
				var questions = _tutorials.length + Math.min(_tests.length, MAX_TESTS);
				_attempt.progress.flow = "results";
				_attempt.progress.position = 0;
				_attempt.is_completed = true;
				_attempt.grade = (questions - (_lesson.lives - _attempt.lives)) / questions * 100;
				_user.custom_fields.points += _attempt.points;
				User.save(_user);
			}
		}
		
		UserAttempt.save(_attempt);
		load(_attempt);
	} else {
		display_outoflives();<commit_msg>Removed the continue button listener again just to make sure it was really gone :)<commit_after>var Device = require('utils/Device');
var Log = require('utils/Log');
var Quizzes = require('objects/Quizzes');
var Tests = require('objects/Tests');
var Tutorials = require('objects/Tutorials');
var User = require('objects/User');
var UserAttempt = require('objects/UserAttempt');

var MAX_TESTS = 5;

var _attempt;
var _lesson;
var _tests;
var _tutorials;
var _view;
var _user = User.getUser();

function display_tutorial(tutorial) {
	_view = Alloy.createController('lessons/tutorial', {parent: $, tutorial: tutorial});
	
	$.content.removeAllChildren();
	$.content.add(_view.getView());
	
	$.btnContinue.removeEventListener('click', $.advance);
	$.btnContinue.addEventListener('click', $.advance);
}

function display_quiz(quiz) {
	_view = Alloy.createController('lessons/quiz', {parent: $, quiz: quiz, type: "quiz", attempt: _attempt});
	
	$.content.removeAllChildren();
	$.content.add(_view.getView());
	
	$.btnContinue.removeEventListener('click', $.advance);
}

function display_test(test) {
	_view = Alloy.createController('lessons/quiz', {parent: $, quiz: test, type: "test", attempt: _attempt});
	
	$.content.removeAllChildren();
	$.content.add(_view.getView());
	
	$.btnContinue.removeEventListener('click', $.advance);
}

function display_outoflives() {
	_view = Alloy.createController('lessons/outoflives', {parent: $});
	
	$.content.removeAllChildren();
	$.content.add(_view.getView());
	
	$.btnContinue.removeEventListener('click', $.advance);
}

function display_completed() {
	_view = Alloy.createController('lessons/completed', {parent: $, attempt: _attempt, user: _user});
	
	$.content.removeAllChildren();
	$.content.add(_view.getView());
	
	$.btnContinue.removeEventListener('click', $.advance);
}

function display_results() {
	_view = Alloy.createController('lessons/results', {parent: $, attempt: _attempt, user: _user});
	
	$.content.removeAllChildren();
	$.content.add(_view.getView());
	
	$.btnContinue.removeEventListener('click', $.advance);
}

function start(attempt) {
	_attempt = attempt;
	
	display_tutorial(_tutorials[0]);
	$.stats();
}

function check_load(attempt) {
	if (attempt === undefined) {
		UserAttempt.create(_lesson.id, start);
	} else {
		_attempt = attempt;
		
		if (_attempt.is_completed) {
			display_completed();
		}
		else if (_attempt.lives <= 0) {
			display_outoflives();
			$.stats();
		} else {
			if (_attempt.progress.flow == "quizzes") {
				_attempt.progress.flow = "tutorials";
			}
			
			load(_attempt);
		}
	}
}

function load(attempt) {
	_attempt = attempt;

	switch (_attempt.progress.flow) {
		case "tutorials":
			display_tutorial(_tutorials[_attempt.progress.position]);
			break;
		case "quizzes":
			Quizzes.getQuiz(_tutorials[_attempt.progress.position].id, display_quiz);
			break;
		case "tests":
			display_test(_tests[_attempt.progress.position]);
			break;
		case "results":
			display_results();
			break;
		default:
			Log.info("Invalid flow: " + _attempt.progress.flow);
	}
	
	$.stats();
}

exports.restart = function() {
	Tests.randomize(_lesson.id);
	UserAttempt.create(_lesson.id, start);
};

exports.advance = function() {
	$.btnContinue.removeEventListener('click', $.advance);
	
	if (_attempt.lives > 0) {
		if (_attempt.progress.flow == "tutorials") {
			_attempt.progress.flow = "quizzes";
		} else if (_attempt.progress.flow == "quizzes") {
			if (_attempt.progress.position + 1 < _tutorials.length) {
				_attempt.progress.flow = "tutorials";
				_attempt.progress.position = _attempt.progress.position + 1;
			} else {
				_attempt.progress.flow = "tests";
				_attempt.progress.position = 0;
			}
		} else if (_attempt.progress.flow == "tests") {
			if (_attempt.progress.position + 1 < _tests.length && _attempt.progress.position + 1 < MAX_TESTS) {
				_attempt.progress.position = _attempt.progress.position + 1;
			} else {
				var questions = _tutorials.length + Math.min(_tests.length, MAX_TESTS);
				_attempt.progress.flow = "results";
				_attempt.progress.position = 0;
				_attempt.is_completed = true;
				_attempt.grade = (questions - (_lesson.lives - _attempt.lives)) / questions * 100;
				_user.custom_fields.points += _attempt.points;
				User.save(_user);
			}
		}
		
		UserAttempt.save(_attempt);
		load(_attempt);
	} else {
		display_outoflives();
{'fraction_non_alphanumeric': 0.1623353921454376, 'fraction_numerical': 0.003263022957697238, 'mean_word_length': 4.576348278102664, 'pattern_counts': {'":': 8, '<': 11, '<?xml version=': 0, '>': 5, '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': '1343585', 'n_tokens_mistral': 3250, 'n_tokens_neox': 2768, 'n_words': 509}