<commit_before>/*
 * Track the progress of a learner during a session.
 * Used by the SCORM API.
 */
VISH.ProgressTracking = (function(V,$,undefined){

	//Auxiliar vars
	var objectives = {};
	var minRequiredTime = 1;
	var hasScore = false;


	var init = function(animation,callback){
		_createObjectives();

		//Subscribe to events

		// Check if all slides have been viewed
		// V.EventsNotifier.registerCallback(V.Constant.Event.onEnterSlide, function(params){
		// });

		// Check the average time viewing slides
		minRequiredTime = _getMinRequiredTime();
		setTimeout(function(){
			objectives["slide_average_time"].completed = true;
			objectives["slide_average_time"].progress = 1;
			V.EventsNotifier.notifyEvent(V.Constant.Event.onProgressObjectiveUpdated,objectives["slide_average_time"],false);
		},minRequiredTime*1000);

		//Quizzes
		V.EventsNotifier.registerCallback(V.Constant.Event.onAnswerQuiz, function(params){
			V.Debugging.log("onAnswerQuiz");
			V.Debugging.log(params);
		});
	};

	var _getMinRequiredTime = function(){
		var AVERAGE_SLIDE_TIME = 4; //seg
		try {
			_minRequiredTime = V.Viewer.getCurrentPresentation().slides.length * AVERAGE_SLIDE_TIME;
		} catch(e) {
			_minRequiredTime = 1;
		}
		return _minRequiredTime;
	};

	//Return a value in a [0,1] scale
	var getProgressMeasure = function(){
		//Adjust slide_average_time progress if is not 100%
		if (objectives["slide_average_time"].progress<1){
			objectives["slide_average_time"].progress = Math.min(1,V.TrackingSystem.getAbsoluteTime()/minRequiredTime);
		}

		var overallProgressMeasure = 0;
		Object.keys(objectives).forEach(function(key){
			overallProgressMeasure += objectives[key].progress * objectives[key].completion_weight;
		});

		return overallProgressMeasure;
	};

	//Return a value in a [0,1] scale
	var getScore = function(){
		//TODO. Take into account objectives with scores.
		//
		var overallScore = 0;
		return 0;
	};

	var getHasScore = function(){
		return hasScore;
	};

	var getObjectives = function(){
		return objectives;
	};


	/////////////
	// Helpers
	/////////////

	var _createObjectives = function(){
		var presentation = V.Viewer.getCurrentPresentation();

		var slidesL = presentation.slides.length;
		for(var i=0; i<slidesL; i++){<commit_msg>Track score. SCORM API send scores now.<commit_after>/*
 * Track the progress of a learner during a session.
 * Used by the SCORM API.
 */
VISH.ProgressTracking = (function(V,$,undefined){

	//Constants
	var SCORE_THRESHOLD = 0.5;

	//Auxiliar vars
	var objectives = {};
	var minRequiredTime = 1;
	var hasScore = false;


	var init = function(animation,callback){
		_createObjectives();

		//Subscribe to events

		// Check if all slides have been viewed
		// V.EventsNotifier.registerCallback(V.Constant.Event.onEnterSlide, function(params){
		// });

		// Check the average time viewing slides
		minRequiredTime = _getMinRequiredTime();
		setTimeout(function(){
			objectives["slide_average_time"].completed = true;
			objectives["slide_average_time"].progress = 1;
			V.EventsNotifier.notifyEvent(V.Constant.Event.onProgressObjectiveUpdated,objectives["slide_average_time"],false);
		},minRequiredTime*1000);

		//Quizzes
		V.EventsNotifier.registerCallback(V.Constant.Event.onAnswerQuiz, function(params){

			//Find Objective
			if((params.quizId)&&(typeof objectives[params.quizId] != "undefined")){
				objectives[params.quizId].progress = 1;
				objectives[params.quizId].completed = true;

				if(typeof params.score == "number"){
					//params.score (i.e. the scaled quiz score) is number in a 0-10 scale.
					//If a customized score weight has been assigned to the quiz in the settings (field score), this should be reflected in the score_weight param.
					//objectives[params.quizId].score should be a score in a 0-1 scale. So, we will divide params.score/10
					var scaledScore = params.score/10;
					objectives[params.quizId].score = scaledScore;

					if(scaledScore >= SCORE_THRESHOLD){
						objectives[params.quizId].success = true;
					} else {
						objectives[params.quizId].success = false;
					}
				}

				V.EventsNotifier.notifyEvent(V.Constant.Event.onProgressObjectiveUpdated,objectives[params.quizId],false);
			}
		});
	};

	var _getMinRequiredTime = function(){
		var AVERAGE_SLIDE_TIME = 4; //seg
		try {
			_minRequiredTime = V.Viewer.getCurrentPresentation().slides.length * AVERAGE_SLIDE_TIME;
		} catch(e) {
			_minRequiredTime = 1;
		}
		return _minRequiredTime;
	};

	//Return a value in a [0,1] scale
	var getProgressMeasure = function(){
		//Adjust slide_average_time progress if is not 100%
		if (objectives["slide_average_time"].progress<1){
			objectives["slide_average_time"].progress = Math.min(1,V.TrackingSystem.getAbsoluteTime()/minRequiredTime);
		}

		var overallProgressMeasure = 0;
		Object.keys(objectives).forEach(function(key){
			overallProgressMeasure += objectives[key].progress * objectives[key].completion_weight;
		});

		return +(overallProgressMeasure).toFixed(6);
	};

	//Return a value in a [0,1] scale
	var getScore = function(){
		var overallScore = 0;
		Object.keys(objectives).forEach(function(key){
			if(typeof objectives[key].score == "number"){
				overallScore += objectives[key].score * objectives[key].score_weight;
			}
		});
		return +(overallScore).toFixed(6);
	};

	var getHasScore = function(){
		return hasScore;
	};

	var getObjectives = function(){
		return objectives;
	};


	/////////////
	// Helpers
	/////////////

	var _createObjectives = function(){
		var presentation = V.Viewer.getCurrentPresentation();

		var slidesL = presentation.slides.length;
		for(var i=0; i<slidesL; i++){
{'fraction_non_alphanumeric': 0.13440765007968833, 'fraction_numerical': 0.009739684788383213, 'mean_word_length': 4.042857142857143, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 4, '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': '5891374', 'n_tokens_mistral': 2025, 'n_tokens_neox': 1756, 'n_words': 392}