Pulling Data Back from the LRS: Correlation for Analysis

Source: Pulling Data Back from the LRS: Correlation for Analysis : Learning Solutions Magazine


“More than anything else, this is the most exciting part of xAPI. Before xAPI happened along, it was very difficult to build reports like this pulling together this data. Now, you can do it with the push of a button (and some code behind the scenes).”

If you’ve been following along in my series of articles, you’ve covered a lot of ground. And now, it’s time to bring it all together. In this final article in the series, we’re going to look at the reporting side of the examples used in the third article: “xAPI Can Tell You What They Learned from the Video.” In that article, we looked at sending the statements to record when someone played a video and what part of the video that user played. We also looked at one way to report which answer the user selected on a quiz asking about the video. Again, the question was “What is the first animal you see in the video?” Not exactly the deepest or most probing question, I know. But it does show if the person was paying attention.

In this final outing, we’re going to look at how you can pull that data back from the LRS. Using xAPI queries, we’ll show who answered the question, what their answer was, and if they played the relevant part of the video. This way we can find out whether the video is effective. Remember, there are three practical results we can get here:

  1. The average user watches the video, but gets the answer incorrect. This could potentially indicate the video is not effective.
  2. The average user does not watch the video, but does get the answer correct. This could indicate that the question was too simple.
  3. The average user who did watch the video answers the question correctly, and the average user who did not watch the video answers the question incorrectly. This would tend to indicate that both the question and the video are effective.

We’re hoping to see the report trend toward the third option.

But I’m not a programmer/developer

As usual, I will show code examples so you can see how I did things. But the process is what’s really important here, so I’ll do my best to describe that outside of the code.

We have to consider what we want to know. That means knowing what data we need, how to get it, and how we can piece it together. At the end of the day, the code is simple. The strategy is the more difficult thing to put together, and that can be made much easier. (A great place to start is with a fantastic book from Sean Putman and Janet Laane Effron titled Investigating Performance: Design and Outcomes with xAPI.)

Looking at the data

So, from the previous articles in this series, we’ve generated some statements. There are two we want to look at here. The first is the information the LRS knows about when I watched the video:

  1. {
  2.  “verb”: {
  3.    “id”: “http://adlnet.gov/expapi/verbs/Play”,
  4.    “display”: {
  5.      “en-US”: “Video Played”
  6.    }
  7.  },
  8.  “version”: “1.0.0”,
  9.  “timestamp”: “2017-08-19T13:37:22.625732+00:00”,
  10.  “object”: {
  11.    “definition”: {
  12.      “name”: {
  13.        “en-US”: “Big Buck Bunny Video”
  14.      },
  15.      “description”: {
  16.        “en-US”: “sample description”
  17.      }
  18.    },
  19.    “id”: “http://example.com/bigbuckbunnyvid.html”,
  20.    “objectType”: “Activity”
  21.  },
  22.  “actor”: {
  23.    “mbox”: “mailto:anthony@devlearn16.com”,
  24.    “name”: “anthony”,
  25.    “objectType”: “Agent”
  26.  },
  27.  “stored”: “2017-08-19T13:37:22.625732+00:00”,
  28.  “result”: {
  29.    “extensions”: {
  30.      “http://example.com/xapi/period_end”: 17.4,
  31.      “http://example.com/xapi/period_start”: 1.5
  32.    }
  33.  },
  34.  “id”: “5125d510-00c5-4431-a3aa-9918d688d437”,
  35.  “authority”: {
  36.    “mbox”: “mailto:techteam+xapi-tools@adlnet.gov”,
  37.    “name”: “xapi-tools”,
  38.    “objectType”: “Agent”
  39.  }

Let’s take a look at what we can learn from this:

  • Who played the video (in this case, it was me)
  • I played the video on August 19 at about 13:37 Zulu
  • The video I played was my favorite example: Big Buck Bunny
  • I played it from 1.5 seconds to 17.4 seconds
  • played the video (the specific verb is useful to know, as well!)

That’s a good bit of information. And we’ll be able to use all of it. Now, let’s look at what we know about my effort to answer the quiz question:

  1. {
  2.  “verb”: {
  3.    “id”: “http://adlnet.gov/expapi/verbs/answered”,
  4.    “display”: {
  5.      “en-US”: “answered”
  6.    }
  7.  },
  8.  “version”: “1.0.0”,
  9.  “timestamp”: “2017-08-19T13:38:26.793810+00:00”,
  10.  “object”: {
  11.    “definition”: {
  12.      “name”: {
  13.        “en-US”: “xAPI Video Quiz”
  14.      },
  15.      “description”: {
  16.        “en-US”: “Correlating quiz answers to video consumption”
  17.      }
  18.    },
  19.    “id”: “http://omnesLRS.com/xapi/quiz_tracker”,
  20.    “objectType”: “Activity”
  21.  },
  22.  “actor”: {
  23.    “mbox”: “mailto:anthony@devlearn16.com”,
  24.    “name”: “anthony”,
  25.    “objectType”: “Agent”
  26.  },
  27.  “stored”: “2017-08-19T13:38:26.793810+00:00”,
  28.  “result”: {
  29.    “extensions”: {
  30.      “http://example.com/xapi/location”: “15.6”
  31.    },
  32.    “response”: “Bunny”
  33.  },
  34.  “id”: “88291bfb-b7fb-4131-847b-e0445826461b”,
  35.  “authority”: {
  36.    “mbox”: “mailto:techteam+xapi-tools@adlnet.gov”,
  37.    “name”: “xapi-tools”,
  38.    “objectType”: “Agent”
  39.  }

Similar to the video statement, we can learn a bunch of stuff from this statement:

  • Someone answered the question (again, guilty)
  • answered the question (verbs matter)
  • I answered the question at 13:38 Zulu on August 19
  • I answered that specific question
  • “Bunny” was my answer
  • The answer can be found at 15.6 seconds into the video

Putting all of this together

So now we have a lot of information about this one consumer. It’s fairly easy to just eyeball the two statements and see that I watched the relevant part of the video, but I did answer the question incorrectly (the correct answer is “Bird”). But now let’s try that for a few thousand consumers. That’s not going to be so easy. We want a way to programmatically query all the relevant statements.

This is where strategy takes over: What is the exact question we want answered? I can see two possibilities:

  1. Of those who played the video, who answered the question and how did they answer?
  2. Of those who answered the question, how did they answer and did they play the video?

Essentially, this translates into one of two processes, each of which requires several steps:

  1. Of those who watched the video, who answered the question and how did they answer?
    • Query for statements where someone played that video. (Remember, you can’t query on extensions! So we have to get all the statements.)
    • Crawl through those statements for those who played the relevant bit of the video, and collect the agent IDs.
    • For each agent ID we collect, query for any statements where that agent answered the quiz question.
  2. Of those who answered the question, how did they answer and did they watch the video?
    • Query for statements where someone answered the question.
    • For each agent that answered the question, query for statements where that agent played the video.
    • Crawl through the video statements to see if the consumer played the relevant bits of the video. (Again, we can’t query for extensions; we must do this on the client side.)

At first glance, you might not see a difference between those processes. But there could be a huge difference here. Specifically, there’s likely to be many more statements for the video than for the question. Consumers may have watched the video several times. Or there may be a significant number who have watched the video, but haven’t progressed through the course to the quiz yet.

In the end, we may have the same amount of statements to process, but if we take the second option, we should have fewer queries to run. So, it’s more efficient to take the second route and start by querying for those who answered the test question first. And that is easily done. Using the ADL xAPI wrapper, the code looks like this :

  1. <quiz>
  2. var quizParams = ADL.XAPIWrapper.searchParams()
  3. quizParams[‘verb’] = “http://adlnet.gov/expapi/verbs/answered”;
  4. quizParams[‘activity’] = “http://omnesLRS.com/xapi/quiz_tracker”;
  5. //  Now, issue the query
  6.  var ret = ADL.XAPIWrapper.getStatements(quizParams);
  7. </quiz>

Looking at the code, we create a variable for the query parameters in line 1. In lines 2 and 3, we set the verb and activity IDs for which we want to query. In line 6, we send the query, assigning the returned statements to the variable “ret.”

Once we have the statements, we crawl through them and start building the next query :

  1. <quiz>
  2.         if (ret) {
  3.         for (i = 0; i < ret.statements.length; i++) {
  4.             var studentName = ret.statements[i].actor.mbox;
  5.             var studentAnswer = ret.statements[i].result.response;
  6.             var studentTS = ret.statements[i].timestamp + “
  7. “;
  8.             var answerLocation =        ret.statements[i].result.extensions[“http://example.com/xapi/location”];
  9. </quiz>

In line 1, we make sure that there were statements returned. If there are, then one at a time, we look at them and pull out the data we need, using the “for” loop defined in line 2. We’re collecting the student’s name (in this case it’s actually their email address), the answer selected, when they answered the question, and where the answer was provided in the video. This last one (on line 6) is by pulling from the result extension. Notice how we have to reference that, using the URL defined in that extension’s keyed pair from line 29 of the quiz statement seen above. And, the dotted notation for each of the data points is easy to follow:ret.statements[i].actor.mbox maps to the mbox defined in the actor object of the statement stored in the variable “ret.” And so on and so forth.

So now we have all the information we need for each of the statements where someone answered the question. Now, we need to see if they watched the video. This requires another query. Again, fairly easily built :

  1. var vidParams = ADL.XAPIWrapper.searchParams()
  2. vidParams[‘agent’] = ‘{“mbox”:”‘ + studentName + ‘”}’;
  3. vidParams[‘verb’] = “http://adlnet.gov/expapi/verbs/Play”;
  4. //Make sure you pay attention the CASE OF THE VERB!!!!!!!!!
  5. vidParams[‘activity’] = “http://example.com/bigbuckbunnyvid.html”;
  6. var vidRet = ADL.XAPIWrapper.getStatements(vidParams);

Note: First and foremost, take heed of the comment on line 4. Everything is case sensitive! You must query for the same case as you used in the original statements! So make sure you keep all of that consistent—I can’t stress that enough! (I may have lost several hours debugging that mistake. Sigh…)

So, same as the first query, we’re setting the verb and the activity IDs. But this time, we’re also using the user email address we collected from the quiz statements to search for any statements where that user played the videos. This time, we’re assigning the videos to “vidRet.”

I’ll spare you the code here, as it’s a little tedious, but I’ll include the full text below for the curious and adventurous. The process is straightforward, though: Look at each statement and see if the users played the segment of video containing the answer. We do this by looking at the result extensions for the period_start and period_end and comparing those to the answerLocation variable we defined in the quiz query-results example above. If the users played that segment of the video, then we set a variable called vidWatched to “true.” And if not, then we leave that variable as “false,” meaning they didn’t play that segment of the video. Then we build that line of the chart and move on to the next statement in the quiz query results, and do it all over again.

The finished product will look like Table 1.

Table 1: The result of the query

If we know the correct answer (Bird), then we can see who answered the question correctly and if they played that segment of the video. Now, from here, we could add code to check for correct answers, and if they played the video, and add a column to reflect that. I did not do that here, for the sake of simplicity. There’s already a lot going on with this page.

In closing…

And that’s it, folks! With only a few lines of code, we’re able to bring together two completely disparate sets of data, compare them, and then correlate that data to show if the video is effective or not. In this case, looking at the results, it is not!

Notice that of the six people who played the video, only three got the correct answer! That’s only 50 percent. That’s hardly effective. But now we can show that. We have the data to prove this. OK, technically not yet: We’d need far more data, as this sample size is far too small. But you can see how this can scale up quickly and easily. And at the end of the day, this, more than anything else, is the most exciting part of xAPI. Before xAPI happened along, it was very difficult to build reports like this pulling together this data. Now, you can do it with the push of a button (and some code behind the scenes). This is what makes xAPI special. This is what makes xAPI powerful. And this is why, in this author’s humble opinion, xAPI is the way we will track our consumers in the future. It shouldn’t be much of a stretch for you to see how, using similar queries to those I’ve used here, you could make courses adapt to a student’s results in another, prerequisite course. Or how you could build just about any other report you can imagine.

I really do hope you’ve found this series of articles helpful. I’ve tried to be as thorough as I can be without being too overwhelming. xAPI can be a little like the game Go: a moment to learn; a lifetime to master. But it doesn’t have to be. You can make it as complex or as simple as you want! It’s all up to you and your needs. All that power is there for you to use at your will. And no matter how complicated you need it to be, just remember this…

It all starts with four lines of code.


Below is the full text for this example. I hope you can find it useful!

Note to developers: Yes, this is a painful way to do this. It requires N-many queries based on how many people took the quiz. If 1,000 people took the quiz, we’re running 1,000 queries for the video statements. The point here is to illustrate the process, not necessarily the most efficient method. In this example, I can show two query processes. So it meets the needs of this article very nicely, although isn’t really “production ready .”

  1. <!doctype html>
  2. <head>
  3.   <meta charset=“utf-8”>
  4.   <meta http-equiv=“X-UA-Compatible” content=“IE=edge,chrome=1”>
  5.   <title>xAPI sample page</title>
  6.   <meta name=“description” content=“”>
  7.   <meta name=“author” content=“”>
  8.   <style>
  9.     table, th, td {
  10.         border: 1px solid black;
  11.         border-collapse: collapse;
  12.     }
  13. </style>
  14.     <script type=“text/javascript” src=“./js/cryptojs_v3.1.2.js”></script>
  15.     <script type=“text/javascript” src=“./js/verbs.js”></script>
  16.     <script type=“text/javascript” src=“./js/xapistatement.js”></script>
  17.     <script type=“text/javascript” src=“./js/xapiwrapper.js”></script>
  18. <script>
  19.     function config_LRS(){
  20. //  Tell the content where to send the xAPI statements
  21.             var conf = {
  22.               “endpoint” : “https://lrs.adlnet.gov/xapi/”,
  23.               “auth” : “Basic ” + toBase64(‘xapi-tools:xapi-tools’)
  24.             };
  25.     function get_statements(){
  26.         config_LRS();
  27. //  Start by getting the list of statements for those who answered the quiz question
  28. //  First, we set the parameters for the query:
  29.         var quizParams = ADL.XAPIWrapper.searchParams()
  30.         quizParams[‘verb’] = “http://adlnet.gov/expapi/verbs/answered”;
  31.         quizParams[‘activity’] = “http://omnesLRS.com/xapi/quiz_tracker”;
  32. //  Now, issue the query
  33.         var ret = ADL.XAPIWrapper.getStatements(quizParams);
  34.             console.log(“answered list: “);
  35.             console.log (ret);
  36.             var txt = ” “;
  37.             if (ret) {
  38. // walk through the list of “answer” statements to see what we have
  39.             for (i = 0; i < ret.statements.length; i++) {
  40.                 var studentName = ret.statements[i].actor.mbox;
  41.                 var studentAnswer = ret.statements[i].result.response;
  42.                 var studentTS = ret.statements[i].timestamp + “<br>“;
  43.                 var answerLocation = ret.statements[i].result.extensions[“http://example.com/xapi/location”];
  44. //  When we find a statement for someone who answered the question, search for statements
  45. //  for when/if that user played the video
  46. //  Set the parameters for the query for “Play”
  47.                 var vidParams = ADL.XAPIWrapper.searchParams()
  48.                 vidParams[‘agent’] = ‘{“mbox”:”‘ + studentName + ‘”}’;
  49.                 vidParams[‘verb’] = “http://adlnet.gov/expapi/verbs/Play”;
  50.                         // Make sure you pay attention to the CASE OF THE VERB!!!!!!!!!
  51.                 vidParams[‘activity’] = “http://example.com/bigbuckbunnyvid.html”;
  52. //  Send the query for statements where the student played this video
  53.                 var vidRet = ADL.XAPIWrapper.getStatements(vidParams);
  54.                 var vidWatched = false;
  55. //  Now walk through the Play statements
  56.                 for (x = 0; x < vidRet.statements.length; x++) {
  57.                         if (!(vidWatched))
  58. // Look to see if the user played the relevant segment of the video
  59.                         if (answerLocation > vidRet.statements[x].result.extensions[“http://example.com/xapi/period_start”])
  60.                             {
  61.                             if (answerLocation < vidRet.statements[x].result.extensions[“http://example.com/xapi/period_end”])
  62.                                 {
  63.                                 vidWatched = true;
  64.                                 console.log (“vidWatched = true“);
  65.                                 }
  66.                                 else { vidWatched = false;
  67.                                     console.log (“vidWatched = ” );
  68.                                 }
  69.                             }
  70.                             else { var vidWatched = false;
  71.                                     console.log (“vidWatched = ” );
  72.                                 }
  73.                 }
  74.                 var table = document.getElementById(“result_table”);
  75.                 var row = table.insertRow(i + 1);
  76.                 var cell0 = row.insertCell(0);
  77.                 cell0.innerHTML = i;
  78.                 var cell1 = row.insertCell(1);
  79.                 cell1.innerHTML = studentName;
  80.                 var cell2 = row.insertCell(2);
  81.                 cell2.innerHTML = studentAnswer;
  82.                 var cell3 = row.insertCell(3);
  83.                 cell3.innerHTML = vidWatched;
  84.             }
  85.         }
  86.     }
  87. </script>
  88. </head>
  89. <body>
  90. <button type=“button” onclick=“get_statements()”>Get Statements</button>
  91. <br/><br/><br/>
  92. <div id=“results”>
  93.     <table id=“result_table” style=“width:50%”>
  94.         <tr>
  95.             <td> # </td>
  96.             <td><b>Student Name</b></td>
  97.             <td><b>Student Answer</b></td>
  98.             <td><b>Video Watched</b></td>
  99.         </tr>
  100.     </table>
  101. </div>
  102. </body>
  103. </html>

Leave a Reply

Your email address will not be published. Required fields are marked *