Commit cbaba5aa by Will Daly

Add event tracking for student training and image upload

parent c80d9141
...@@ -271,8 +271,6 @@ class OpenAssessmentBlock( ...@@ -271,8 +271,6 @@ class OpenAssessmentBlock(
else: else:
return False return False
@property @property
def in_studio_preview(self): def in_studio_preview(self):
""" """
...@@ -649,4 +647,3 @@ class OpenAssessmentBlock( ...@@ -649,4 +647,3 @@ class OpenAssessmentBlock(
return key.to_deprecated_string() return key.to_deprecated_string()
else: else:
return unicode(key) return unicode(key)
describe("OpenAssessment.FileUploader", function() {
var fileUploader = null;
var TEST_URL = "http://www.example.com/upload";
var TEST_IMAGE = {
data: "abcdefghijklmnopqrstuvwxyz",
name: "test.jpg",
size: 10471,
type: "image/jpeg"
};
var TEST_CONTENT_TYPE = "image/jpeg";
beforeEach(function() {
fileUploader = new OpenAssessment.FileUploader();
});
it("logs a file upload event", function() {
// Stub the AJAX call, simulating success
var successPromise = $.Deferred(
function(defer) { defer.resolve(); }
).promise();
spyOn($, 'ajax').andReturn(successPromise);
// Stub the event logger
spyOn(Logger, 'log');
// Upload a file
fileUploader.upload(TEST_URL, TEST_IMAGE, TEST_CONTENT_TYPE);
// Verify that the event was logged
expect(Logger.log).toHaveBeenCalledWith(
"openassessment.upload_file", {
contentType: TEST_CONTENT_TYPE,
imageName: TEST_IMAGE.name,
imageSize: TEST_IMAGE.size,
imageType: TEST_IMAGE.type
}
);
});
});
\ No newline at end of file
...@@ -8,7 +8,7 @@ PUT requests on the server. ...@@ -8,7 +8,7 @@ PUT requests on the server.
Args: Args:
url (string): The one-time URL we're uploading to. url (string): The one-time URL we're uploading to.
data (object): The object to upload, which should have properties: imageData (object): The object to upload, which should have properties:
data (string) data (string)
name (string) name (string)
size (int) size (int)
...@@ -20,18 +20,32 @@ Returns: ...@@ -20,18 +20,32 @@ Returns:
*/ */
OpenAssessment.FileUploader = function() { OpenAssessment.FileUploader = function() {
this.upload = function(url, data, contentType) { this.upload = function(url, imageData, contentType) {
return $.Deferred( return $.Deferred(
function(defer) { function(defer) {
$.ajax({ $.ajax({
url: url, url: url,
type: 'PUT', type: 'PUT',
data: data, data: imageData,
async: false, async: false,
processData: false, processData: false,
contentType: contentType, contentType: contentType,
}).done( }).done(
function(data, textStatus, jqXHR) { defer.resolve(); } function(data, textStatus, jqXHR) {
// Log an analytics event
Logger.log(
"openassessment.upload_file",
{
contentType: contentType,
imageName: imageData.name,
imageSize: imageData.size,
imageType: imageData.type
}
);
// Return control to the caller
defer.resolve();
}
).fail( ).fail(
function(data, textStatus, jqXHR) { function(data, textStatus, jqXHR) {
defer.rejectWith(this, [textStatus]); defer.rejectWith(this, [textStatus]);
......
...@@ -17,3 +17,10 @@ if (typeof OpenAssessment == "undefined" || !OpenAssessment) { ...@@ -17,3 +17,10 @@ if (typeof OpenAssessment == "undefined" || !OpenAssessment) {
if (typeof window.gettext === 'undefined') { if (typeof window.gettext === 'undefined') {
window.gettext = function(text) { return text; }; window.gettext = function(text) { return text; };
} }
// Stub event logging if the runtime doesn't provide it
if (typeof window.Logger === 'undefined') {
window.Logger = {
log: function(event_type, data, kwargs) {}
};
}
\ No newline at end of file
...@@ -167,6 +167,15 @@ class StudentTrainingMixin(object): ...@@ -167,6 +167,15 @@ class StudentTrainingMixin(object):
corrections = student_training.assess_training_example( corrections = student_training.assess_training_example(
self.submission_uuid, data['options_selected'] self.submission_uuid, data['options_selected']
) )
self.runtime.publish(
self,
"openassessment.student_training_assess_example",
{
"submission_uuid": self.submission_uuid,
"options_selected": data["options_selected"],
"corrections": corrections
}
)
except student_training.StudentTrainingRequestError: except student_training.StudentTrainingRequestError:
msg = ( msg = (
u"Could not check student training scores for " u"Could not check student training scores for "
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment