CompleteSession()

CompleteSession(currentSessionData : SessionData, contextExtension : Extension, resultExtension : Extension) : Boolean

Overview

The CompleteSession function should be called every time the user completes a session.

It:

  • Completes the current session.

  • Auto-generates an xAPI statement and sends it to Apex as a PIXOVR_SESSION_COMPLETE event.

  • Adds the given context extensions to the xAPI Statement context if it's not null.

  • Returns false if there is no logged in user or current session.

OnCompleteSessionSuccess is called when the session was completed successfully.

OnCompleteSessionFailed is called when the session was not started, unable to be completed otherwise or when the server is not able to be reached.

Parameters

The CompleteSession function has 3 optional parameters:

  • currentSessoinData:SessionData Use this parameter to pass the basic data that Apex uses to complete the reporting dashboard for finished sessions. Failure to include any of this data will result in the dashboard displaying the session report as being "incomplete". More information can be found in the SessionData section of this page.

  • contextExtension:Extension - Allows you to include any custom extensions in the context object. This is used to include any additional information you want to report that is not in the standard PIXOVR_SESSION_COMPLETE report. See Extensions for more details.

  • resultExtension:Extension identical to the contextExtension variable, but it adds extensions to the result object instead of the context object.

SessionData

Constructors

SessionData is a custom object that stores end of session data. It has two constructors:

  • The default constructor:

public SessionData() { }
  • Parameterized constructor:

public SessionData(float score, float scaled, float min, float max, int duration, bool completed, bool success)
{
    Score = score;
    ScaledScore = scaled;
    MinimumScore = min;
    MaximumScore = max;
    Duration = duration; 
    Complete = completed;
    Success = success;
}

The SessionData is used for two purposes, both of which are automatic but are explained here for completeness. First, many of the required properties of the "result" object in the generated xAPI statement get populated with data from the SessionData. Secondly, it is used to populate some additional top level properties that get sent in parallel with the xAPI statement that the Apex dashboard currently uses to for analytic display. The Example Data below demonstrates how this additional top level data is included.

Members

The following members are defined for SessionData:

  • score:float The final score the user achieved on the module.

  • scaled:float Usually the "score" value divided by the "max" value. The value can range from -1 to 1.

  • min:float The lowest possible score in the module (often 0, but it depends on the nature of your module).

  • max:float The highest possible score a user could achieve in your module

  • duration:int How long, in seconds, the session lasted.

  • completed:bool TRUE indicates the user made it all the way through to an expected completion point. FALSE indicates they quit early, usually through a menu option to quit or return to lobby.

  • success:bool TRUE indicates they achieved a high enough score or otherwise performed the necessary tasks to pass the module. FALSE indicates they did not.

Example Code

float score = 85;
float scaled = .85;
float min = 0;
float max = 100;
int duration = 120;
bool completed = true;
bool success = true;

Extension resultExtension = new Extension();
resultExtension.Add("https://pixovr.com/xapi/extension/score_average", "99.99");
resultExtension.AddSimple("expected_score_prediction", "100");
ApexSystem.CompleteSession(new SessionData(score, scaled, min, max, duration, completed, success), resultExtension: resultExtension);

Example Data

An example of the data that could get sent as part of a PIXOVR_SESSION_COMPLETE event:

id: 1fed6249-988e-4dfe-abca-6516678029ac
verb: {
    "id":"https://pixovr.com/xapi/verbs/completed_session",
    "display":{"en":"Completed Session"
    }
}
actor: {
    "mbox":"test@pixodev.com",
    "objectType":"Agent"
}

object: {
    "id":"https://pixovr.com/xapi/objects/34/Generic","objectType":"Activity"
    }
result: {
    "score":{
        "max":100,
        "min":0,
        "raw":85,
        "scaled":0.8500000238418579
    },
    "success":true,
    "duration":"PT2M",
    "completion":true,
    "extensions":{
        "https://pixovr.com/xapi/extension/score_average":"99.99",
        "https://pixovr.com/xapi/extension/expected_score_prediction":"100"
    }
}
context: {
    "platform":"OSXEditor",
    "revision":"1.00.00",
    "extensions":{
        "https://pixovr.com/xapi/extension/device_id":"C79C3829-B4D3-587A-8FB8-5BDACCE16553",
        "https://pixovr.com/xapi/extension/moduleIds":"34",
        "https://pixovr.com/xapi/extension/device_model":"MacBookPro16,1"
    },
    "registration":"92886b73-c959-4707-a51b-2efe7d48c99c"
}
timestamp: 2022-06-20T06:55:44.0616200Z
version: 1.0.3
score: 85
scoreMax: 100
scoreMin: 0
moduleName: 34
scoreScaled: 0.85
lessonStatus: passed
sessionDuration: 120

Last updated