-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup_code
414 lines (325 loc) · 13.9 KB
/
backup_code
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
var url = 'https://api.keen.io/3.0/projects/54b6884e96773d36ffcb1d4a/queries/extraction?api_key=95f7c9d5d7af1a8dfc4d5bf22e9e21627ecb74716bd41b7033a5cfe779cc56b6f1d3e761230cd06474a6d837c3c565d3c43dcc1886bde939e6ef53aa78611d4d54aa25fa6c0bec1b645b353912235c076eebb03730719195c7b6e22f3f94bd450813848ae2648ca4267314d2a5e84603&event_collection=tracking'
//ToDo: INclude: https://github.com/jsmreese/moment-duration-format
var color_map = ["#326B5F","#70AC2D","#446329","#55B5A4","#70A460","#48BD5C"];
var color_page =["#784C20","#CB4B23","#CD9433","#CC7E4F"];
//Hellgrün
var map_extend_color =["#BAD8C0"];
//Rotweinfarben
var mosaiv_view_jump =["#AF2867"];
//Gelb
var header_map = ["#C5E641"]
var width = $(window).width()-100,
height = 100,
barHeight = 30,
barPadding = 5;
var session_timer = 300000; // 60 Minuten
//Create a ToolTip
var tooltip = d3.select("body").append("div")
.attr("id", "tooltip")
.style("opacity", 0.9)
.classed("hidden", true);
//d3.json(url, function(error, json) {
// if (error) return console.warn(error);
keen_data = json.result;
var nested_keen = d3.nest()
.key(function(d) { return d.fingerprint; })
.entries(keen_data);
//Sort by length of the array to have the biggest& most active first.
nested_keen.sort(function(a,b){
return b.values.length - a.values.length}
);
nested_keen.forEach(function (d,i) {
//Sort the data per user by the timestamp as the events that are send are async.
nested_keen[i].values.sort(function(a,b){return a.timestamp - b.timestamp});
var one_session = [];
var all_session = [];
//Sorted by fingerprint access individual user values
nested_keen[i].values.forEach(function (individual_value,e) {
if(e == nested_keen[i].values.length-1){
nested_keen[i].values[e].next_timestamp = nested_keen[i].values[e].timestamp + 1000; // + 1000 to get an idea of the last action - it is not shown if it has no duration;
}
else{
nested_keen[i].values[e].next_timestamp = nested_keen[i].values[e+1].timestamp;
}
var action_timestamp = moment(nested_keen[i].values[e].timestamp)
var action_next_timestamp = moment(nested_keen[i].values[e].next_timestamp)
var action_duration = moment.duration(action_next_timestamp.diff(action_timestamp));
nested_keen[i].values[e].time = action_duration.valueOf();
nested_keen[i].values[e].time_human = action_duration;
if(nested_keen[i].values[e].time > session_timer){
nested_keen[i].values[e].time_threshold_hit = true;
//console.log(nested_keen[i].key+" "+nested_keen[i].values[e].time_human);
}
else{
nested_keen[i].values[e].time_threshold_hit = false;
}
if(nested_keen[i].values[e].time_threshold_hit)
{
//Modify the "next_timestamp" element as we use it to draw the boxes to something sensible.
//Add the element to the session where the time threshold was hit e.g. pls one second 1000
nested_keen[i].values[e].next_timestamp = nested_keen[i].values[e].timestamp + 1000;
one_session.push(nested_keen[i].values[e]);
//push sessions to all sessions
all_session.push(one_session);
//clear for addtional sessions
one_session = [];
}
else one_session.push(nested_keen[i].values[e]);
});
var a = moment(nested_keen[i].values[0].timestamp);
var b = moment(nested_keen[i].values[nested_keen[i].values.length-1].timestamp);
nested_keen[i].timespent_total = moment.duration(b.diff(a));
//push the last session to all sessions.
all_session.push(one_session);
//persist it
nested_keen[i].all_session = all_session;
//console.log(nested_keen[i].timespent_total);
nested_keen[i].timespent_total_human = days_hours_minutes(nested_keen[i].timespent_total);
});
/*
var users_with_map_use = nested_keen.filter(function (d) {
contains_map_use = false;
d.values.forEach(function (e){
if (e.action.match("map:extentchange|map:click|marker:click|marker:mouseover|navigate|sidebar:clickBack|marker:click|sidebar:clickToggleFilter|sidebar:filterCategories|sidebar:typeFilter|sidebar:clickResetFilterQuery|sidebar:clickReply|sidebar:contributionMouseEnter|sidebar:contributionMouseLeave|sidebar:mouseoverFeatureTag|sidebar:mouseoverFeatureReferenceTag|sidebar:clickUserLink|sidebar:clickLegend|sidebar:mouseoverUrlTag|sidebar:clickHelp")) {
contains_map_use = true;
}
});
if(contains_map_use) return d;
});
*/
var non_idle_users = nested_keen.filter(function (d) {
return d.values.length > 5
});
console.log("Non-Idle Users: "+ non_idle_users.length);
var removed_trolls = non_idle_users.filter(function (d) {
return d.timespent_total > 10
});
console.log("Users looking at homepage more than 10 sec: "+ removed_trolls.length);
var users_with_one_session = removed_trolls.filter(function (d) {
return d.all_session.length = 1;
});
console.log("Users with one Session: "+ users_with_one_session.length);
var users_with_multiple_sessions = nested_keen.filter(function (d) {
return d.all_session.length > 1;
});
console.log("Users with multiple Sessions: "+ users_with_multiple_sessions.length);
console.log("Total Amount of users: "+ nested_keen.length)
prepare_divs(users_with_one_session);
console.log("Shown # of Users with one session: "+ users_with_one_session.length)
//draw(nested_keen[16])
function prepare_divs(nested_keen) {
var divs = d3.select("body")
.selectAll("div")
.data(nested_keen,function(d){
//console.log(d);
return d;})
.data(nested_keen)
.enter()
.append("div")
.attr("id", function(d) {
return "fingerprint_"+d.key
})
nested_keen.forEach(function (d,i) {
draw(nested_keen[i]);
});
};
function draw(keen_data_fingerprint) {
//Not nice but I'm too lazy to change this
var zoom = d3.behavior.zoom()
.scaleExtent([-10, 10])
.on("zoom", zoomed);
function zoomed(key) {
g.attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
}
var container = d3.select("#fingerprint_"+keen_data_fingerprint.key)
.append("svg")
.attr("width", width)
.attr("height", height)
.call(zoom)
var g = container.append("g");
var keen_data = keen_data_fingerprint.values
var x = d3.time.scale()
.domain([keen_data[0].timestamp,keen_data[keen_data.length-1].next_timestamp])
.range([0, width]);
g.append("text")
.attr("x",0)
.attr("y",barHeight*2)
//.attr("dy", ".35em")
.text("Fingerprint:"+ keen_data_fingerprint.key
+" Number of actions "+ keen_data_fingerprint.values.length
+" Session Time: "+keen_data_fingerprint.timespent_total_human);
var group = g.selectAll("g")
.data(keen_data)
.enter()
.append("g")
.attr("class", "chart")
.attr("transform", function(d, i) { return "translate("+0*i+",0)"; });
/*
group.append("g")
.attr("transform", function(d, i) { return "translate("+ x(d.timestamp) +","+ barHeight +") rotate(45) "; })
.append("text")
.attr("x", 0)
.attr("y", 8)
//.attr("dy", ".35em")
.text(function(d) {
if (d.action == "loadPage") return d.url;
else if (d.action == "sidebar:contributionMouseEnter") return "Sidebar Mouse Enter: "+d.contribution;
else if (d.action == "sidebar:contributionMouseLeave") return "Sidebar Mouse Leave: "+d.contribution;
else if (d.action == "sidebar:mouseoverFeatureTag") return "Mouse Over Feature Tag :"+d.tag.properties.title;
else if (d.action == "sidebar:clickReply") return "Sidebar Click Reply: "+d.contribution_id;
else return d.action;
});
*/
group.append("g")
.attr("transform", function(d, i) { return "translate("+(x(d.timestamp)) +",0)"; })
.append("rect")
.attr("width", function(d) { return (x(d.next_timestamp) - x(d.timestamp)) } )
.attr("height", barHeight - 1)
.attr("fill", function(d) {
return setRectColor(d,this);
});
//g.transition().call(zoom.scale(width/container.node().getBBox().width).event);
}
// All actions without loading "map:extentchange","map:click","marker:click","marker:mouseover","navigate","sidebar:clickBack","marker:click","sidebar:clickToggleFilter","sidebar:filterCategories","sidebar:typeFilter","sidebar:clickResetFilterQuery","sidebar:clickReply","sidebar:contributionMouseEnter","sidebar:contributionMouseLeave","sidebar:mouseoverFeatureTag","sidebar:mouseoverFeatureReferenceTag","sidebar:clickUserLink","sidebar:clickLegend"
function setRectColor(d, context) {
//Map Actions //Hellgrün
if (d.action == "map:extentchange") return "#BAD8C0";
else if (d.action == "map:click") return "#BAD8C0";
else if (d.action == "marker:click") return "#BAD8C0";
else if (d.action == "marker:mouseover") return "#BAD8C0";
//Navigate from mosaic-view to map view or to one specific
else if (d.action == "navigate")
{
//Wenn es eine Zahl enthält war es eine Aktion aus der mosaic-view
//Rotweinfarben
if(/[0-9]/.test(d.target)) return "#AF2867";
//Ansonsten ein Aufruf aus dem Header helles gelb
else return "#AF2867";
}
//Detailed-View geo-visualization
else if (d.action == "sidebar:clickBack") return "#C87B33";
else if (d.action == "marker:click") return "#C87B33";
//Filter Actions
else if (d.action == "sidebar:clickToggleFilter") return "#C3CBE1";
else if (d.action == "sidebar:filterCategories") return "#C3CBE1";
else if (d.action == "sidebar:typeFilter") return "#C3CBE1";
else if (d.action == "sidebar:clickResetFilterQuery") return "#C3CBE1";
//Dialog Funktion
else if (d.action == "sidebar:clickReply") return "#808080";
//Sidebar Actions
else if (d.action == "sidebar:contributionMouseEnter") return "#C3CBE1";
else if (d.action == "sidebar:contributionMouseLeave") return "#C3CBE1";
else if (d.action == "sidebar:mouseoverFeatureTag") return "#C3CBE1";
else if (d.action == "sidebar:mouseoverFeatureReferenceTag") return "#C3CBE1";
else if (d.action == "sidebar:clickUserLink") return "#C3CBE1";
else if (d.action == "sidebar:clickLegend") return "#C3CBE1";
else if (d.action == "sidebar:mouseoverUrlTag") return "#C3CBE1";
else if (d.action == "sidebar:clickHelp") return "#C3CBE1";
else if (d.action == "loadPage") return "#B657AD";
else {
console.log(d);
return "#000000";
}
}
function showTooltip(d, context) {
//Update the to get its dimensions -
d3.select("#tooltip")
.html(JSON.stringify(d, replacer));
//Get Mouse Cursor Position
var t_width = parseFloat(d3.select("#tooltip").style("width"));
var t_height = d3.select("#tooltip").style("height");
// Für den Arrow per CSS muss hier noch was abgezogen werden.. bla einfach weglassen
var xPosition = (parseFloat(d3.event.pageX));
if ((parseFloat(d3.event.pageX) + t_width) > $(document).width()) {
xPosition = (parseFloat(d3.event.pageX) - t_width);
}
//Hier pauschal "etwas" drunter setzen
var yPosition = (parseFloat(d3.event.pageY) + 10);
d3.select("#tooltip")
.style("left", xPosition + "px")
.style("top", yPosition + "px");
d3.select("#tooltip").classed("hidden", false);
}
function replacer(key,value)
{
if (key=="keen") return undefined;
else if (key=="fingerprint") return undefined;
else if (key=="map") return undefined;
else if (key=="geometry") return undefined;
else if (key=="type") return undefined;
else if (key=="marker-size") return undefined;
else if (key=="marker-symbol") return undefined;
else if (key=="marker-color") return undefined;
else if (key=="id") return undefined;
else return value;
}
function days_hours_minutes(ms){
days = Math.floor(ms / (24*60*60*1000));
daysms=ms % (24*60*60*1000);
hours = Math.floor((daysms)/(60*60*1000));
hoursms=ms % (60*60*1000);
minutes = Math.floor((hoursms)/(60*1000));
minutesms=ms % (60*1000);
sec = Math.floor((minutesms)/(1000));
return days+":"+hours+":"+minutes+":"+sec;
}
function draw_old(keen_data_fingerprint, div_id) {
var svg = d3.select("body")
.append("div")
//.attr("id", function(d) { return d.label; })
.append("svg")
.attr("width", width)
.attr("height", height);
//.call(zoom);
var container = svg.append("g");
var keen_data = keen_data_fingerprint.values
//As we have sorted the data by timestamp we don't have to find the min and max =
var x = d3.time.scale()
.domain([keen_data[0].timestamp,keen_data[keen_data.length-1].next_timestamp])
// .range([0, width-(keen_data.length*20)]);
.range([0, width]);
/*keen_data.forEach(function (d,i) {
console.log( x(keen_data[i].next_timestamp) - x(keen_data[i].timestamp) );
});
*/
var group = container.selectAll("g")
.data(keen_data)
.enter().append("g")
.attr("class", "chart")
.attr("transform", function(d, i) { return "translate("+0*i+",0)"; })
.on("mouseover", function (d) {
//showTooltip(d, this);
})
.on("mouseout", function () {
//d3.select("#tooltip").classed("hidden", true);;
});
/*group.append("circle")
.attr("cx", function(d) { return x(d.timestamp) } )
//.attr("height", barHeight - 1);
.attr("cy",barHeight)
.attr("r", 2);
group.append("g")
.attr("transform", function(d, i) { return "translate("+ x(d.timestamp) +","+ barHeight +") rotate(45) "; })
.append("text")
.attr("x", 0)
.attr("y", 8)
//.attr("dy", ".35em")
.text(function(d) {
if (d.action == "loadPage") return d.url;
else if (d.action == "sidebar:contributionMouseEnter") return "Sidebar Mouse Enter: "+d.contribution;
else if (d.action == "sidebar:contributionMouseLeave") return "Sidebar Mouse Leave: "+d.contribution;
else if (d.action == "sidebar:mouseoverFeatureTag") return "Mouse Over Feature Tag :"+d.tag.properties.title;
else if (d.action == "sidebar:clickReply") return "Sidebar Click Reply: "+d.contribution_id;
else return d.action;
});
*/
group.append("g")
.attr("transform", function(d, i) { return "translate("+(x(d.timestamp)) +",0)"; })
.append("rect")
.attr("width", function(d) { return (x(d.next_timestamp) - x(d.timestamp)) } )
.attr("height", barHeight - 1)
.attr("fill", function(d) {
return setRectColor(d,this);
});
svg.transition().call(zoom.scale($(window).width()/container.node().getBBox().width).event);
}