| 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 |
1x
1x
1x
1x
182x
182x
182x
88x
182x
475x
164x
164x
1x
97x
1x
597x
210x
210x
205x
205x
310x
6x
| /*
* Metrics logging.
* This acts upon events that are deemed interesting enough to be recorded and sent to a log server for analysis.
*
* Copyright 2017 Raising the Floor - International
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License.
*
* The R&D leading to these results received funding from the
* Department of Education - Grant H421A150005 (GPII-APCP). However,
* these results do not necessarily represent the policy of the
* Department of Education, and you should not assume endorsement by the
* Federal Government.
*
* You may obtain a copy of the License at
* https://github.com/GPII/universal/blob/master/LICENSE.txt
*/
"use strict";
var fluid = require("infusion");
var gpii = fluid.registerNamespace("gpii");
fluid.defaults("gpii.metrics", {
gradeNames: ["fluid.modelComponent", "fluid.contextAware"],
contextAwareness: {
platform: {
checks: {
windows: {
contextValue: "{gpii.contexts.windows}",
gradeNames: "gpii.metrics.windows"
}
}
}
},
invokers: {
logMetric: {
func: "{eventLog}.logEvent",
args: ["{eventLog}", "metrics", "{arguments}.0", "{arguments}.1"]
}
},
members: {
sessionSolutions: {}
},
events: {
"onStartMetrics": null,
"onStopMetrics": null
},
modelListeners: {
"{lifecycleManager}.model.logonChange": {
funcName: "gpii.metrics.logonStateChanged",
args: [ "{that}", "{lifecycleManager}", "{change}.oldValue", "{change}.value" ]
}
},
listeners: {
"{lifecycleManager}.events.onSessionStart": "{that}.events.onStartMetrics",
"{lifecycleManager}.events.onSessionStop": [{
namespace: "metrics.session",
funcName: "gpii.metrics.sessionStopped",
args: ["{that}", "{arguments}.1.id"]
}, {
"func": "{that}.events.onStopMetrics",
"priority": "before:eventLog"
}],
"{lifecycleManager}.events.onSessionSnapshotUpdate": {
namespace: "metrics",
funcName: "gpii.metrics.snapshotUpdate",
args: ["{that}", "{arguments}.1.id", "{arguments}.2"]
}
}
});
/**
* Log the solutions as they're applied.
*
* @param that {Component} The gpii.metrics instance.
* @param sessionID {String} Session ID.
* @param originalSettings {Object} The original settings (only interested in the keys).
*/
gpii.metrics.snapshotUpdate = function (that, sessionID, originalSettings) {
var ids = fluid.keys(originalSettings);
var solutionIDs = that.sessionSolutions[sessionID];
if (!solutionIDs) {
solutionIDs = that.sessionSolutions[sessionID] = {};
}
// Log the solution IDs that haven't been logged.
fluid.each(ids, function (id) {
if (!solutionIDs[id]) {
that.logMetric("solution-applied", {
solutionID: id
});
solutionIDs[id] = true;
}
});
};
/**
* Removes the logged solution IDs for the session.
* @param that {Component} The gpii.metrics instance.
* @param sessionID {String} Session ID.
*/
gpii.metrics.sessionStopped = function (that, sessionID) {
delete that.sessionSolutions[sessionID];
};
/**
* A model state listener for {lifecycleManager}.model.logonChange.
* When the login state changes from "login" to "logout", log the solutions that did not get applied for that session.
*
* @param that {Component} The gpii.metrics instance.
* @param lifecycleManager {Component} The lifecycleManager instance.
* @param oldValue {object} The old value.
* @param newValue {object} The new value.
*/
gpii.metrics.logonStateChanged = function (that, lifecycleManager, oldValue, newValue) {
if (oldValue && oldValue.type === "login" && (newValue.type === "logout" || !newValue.inProgress)) {
var session = lifecycleManager.getSession(oldValue.userToken);
// The reason for this null checker is that the lifecyclaManager's "session" may be null after
// having logged on with a bogus token which terminated the request in error before the
// "session" could be created.
if (session) {
// Log the solution IDs that hadn't been applied.
var expectedSolutions = fluid.keys(session.model.activeConfiguration.lifecycleInstructions);
fluid.each(expectedSolutions, function (id) {
if (!session.model.appliedSolutions[id]) {
that.logMetric("solution-failed", {
solutionID: id
});
}
});
}
}
};
|