h5p / moodle-mod_hvp

H5P Plugin for Moodle
GNU General Public License v3.0
135 stars 172 forks source link

Send xAPI statements to a remote LRS #45

Open nadavkav opened 8 years ago

nadavkav commented 8 years ago

Is there any plans (roadmap) on adding an xAPI dispatcher? outside of Moodle, to an LRS? or inside Moodle, (1) into a custom hvp DB table (2) Moodle's mdl_logstore_standard_log ?

nadavkav commented 8 years ago

A quick wip... I have added adlnet xAPIWrapper to hvp (there are others too) and used it on two different LRS clouds (grassblade & watershedlrs) which worked great. using the following JS code

Added the following code to mod/hvp/view.php

// xAPI (ADL) js wrapper.
$PAGE->requires->js(new moodle_url($CFG->httpswwwroot . '/mod/hvp/xapi-jswrapper/dist/xapiwrapper.min.js'), true);
$PAGE->requires->jquery();
$PAGE->requires->js(new moodle_url($CFG->httpswwwroot . '/mod/hvp/js/xapi-stmt-dispatcher.js'), true);

And some basic JS code (xapi-stmt-dispatcher.js) that listens to xAPI events and send the statement to an external LRS

$(document).ready(function () {
    ADL.XAPIWrapper.changeConfig({
        'endpoint': 'https://sandbox.watershedlrs.com/api/organizations/2991/lrs/',
        "auth" : "Basic " + toBase64('username:password')

    });
    H5P.externalDispatcher.on('xAPI', function(event) {
        console.log(event.data.statement);
        var stmt = new ADL.XAPIStatement(
            event.data.statement.actor,
            event.data.statement.verb,
            event.data.statement.object);
        stmt.generateId();
        stmt.generateRegistration();
        console.log(JSON.stringify(stmt));
        ADL.XAPIWrapper.sendStatement(stmt);

    });
});
falcon-git commented 8 years ago

Thanks for sharing! We plan to add server side evaluation of answers and APIs so that third party plugins may send xAPI statements to LRS with secure server to server communication.

nadavkav commented 8 years ago

Super cool :-)

We discussed the above prototype today, and we plan to send all the xAPI statements directly into Moodle's log (mdl_logstore_standard_log) by extending the your ajax.php file. (have the above js code send the xAPI statements locally to Moodle)

What do you think?

Do you plan to have a local hvp special Moodle table to hold all the events that happen inside each h5p interaction?

falcon-git commented 8 years ago

On Drupal and WordPress H5P doesn't store the statements at all. Only makes them available for other plugins. Initially I would prefer doing the same on Moodle, but I think I have to study Moodle a bit more first. Perhaps we should do something along the lines you suggest instead. Is this a normal way of using Moodle's log? What is it normally used for?

nadavkav commented 8 years ago

@falcon-git , Is it Ok with you guys that I use the adlnet xAPIWrapper when sending PR with this patch?

garemoko commented 8 years ago

As mentioned here, I'd have the logstore plugin send all the statement server side (and handle re-sending when there's an error etc etc) rather than send them client side with the JS library.

falcon-git commented 8 years ago

I agree with @garemoko.

nadavkav commented 8 years ago

Agreed (thank you)

garemoko commented 8 years ago

Reflecting some more on this, it would be really cool if H5P were to be implemented as Moodle quiz question types. In that case, potentially all of the tracking could be handled by existing Moodle xAPI tracking code.

nadavkav commented 8 years ago

@garemoko you might be interested watching this: https://github.com/h5p/h5p-moodle-plugin/issues/104

polarbear717 commented 6 years ago

@nadavkav hello there, were are currently two students setting up moodle with the H5P plugin and connecting it to Learning Locker. We are not familiar with Java Script and just followed your suggested instructions to send the H5P xAPI Statements to Learning Locker. It all works fine, but the "result" Object is missing although it is generated. It seems like the xAPIWrapper doesnt catch it. Is there any solution to do so? xapi_statements

nadavkav commented 6 years ago

@polarbear717 , both LL and H5P changed so much since this code was used, and also it was only a prototype. which eventually was not the proper way to go about it. Now, I use https://moodle.org/plugins/logstore_xapi to send all Moodle events (including H5P) to LL.

H5P JS is already sending xAPI into Moodle and store them in a local table. better use a Moodle observer to catch them on the server side.

polarbear717 commented 6 years ago

@nadavkav thank you alot for your support. Is there any special solution you could recommend for setting up the Moodle observer or a ready to run one out there? (We just need the xAPI Statements from H5P to evaluate the quality of our created courses, especially the "result" object)

nadavkav commented 6 years ago

There is no specific H5P event that you can observe (listen to) when a client side (JS) activity finishes The xAPI statement is saved: https://github.com/h5p/h5p-moodle-plugin/blob/master/classes/xapi_result.php#L116 But you might like to observer Moodle core grade update events for hvp? https://github.com/h5p/h5p-moodle-plugin/blob/582e10fc31576e68982ff8cf92b7bb681a6d3167/classes/user_grades.php#L81

polarbear717 commented 6 years ago

I am not sure if I got it right, does the Moodle core grade update happen everytime someone answers a question from some sort of hvp course and provides information about their selected answer or does it trigger when the person finishes the course and I am not able to see the individual answers they selected? For example a course with two multiple choice questions:

1.Question 5 + 4 = ?

  1. Answer 7
  2. Answer 8
  3. Answer 9
  4. Answer 10

The student selects the 2nd answer. Does it trigger the moodle core grade update? Am I able to see he selected answer 2 , or do I just get the feedback 0/1 Points?

2.Question 3 * 6 = ?

  1. Answer 18
  2. Answer 19
  3. Answer 20
  4. Answer 21

The student selects the 1st answer. The course is completed and now the moodle core grade update is triggerd, I receive the information the student scored 1/2 Points but no further information?

nadavkav commented 6 years ago

I am not entirely sure what do you mean when you refer to a "course"? Is it a H5P activity? (If YES... than Moodle update a user's grade after an attempt to answer it finishes)

polarbear717 commented 6 years ago

My bad, course is indeed the wrong word, "class" would have made much more sense. But anyway your assumption, that I´m referrering to the H5P activitys, is correct.

Thank you for your patience and support 👍 keep up the good work

flxzt commented 6 years ago

Hi nadavkay, sorry to hijack this issue thread for our problem. I'm working with polarbear717 and I am very interested on how you managed to catch and store the xapi statements in the logstore. Unfortunatly we both have no experience in PHP/JS, so we're a little bit stuck (We have the same configuration with H5P, Moodle and learninglocker). The code you used would be greatly appreciated:) Kind regards, Felix