-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
642 lines (511 loc) · 21.5 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
/*
* This file is part of IMS Caliper Analytics™ and is licensed to
* IMS Global Learning Consortium, Inc. (http://www.imsglobal.org)
* under one or more contributor license agreements. See the NOTICE
* file distributed with this work for additional information.
*
* IMS Caliper is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, version 3 of the License.
*
* IMS Caliper is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with this program. If not, see http://www.gnu.org/licenses/.
*/
/*
* AngularJS Controller for Sample Caliper Application
*
* This controller manages the logic for the Sample Application
* and uses the sensor service to send Caliper events
*
* @author: Prashant Nayak, Intellify Learning; Anthony Whyte, University of Michigan
*/
var app = angular.module('sampleCaliperApp', []);
app.controller('sampleAppCtrl', ['$scope', 'sampleAppSensorService',
function($scope, sampleAppSensorService, $window, $location) {
// Model(Flags) for controlling UI
$scope.syllabusActive = true;
$scope.readingActive = false;
$scope.quizActive = false;
// Model for Annotation (Tags)
$scope.currentTag = '';
$scope.readingTags = [];
// Model for Quiz
$scope.correctAnswer = false;
$scope.quizSubmitted = false;
$scope.currentAttempt = null; // set/get current assessment attempt
$scope.currentEvent = {};
$scope.init = function() {
console.log("INIT: Session started, Caliper = %o");
$scope.startSession(); // Fire Session Event
};
// Controller functions for UI
$scope.setSyllabusActive = function() {
$scope.navigateToHomePage(); // Fire Navigation Event
$scope.syllabusActive = true;
$scope.readingActive = false;
$scope.quizActive = false;
};
$scope.setReadingActive = function() {
$scope.navigateToReadingPage(); // Fire Navigation Event
$scope.readingActive = true;
$scope.quizActive = false;
$scope.syllabusActive = false;
};
$scope.setQuizActive = function() {
$scope.navigateToQuizPage(); // Fire Navigation Event
$scope.startQuiz(); // Fire Assessment Event
$scope.quizActive = true;
$scope.readingActive = false;
$scope.syllabusActive = false;
};
$scope.addTag = function() {
$scope.readingTags.push($scope.currentTag);
$scope.addTagsToPage($scope.readingTags); // Fire Annotation Event
$scope.currentTag = '';
};
$scope.submitQuiz = function() {
$scope.quizSubmitted = true;
// if (correctAnswer) {
// // $scope.submitQuizToSensor(3.0); // Fire Assessment Event
// } else {
// // $scope.submitQuizToSensor(0.0); // Fire Assessment Event
// }
// Generate an outcome against the quiz submission attempt
$scope.gradeQuiz();
};
$scope.retakeQuiz = function() {
$scope.quizSubmitted = false;
};
//////////////////////////////////////////////////////
// Controller functions for specific Caliper Events //
//////////////////////////////////////////////////////
$scope.startSession = function() {
// Actor LOGGED IN to edApp generating a new Session
// Event identifier
var id = "urn:uuid:d4618c23-d612-4709-8d9a-478d87808067";
// The Actor for the Caliper Event
var actor = sampleAppSensorService.currentUser;
// The Action for the Caliper Event (Hint: Use SessionActions)
var action = Caliper.Actions.loggedIn.term;
// The Object being interacted with by the Actor (edApp)
var obj = sampleAppSensorService.edApp;
// The edApp that is part of the Learning Context
var edApp = obj;
// Target
var target = sampleAppSensorService.courseHomePage;
// The LIS Course Section for the Event (part of Learning Context)
var group = sampleAppSensorService.course;
// The actor's membership, roles and status
var membership = sampleAppSensorService.membership;
// The actor's session
var sessionStart = new Date().toISOString();
var session = Caliper.Entities.EntityFactory().create(Caliper.Entities.Session, {
id: "https://imsglobal.org/sampleCaliperApp//session-123456789",
name: "session-123456789",
user: actor,
dateCreated: sessionStart,
startedAtTime: sessionStart
});
// Create the Session Event (Uncomment and set references to objects)
var event = Caliper.Events.EventFactory().create(Caliper.Events.SessionEvent, {
id: id,
actor: actor,
action: action,
object: obj,
eventTime: new Date().toISOString(),
target: target,
edApp: edApp,
group: group,
membership: membership,
session: session
});
// console.log('created session event %O', event);
$scope.currentEventType = 'Session Event (LOGGED IN)';
$scope.currentEvent = event;
// Send event
var opts = {sensor: sampleAppSensorService.getId, data: event};
var envelope = sampleAppSensorService.createEnvelope(opts);
sampleAppSensorService.sendEnvelope(envelope);
};
// Navigation Event
$scope.navigateToHomePage = function() {
// Event identifier
var id = "urn:uuid:0067a052-9bb4-4b49-9d1a-87cd43da488a";
// The Actor for the Event
var actor = sampleAppSensorService.currentUser;
// The Action for the Event
var action = Caliper.Actions.navigatedTo.term;
// The Object being interacted with by the Actor
var obj = sampleAppSensorService.syllabus;
// The target object within the Event Object
var target = sampleAppSensorService.courseHomePage;
// The edApp that is part of the Learning Context
var edApp = sampleAppSensorService.edApp;
// The LIS Course Section for the Event (part of Learning Context)
var group = sampleAppSensorService.course;
// The actor's membership, roles and status
var membership = sampleAppSensorService.membership;
// Referrer
var referrer = sampleAppSensorService.courseHomePage;
// Reset if target value exists
if ($scope.currentEvent.target) {
referrer = $scope.currentEvent.target;
}
if (target != sampleAppSensorService.courseHomePage) {
referrer = sampleAppSensorService.courseHomePage;
}
// The actor's session
var sessionStart = new Date().toISOString();
var session = Caliper.Entities.EntityFactory().create(Caliper.Entities.Session, {
id: "https://imsglobal.org/sampleCaliperApp//session-123456789",
name: "session-123456789",
user: actor,
dateCreated: sessionStart,
startedAtTime: sessionStart
});
// Create the Navigation Event
var event = Caliper.Events.EventFactory().create(Caliper.Events.NavigationEvent, {
id: id,
actor: actor,
action: action,
object: obj,
eventTime: new Date().toISOString(),
target: target,
referrer: referrer,
edApp: edApp,
group: group,
membership: membership,
session: session
});
// console.log('created navigation event %O', event);
$scope.currentEventType = 'Navigation Event';
$scope.currentEvent = event;
// Send event
var opts = {sensor: sampleAppSensorService.getId, data: event};
var envelope = sampleAppSensorService.createEnvelope(opts);
sampleAppSensorService.sendEnvelope(envelope);
};
// Exercise 1: add missing Navigation Event properties
$scope.navigateToReadingPage = function() {
// Event identifier
var id = "urn:uuid:3bdab9e6-11cd-4a0f-9d09-8e363994176b";
// The Actor for the Event
var actor = sampleAppSensorService.currentUser;
// The Action for the Event
var action = Caliper.Actions.navigatedTo.term;
// The Object (Reading) being interacted with by the Actor
var obj = sampleAppSensorService.reading;
// The target object (frame) within the Event Object
var target = sampleAppSensorService.readingFrame;
// The edApp that is part of the Learning Context
var edApp = sampleAppSensorService.edApp;
// The LIS Course Section for the Event (part of Learning Context)
var group = sampleAppSensorService.course;
// The actor's membership, roles and status
var membership = sampleAppSensorService.membership;
// Default referrer
var referrer = sampleAppSensorService.courseHomePage;
// Reset if target value exists
if ($scope.currentEvent.target) {
referrer = $scope.currentEvent.target;
}
// The actor's session
var sessionStart = new Date().toISOString();
var session = Caliper.Entities.EntityFactory().create(Caliper.Entities.Session, {
id: "https://imsglobal.org/sampleCaliperApp//session-123456789",
name: "session-123456789",
user: actor,
dateCreated: sessionStart,
startedAtTime: sessionStart
});
// Create the Navigation Event
var event = Caliper.Events.EventFactory().create(Caliper.Events.NavigationEvent, {
id: id,
actor: actor,
action: action,
object: obj,
eventTime: new Date().toISOString(),
target: target,
referrer: referrer,
edApp: edApp,
group: group,
membership: membership,
session: session
});
// console.log('created navigation event %O', event);
$scope.currentEventType = 'Navigation Event';
$scope.currentEvent = event;
// Send event
var opts = {sensor: sampleAppSensorService.getId, data: event};
var envelope = sampleAppSensorService.createEnvelope(opts);
sampleAppSensorService.sendEnvelope(envelope);
};
// Exercise 2: add an Annotation Event
$scope.addTagsToPage = function(tags) {
// Event identifier
var id = "urn:uuid:b2009c63-2659-4cd2-b71e-6e03c498f02b";
// The Actor for the Caliper Event
var actor = sampleAppSensorService.currentUser;
// The Action for the Caliper Event
var action = Caliper.Actions.tagged.term;
// The Object being interacted with by the Actor
var obj = sampleAppSensorService.readingFrame;
// The generated object (Tag annotation)
var generated = Caliper.Entities.EntityFactory().create(Caliper.Entities.TagAnnotation, {
id: "https://imsglobal.org/sampleCaliperApp/tags/7654",
annotator: actor,
annotated: obj,
tags: tags,
dateCreated: new Date().toISOString()
});
// The edApp that is part of the Learning Context
var edApp = sampleAppSensorService.edApp;
// The LIS Course Section for the Event (part of Learning Context)
var group = sampleAppSensorService.course;
// The actor's membership, roles and status
var membership = sampleAppSensorService.membership;
// The actor's session
var sessionStart = new Date().toISOString();
var session = Caliper.Entities.EntityFactory().create(Caliper.Entities.Session, {
id: "https://imsglobal.org/sampleCaliperApp//session-123456789",
name: "session-123456789",
user: actor,
dateCreated: sessionStart,
startedAtTime: sessionStart
});
// Create the Navigation Event
var event = Caliper.Events.EventFactory().create(Caliper.Events.AnnotationEvent, {
id: id,
actor: actor,
action: action,
object: obj,
eventTime: new Date().toISOString(),
generated: generated,
edApp: edApp,
group: group,
membership: membership,
session: session
});
console.log('created annotation event %O', event);
$scope.currentEventType = 'Annotation Event';
$scope.currentEvent = event;
// Send event
var opts = {sensor: sampleAppSensorService.getId, data: event};
var envelope = sampleAppSensorService.createEnvelope(opts);
sampleAppSensorService.sendEnvelope(envelope);
};
// Navigation Event
$scope.navigateToQuizPage = function() {
// Event identifier
var id = "urn:uuid:27734504-068d-4596-861c-2315be33a2a2";
// The Actor for the Event
var actor = sampleAppSensorService.currentUser;
// The Action for the Event
var action = Caliper.Actions.navigatedTo.term;
// The Object (Reading) being interacted with by the Actor
var obj = sampleAppSensorService.quiz;
// The target object within the Event Object
var target = sampleAppSensorService.quizPage;
// Default referrer
var referrer = sampleAppSensorService.courseHomePage;
// Reset if target value exists
if ($scope.currentEvent.target) {
referrer = $scope.currentEvent.target;
}
// Default navigation page
//var navigatedFrom = sampleAppSensorService.courseHomePage;
// Reset if target value exists
/**
if ($scope.currentEvent.target) {
navigatedFrom = $scope.currentEvent.target;
}
*/
// The edApp that is part of the Learning Context
var edApp = sampleAppSensorService.edApp;
// The LIS Course Section for the Event (part of Learning Context)
var group = sampleAppSensorService.course;
// The actor's membership, roles and status
var membership = sampleAppSensorService.membership;
// The actor's session
var sessionStart = new Date().toISOString();
var session = Caliper.Entities.EntityFactory().create(Caliper.Entities.Session, {
id: "https://imsglobal.org/sampleCaliperApp//session-123456789",
name: "session-123456789",
user: actor,
dateCreated: sessionStart,
startedAtTime: sessionStart
});
// Create the Navigation Event
var event = Caliper.Events.EventFactory().create(Caliper.Events.NavigationEvent, {
id: id,
actor: actor,
action: action,
object: obj,
eventTime: new Date().toISOString(),
target: target,
referrer: referrer,
edApp: edApp,
group: group,
membership: membership,
session: session
});
// console.log('created navigation event %O', event);
$scope.currentEventType = 'Navigation Event';
$scope.currentEvent = event;
// Send event
var opts = {sensor: sampleAppSensorService.getId, data: event};
var envelope = sampleAppSensorService.createEnvelope(opts);
sampleAppSensorService.sendEnvelope(envelope);
};
// Exercise 3: add a Quiz Start Event
$scope.startQuiz = function() {
// Event identifier
var id = "urn:uuid:dad88464-0c20-4a19-a1ba-ddf2f9c3ff33";
// The Actor for the Caliper Event
var actor = sampleAppSensorService.currentUser;
// The Action for the Caliper Event
var action = Caliper.Actions.started.term;
// The Object being interacted with by the Actor
var obj = sampleAppSensorService.quiz;
// The generated object (Attempt) within the Event Object
var attemptDate = new Date().toISOString();
var generated = Caliper.Entities.EntityFactory().create(Caliper.Entities.Attempt, {
id: "https://some-university.edu/deptOfPhysics/2014/physics101/assessment1/attempt1",
assignee: actor,
assignable: obj,
count: 1,
dateCreated: attemptDate,
startedAtTime: attemptDate
});
// Assign to scope object so that the submit quiz event can reference it
$scope.currentAttempt = generated;
// The edApp that is part of the Learning Context
var edApp = sampleAppSensorService.edApp;
// The LIS Course Section for the Event (part of Learning Context)
var group = sampleAppSensorService.course;
// The actor's membership, roles and status
var membership = sampleAppSensorService.membership;
// The actor's session
var sessionStart = new Date().toISOString();
var session = Caliper.Entities.EntityFactory().create(Caliper.Entities.Session, {
id: "https://imsglobal.org/sampleCaliperApp//session-123456789",
name: "session-123456789",
user: actor,
dateCreated: sessionStart,
startedAtTime: sessionStart
});
// Create the Assessment Event
var event = Caliper.Events.EventFactory().create(Caliper.Events.AssessmentEvent, {
id: id,
actor: actor,
action: action,
object: obj,
eventTime: new Date().toISOString(),
generated: generated,
edApp: edApp,
group: group,
membership: membership,
session: session
});
// console.log('created assessment event %O', event);
$scope.currentEventType = 'Assessment Event (STARTED)';
$scope.currentEvent = event;
// Send event
var opts = {sensor: sampleAppSensorService.getId, data: event};
var envelope = sampleAppSensorService.createEnvelope(opts);
sampleAppSensorService.sendEnvelope(envelope);
};
// Exercise 4: add a Quiz Submit Event
$scope.submitQuizToSensor = function() {
// Actor SUBMITTED Quiz Attempt
// Event identifier
var id = "urn:uuid:e5891791-3d27-4df1-a272-091806a43dfb";
// The Actor for the Caliper Event
var actor = sampleAppSensorService.currentUser;
// The Action for the Caliper Event (Hint: Use AssessmentActions)
var action = Caliper.Actions.submitted.term;
// The object (Attempt) being submitted
var obj = $scope.currentAttempt;
obj.setEndedAtTime(new Date().toISOString());
$scope.currentAttempt = obj;
// The edApp that is part of the Learning Context
var edApp = sampleAppSensorService.edApp;
// The LIS Course Section for the Event (part of Learning Context)
var group = sampleAppSensorService.course;
// The actor's membership, roles and status
var membership = sampleAppSensorService.membership;
// The actor's session
var sessionStart = new Date().toISOString();
var session = Caliper.Entities.EntityFactory().create(Caliper.Entities.Session, {
id: "https://imsglobal.org/sampleCaliperApp//session-123456789",
name: "session-123456789",
user: actor,
dateCreated: sessionStart,
startedAtTime: sessionStart
});
// Create the Assessment Event
var event = Caliper.Events.EventFactory().create(Caliper.Events.AssessmentEvent, {
id: id,
actor: actor,
action: action,
object: obj,
eventTime: new Date().toISOString(),
edApp: edApp,
group: group,
membership: membership,
session: session
});
// console.log('created assessment event %O', event);
$scope.currentEventType = 'Assessment Event (SUBMITTED)';
$scope.currentEvent = event;
// Send event
var opts = {sensor: sampleAppSensorService.getId, data: event};
var envelope = sampleAppSensorService.createEnvelope(opts);
sampleAppSensorService.sendEnvelope(envelope);
};
// Exercise 5: add a GradeEvent
$scope.gradeQuiz = function() {
// Event identifier
var id = "urn:uuid:04e27704-73bf-4d3c-912c-1b2da40aef8f";
// The Actor/Scorer for the Caliper Event. No Event.membership is set for this actor.
var actor = sampleAppSensorService.edApp;
// The Action for the Caliper Event (Hint: Use AssessmentActions)
var action = Caliper.Actions.graded.term;
// The object (Attempt) being submitted
var obj = $scope.currentAttempt;
var generated = Caliper.Entities.EntityFactory().create(Caliper.Entities.Result, {
id: obj.id + "/result/1235",
attempt: obj,
normalScore: 1.0, // TODO Render score dynamic
penaltyScore: 0.0,
extraCreditScore: 0.0,
curvedTotalScore: 0.0,
curveFactor: 0.0,
totalScore: 1.0, // TODO Render score dynamic
comment: "Caliper rocks!",
scoredBy: actor,
dateCreated: new Date().toISOString()
});
// Create the GradeEvent
var event = Caliper.Events.EventFactory().create(Caliper.Events.GradeEvent, {
id: id,
actor: actor,
action: action,
object: obj,
eventTime: new Date().toISOString(),
generated: generated
});
$scope.currentEventType = 'GradeEvent (GRADED)';
$scope.currentEvent = event;
// Send event
var opts = {sensor: sampleAppSensorService.getId, data: event};
var envelope = sampleAppSensorService.createEnvelope(opts);
sampleAppSensorService.sendEnvelope(envelope);
};
$scope.init();
}
]);