Skip to content

Commit

Permalink
Completion time based on TLT
Browse files Browse the repository at this point in the history
  • Loading branch information
agordillo committed May 20, 2015
1 parent 1aadb78 commit 14b57fb
Show file tree
Hide file tree
Showing 13 changed files with 276 additions and 134 deletions.
2 changes: 1 addition & 1 deletion edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<script type="text/javascript" src="/js/VISH.ViewerAdapter.js"></script>
<script type="text/javascript" src="/js/VISH.Text.js"></script>
<script type="text/javascript" src="/js/VISH.Utils.js"></script>
<script type="text/javascript" src="/js/VISH.Utils.iso8601Parser.js"></script>
<script type="text/javascript" src="/js/VISH.Utils.Loader.js"></script>
<script type="text/javascript" src="/js/VISH.Messenger.js"></script>
<script type="text/javascript" src="/js/VISH.Messenger.Helper.js"></script>
Expand Down Expand Up @@ -156,7 +157,6 @@
<script type="text/javascript" src="/js/VISH.Editor.Tools.Menu.js"></script>
<script type="text/javascript" src="/js/VISH.Editor.Utils.js"></script>
<script type="text/javascript" src="/js/VISH.Editor.Utils.Loader.js"></script>
<script type="text/javascript" src="/js/VISH.Editor.Utils.iso8601Parser.js"></script>
<script type="text/javascript" src="/js/VISH.Editor.Utils.LOM.js"></script>
<script type="text/javascript" src="/js/VISH.Editor.Slideset.js"></script>
<script type="text/javascript" src="/js/VISH.Editor.Flashcard.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion js/VISH.Editor.EVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ VISH.Editor.EVideo = (function(V,$,undefined){
if(isNaN(cTime)){
cTime = 0;
}
var durationsPerUnit = VISH.Editor.Utils.iso8601Parser.getDurationPerUnit("PT"+ cTime + "S",true);
var durationsPerUnit = V.Utils.iso8601Parser.getDurationFromISOPerUnit("PT"+ cTime + "S",true);
$("#eVideochapters_hours").val(durationsPerUnit[4]);
$("#eVideochapters_minutes").val(durationsPerUnit[5]);
$("#eVideochapters_seconds").val(durationsPerUnit[6]);
Expand Down
2 changes: 1 addition & 1 deletion js/VISH.Editor.Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ VISH.Editor.Settings = (function(V,$,undefined){
}

if(presentation.TLT){
var durations = VISH.Editor.Utils.iso8601Parser.getDurationPerUnit(presentation.TLT);
var durations = V.Utils.iso8601Parser.getDurationFromISOPerUnit(presentation.TLT);
$("#tlt_hours").val(durations[4].toString());
$("#tlt_minutes").val(durations[5].toString());
$("#tlt_seconds").val(durations[6].toString());
Expand Down
30 changes: 17 additions & 13 deletions js/VISH.ProgressTracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ VISH.ProgressTracking = (function(V,$,undefined){

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


Expand All @@ -25,9 +25,9 @@ VISH.ProgressTracking = (function(V,$,undefined){
// 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);
objectives["lo_spent_time"].completed = true;
objectives["lo_spent_time"].progress = 1;
V.EventsNotifier.notifyEvent(V.Constant.Event.onProgressObjectiveUpdated,objectives["lo_spent_time"],false);
},minRequiredTime*1000);

//Quizzes
Expand Down Expand Up @@ -58,20 +58,24 @@ VISH.ProgressTracking = (function(V,$,undefined){
};

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

var currentPresentation = V.Viewer.getCurrentPresentation();
if(typeof currentPresentation.TLT != "undefined"){
var TLT = V.Utils.iso8601Parser.getDurationFromISO(currentPresentation.TLT);
if((typeof TLT == "number")&&(TLT > 0)){
_minRequiredTime = (0.5 * TLT);
}
}

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);
//Adjust lo_spent_time progress if is not 100%
if (objectives["lo_spent_time"].progress<1){
objectives["lo_spent_time"].progress = Math.min(1,V.TrackingSystem.getAbsoluteTime()/minRequiredTime);
}

var overallProgressMeasure = 0;
Expand Down Expand Up @@ -124,7 +128,7 @@ VISH.ProgressTracking = (function(V,$,undefined){
}

//Create an objective that requires to spent a minimum average time viewing the slides.
var timeObjective = new Objective("slide_average_time");
var timeObjective = new Objective("lo_spent_time");
if(hasScore){
timeObjective.completion_weight = 0.5;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @contributor Jason "Palamedes" Ellis -- https://github.com/palamedes
*/

VISH.Editor.Utils.iso8601Parser = (function(V,$,undefined){
VISH.Utils.iso8601Parser = (function(V,$,undefined){

var multiplicators = [ 31104000,2592000,604800,86400,3600,60,1];
/*
Expand All @@ -24,8 +24,8 @@ VISH.Editor.Utils.iso8601Parser = (function(V,$,undefined){
*/


var getDuration = function(period){
var durationPerUnit = getDurationPerUnit(period,true);
var getDurationFromISO = function(period){
var durationPerUnit = getDurationFromISOPerUnit(period,true);
if(durationPerUnit){
var durationInSeconds = 0;
var dL = durationPerUnit.length;
Expand All @@ -38,7 +38,7 @@ VISH.Editor.Utils.iso8601Parser = (function(V,$,undefined){
return null;
};

var getDurationPerUnit = function(period,distributeOverflow){
var getDurationFromISOPerUnit = function(period,distributeOverflow){
var distributeOverflow = (typeof distributeOverflow == "boolean") ? distributeOverflow : false;
try {
var durationPerUnit = _parsePeriodString(period,distributeOverflow);
Expand Down Expand Up @@ -95,9 +95,87 @@ VISH.Editor.Utils.iso8601Parser = (function(V,$,undefined){
return duration;
};


var getISODurationFromSecs = function(n,bPrecise){
//From centisecs to secs
n = n*100;

/* Note: SCORM and IEEE 1484.11.1 require centisec precision
Parameters:
n = number of centiseconds
bPrecise = optional parameter; if true, duration will
be expressed without using year and/or month fields.
If bPrecise is not true, and the duration is long,
months are calculated by approximation based on average number
of days over 4 years (365*4+1), not counting the extra days
for leap years. If a reference date was available,
the calculation could be more precise, but becomes complex,
since the exact result depends on where the reference date
falls within the period (e.g. beginning, end or ???)
1 year ~ (365*4+1)/4*60*60*24*100 = 3155760000 centiseconds
1 month ~ (365*4+1)/48*60*60*24*100 = 262980000 centiseconds
1 day = 8640000 centiseconds
1 hour = 360000 centiseconds
1 minute = 6000 centiseconds */
var str = "P",
nCs = Math.max(n, 0),
nY = 0,
nM = 0,
nD = 0,
nH,
nMin;
// Next set of operations uses whole seconds
//with (Math) { //argumentatively considered harmful
nCs = Math.round(nCs);
if (bPrecise === true) {
nD = Math.floor(nCs / 8640000);
} else {
nY = Math.floor(nCs / 3155760000);
nCs -= nY * 3155760000;
nM = Math.floor(nCs / 262980000);
nCs -= nM * 262980000;
nD = Math.floor(nCs / 8640000);
}
nCs -= nD * 8640000;
nH = Math.floor(nCs / 360000);
nCs -= nH * 360000;
nMin = Math.floor(nCs / 6000);
nCs -= nMin * 6000;
//}
// Now we can construct string
if (nY > 0) {
str += nY + "Y";
}
if (nM > 0) {
str += nM + "M";
}
if (nD > 0) {
str += nD + "D";
}
if ((nH > 0) || (nMin > 0) || (nCs > 0)) {
str += "T";
if (nH > 0) {
str += nH + "H";
}
if (nMin > 0) {
str += nMin + "M";
}
if (nCs > 0) {
str += (nCs / 100) + "S";
}
}
if (str === "P") {
str = "PT0H0M0S";
}
// technically PT0S should do but SCORM test suite assumes longer form.
return str;
};


return {
getDuration : getDuration,
getDurationPerUnit : getDurationPerUnit
getDurationFromISO : getDurationFromISO,
getDurationFromISOPerUnit : getDurationFromISOPerUnit,
getISODurationFromSecs : getISODurationFromSecs
};

}) ();
Loading

0 comments on commit 14b57fb

Please sign in to comment.