-
Notifications
You must be signed in to change notification settings - Fork 0
/
webwear-collection.js
113 lines (99 loc) · 2.56 KB
/
webwear-collection.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
var Visit = Class.extend({
init: function(user,rawUrl,title){
this.user = user;
this.rawUrl = rawUrl;
this.cleanUrl = util.parseCleanUrl(rawUrl);
this.domain = util.parseDomain(rawUrl);
this.search = util.parseQueryParam(rawUrl);
this.title = title;
this.startTime = new Date();
this.endTime = null;
this.length = null;
},
endVisit: function(){
this.endTime = new Date();
this.length = this.endTime - this.startTime;
//criteria by which to store a visit... must be longer than 1 second
if (this.length > 1000){
chrome.extension.sendRequest(
{type:"storeVisit", data:this},
function(response) {
if (WebWearDebug) console.log(response);
}
);
}
}
});
var LogVisit = Visit.extend({
init: function(user,rawUrl,title){
this.actions = [];
this.lastAction = -1;
this._super(user,rawUrl,title);
},
endVisit: function(){
this.endTime = new Date();
this.length = this.endTime - this.startTime;
//close up any open actions
this.endAction();
chrome.extension.sendRequest(
{type:"logVisit", data:this},
function(response) {
if (WebWearDebug) console.log(response);
}
);
},
addShortAction: function(type){
if (this.actions.length > 0 && this.lastAction != -1 && this.actions[this.lastAction].end == null){
this.actions[this.actions.length-1].shortActions.push(
{
type: type,
time: new Date()
}
);
}
else{
this.actions.push(
{
type: type,
time: new Date()
}
);
}
},
startAction: function(type){
//close up any open actions
this.endAction();
//start new action
this.actions.push({
type: type,
start: new Date(),
end: null,
length: null,
shortActions: []
});
this.lastAction = this.actions.length - 1;
},
endAction: function(){
if (this.actions.length > 0 && this.lastAction != -1 && this.actions[this.lastAction].end == null){
this.actions[this.actions.length-1].end = new Date();
this.actions[this.actions.length-1].length = (new Date() - this.actions[this.actions.length-1].start);
}
}
});
var Task = Class.extend({
init: function(user,task,condition){
this.type = 'ExperimentTask';
this.user = user;
this.taskId = task;
this.condition = condition;
this.startTime = new Date();
this.endTime = null;
this.length = null;
this.answer = null;
},
endTask: function(answer){
this.endTime = new Date();
this.length = this.endTime - this.startTime;
this.answer = answer;
}
});