Writing time to lms using pipwerks wrapper

1,522 views
Skip to first unread message

Josh

unread,
May 5, 2011, 2:25:54 PM5/5/11
to eLearning Technology and Development
Experts,

Im trying to set time using the pipwerks wrapper. Below is my flash
code that fires off before i disconnect from the lms. Am I formating
this code wrong? Or is this a setting in the lms I have to turn on?
The rest of the scorm calls work fine in this flash object.

scorm.set("cmi.session_time", "PT02H23M03S");

My course time apears all zeros.


Thanks for any help you provide.

Marcel Muntaner

unread,
May 9, 2011, 6:04:10 AM5/9/11
to eLearning Technology and Development
Hi Josh,

I've been using a modified version of the Macromedia API for a long
time and swapped recently to pipwerk's.
I'm very happy with this change (thanks Philip for your work!), but I
found myself with the same issue as you, this API doesn't
automatically set the time.
Normally, I don't like the flash movie to comunicate directly with the
lms, or to trigger the API functions, so the solution I got is very
different from yours. I hope the solution may be useful as well to
other people, because it works well with both scorm 1.2 and 2004 and
once you've included the code in the API you don't need to worry about
saving the time, the API does it by itself.
Before giving you the code I just want to let you know that I've just
done some copy-paste, so all the credit should go to the Macromedia
guys, Claude Ostyn and, of course, Philip Hutchison.

(I'll keep some lines from Philip's code before each part of the code
I added, so you know where it goes)
The first step is to record the date when initialising the connection:

pipwerks.SCORM.connection.initialize = function(){

var success = false,
scorm = pipwerks.SCORM,
completionStatus = pipwerks.SCORM.data.completionStatus,
trace = pipwerks.UTILS.trace,
makeBoolean = pipwerks.UTILS.StringToBoolean,
debug = pipwerks.SCORM.debug,
traceMsgPrefix = "SCORM.connection.initialize ",

//next line added to record the time when the connection is
initialized
g_dtmInitialized = new Date();
...



The second and last step is to report the session time when
terminating the connection:

var success = false,
scorm = pipwerks.SCORM,
exitStatus = pipwerks.SCORM.data.exitStatus,
completionStatus = pipwerks.SCORM.data.completionStatus,
trace = pipwerks.UTILS.trace,
makeBoolean = pipwerks.UTILS.StringToBoolean,
debug = pipwerks.SCORM.debug,
traceMsgPrefix = "SCORM.connection.terminate ";


if(scorm.connection.isActive){

//next line added to set the session time
SCOReportSessionTime();
...



And you must add the code for the function called (I've put it at the
end of the file):

function SCOReportSessionTime() {
var success = false;
var dtm = new Date();

//in the next line you substract the time recorded when initialising
the connection from the present time.
var n = dtm.getTime() - g_dtmInitialized.getTime();
switch(scorm.version){

//the time format is different on scorm 1.2 or 2004, so we use
different conversions depending on the case
case "1.2" : success =
scorm.set("cmi.core.session_time",MillisecondsToCMIDuration(n));
break;
case "2004": success =
scorm.set("cmi.session_time",centisecsToISODuration(Math.floor(n/
10))); break;
}

}


//function to convert time to scorm 1.2 time format
function MillisecondsToCMIDuration(n) {
//Convert duration from milliseconds to 0000:00:00.00 format
var hms = "";
var dtm = new Date(); dtm.setTime(n);
var h = "0" + Math.floor(n / 3600000);
var m = "0" + dtm.getMinutes();
var s = "0" + dtm.getSeconds();
hms = h.substr(h.length-2)+":"+m.substr(m.length-2)+":";
hms += s.substr(s.length-2);
return hms
}


//function to convert time to scorm 2004 time format
function centisecsToISODuration(n) {
// Note: SCORM and IEEE 1484.11.1 require centisec precision
// Months calculated by approximation based on average number
// of days over 4 years (365*4+1), not counting the extra day
// every 1000 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
n = Math.max(n,0); // there is no such thing as a negative
duration
var str = "P";
var nCs = n;
// Next set of operations uses whole seconds
var nY = Math.floor(nCs / 3155760000);
nCs -= nY * 3155760000;
var nM = Math.floor(nCs / 262980000);
nCs -= nM * 262980000;
var nD = Math.floor(nCs / 8640000);
nCs -= nD * 8640000;
var nH = Math.floor(nCs / 360000);
nCs -= nH * 360000;
var 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;
}

I'll be keeping an eye on this topic, so if anyone has any question
I'll be happy to try to help! I hope my english to be understandable
enough!

in...@iiea-school.it

unread,
Jun 13, 2011, 11:04:10 AM6/13/11
to eLearning Technology and Development
Thank you for hack Marcel,

I've added two little things and I'd like to share that with you.

1. I've added at the start of theSCORM_API_wrapper.js file this line:

var g_dtmInitialized;

because I think that the scope of the g_dtmInitialized var must be
outside the pipwerks.SCORM.connection.initialize function, but I'm not
a programmer so maybe it is un-necessary.

2. if you also need to record the session time even tough the SCO is
incomplete add the SCOReportSessionTime(); function in the unload
event (index.html file or simply the html file that contain the swf)

window.onunload = function (){
if(scorm.connection.isActive){
SCOReportSessionTime();
scorm.quit();
}
}

I'll tested it only in a Scorm 1.2 SCO.

Matthew Terentjev

unread,
May 23, 2014, 10:11:27 AM5/23/14
to elearning-technolo...@googlegroups.com
Dear all,
 
I am having difficulties to make it work.... I am trying scorm to read back how much time student spent in the course. But it always returns 00:00:00. I am trying to:
 
var timespent = scorm.get("cmi.core.total_time");
  
      //If the the time was successfully retrieved...
      if(timespent){ 
     
         //...let's display the time in a page element named "timespent"
         document.getElementById("timespent").innerHTML = timespent; //use the name in the form
     
      }

Philip Hutchison

unread,
May 23, 2014, 11:51:18 AM5/23/14
to elearning-technolo...@googlegroups.com
If it's returning 00:00:00, you know the SCORM call is working; have you passed/saved any values via cmi.core.session_time?

I'm rusty on the timer portion of the spec, but I believe it's up to you to manage the timers; you provide the time spent in session via cmi.core.session_time (write-only), which will be added to cmi.core.total_time by the LMS. Then you can query cmi.core.total_time in a future launch.



--
You received this message because you are subscribed to the Google Groups "eLearning Technology and Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elearning-technology-and...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ethan Estes

unread,
May 23, 2014, 12:20:47 PM5/23/14
to elearning-technolo...@googlegroups.com
in SCORM 1.2 its up to you to supply the time in session_time that you can get back via total_time.

In SCORM 2004 the LMS can track its own session_time and put it in the cmi object if the content does not push its own session_time value before terminate.

May 23, 2014 at 11:51 AM
If it's returning 00:00:00, you know the SCORM call is working; have you passed/saved any values via cmi.core.session_time?

I'm rusty on the timer portion of the spec, but I believe it's up to you to manage the timers; you provide the time spent in session via cmi.core.session_time (write-only), which will be added to cmi.core.total_time by the LMS. Then you can query cmi.core.total_time in a future launch.




--
You received this message because you are subscribed to the Google Groups "eLearning Technology and Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elearning-technology-and...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
May 23, 2014 at 10:11 AM

--
-EÆ
Reply all
Reply to author
Forward
0 new messages