Learning Analytics Documentation

1. Basic Queries

1.1 Get Latest xAPI statement

In this example we use a empty match to find everything, sort by timestamp (not statement.timestamp, which is a string), and project just the statement.timestamp value that we want to retrieve. We limit to one as we just want the latest statement.

{"$match": {} },
{"$sort": {"timestamp": -1}},
{"$project": {"statement.timestamp": 1} },
{"$limit": 1}

2. Activity queries over time

2.1 Get Moodle or Blackboard activity for a module broken down by day


  • is the vlemodid
  • is the startdate in ISO format
  • is the enddate in ISO format

Typically, we will know the module instance id, so first we have to query the UDD to find the vlemodid

In this example we start with match, using $or to find moodle or blackboard statements.

The next part looks for statements for a particular module.

This is in the follow element of the xAPI statement:


the URI style elements have a dot, which has to be replaced with &46; before the query can be made.

The next part of the query uses the group statement to group and count by day.

Finally we sort so the results are returned by date order.

[{ "$match":{ 
"$or":[ { "statement.context.platform":"Moodle" }, { "statement.context.platform":"Blackboard" } ],
"statement.context.extensions.http://xapi&46;jisc&46;ac&46;uk/courseArea.http://xapi&46;jisc&46;ac&46;uk/vle_mod_id":"<modid>" } },
{ "$match":{ "timestamp":{ "$gt":{ "$dte":"<startdate>" }, "$lt":{ "$dte":"<enddate>" } } } },
{ "$project":{ "_id":0, "timestamp":1 } },
{ "$group":
{ "_id":{ "dayOfMonth":{ "$dayOfMonth":"$timestamp" },
"month":{ "$month":"$timestamp" },
"year":{ "$year":"$timestamp" } },
"count":{ "$sum":1 } } },
{ "$sort":{ "_id.year":1, "_id.week":1, "_id.dayOfMonth":1 } } ]