forked from DuckHunt-discord/DHV3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatistics_display.html
More file actions
374 lines (338 loc) · 12.9 KB
/
Copy pathstatistics_display.html
File metadata and controls
374 lines (338 loc) · 12.9 KB
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
<html>
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/dygraph/2.0.0/dygraph.min.js"></script>
<link rel="stylesheet" src="//cdnjs.cloudflare.com/ajax/libs/dygraph/2.0.0/dygraph.min.css"/>
</head>
<body>
<script>
/**
* Synchronize zooming and/or selections between a set of dygraphs.
*
* Usage:
*
* var g1 = new Dygraph(...),
* g2 = new Dygraph(...),
* ...;
* var sync = Dygraph.synchronize(g1, g2, ...);
* // charts are now synchronized
* sync.detach();
* // charts are no longer synchronized
*
* You can set options using the last parameter, for example:
*
* var sync = Dygraph.synchronize(g1, g2, g3, {
* selection: true,
* zoom: true
* });
*
* The default is to synchronize both of these.
*
* Instead of passing one Dygraph object as each parameter, you may also pass an
* array of dygraphs:
*
* var sync = Dygraph.synchronize([g1, g2, g3], {
* selection: false,
* zoom: true
* });
*
* You may also set `range: false` if you wish to only sync the x-axis.
* The `range` option has no effect unless `zoom` is true (the default).
*/
(function () {
/* global Dygraph:false */
'use strict';
var Dygraph;
if (window.Dygraph) {
Dygraph = window.Dygraph;
} else if (typeof(module) !== 'undefined') {
Dygraph = require('../dygraph');
}
var synchronize = function (/* dygraphs..., opts */) {
if (arguments.length === 0) {
throw 'Invalid invocation of Dygraph.synchronize(). Need >= 1 argument.';
}
var OPTIONS = ['selection', 'zoom', 'range'];
var opts = {
selection: true,
zoom: true,
range: true
};
var dygraphs = [];
var prevCallbacks = [];
var parseOpts = function (obj) {
if (!(obj instanceof Object)) {
throw 'Last argument must be either Dygraph or Object.';
} else {
for (var i = 0; i < OPTIONS.length; i++) {
var optName = OPTIONS[i];
if (obj.hasOwnProperty(optName)) opts[optName] = obj[optName];
}
}
};
if (arguments[0] instanceof Dygraph) {
// Arguments are Dygraph objects.
for (var i = 0; i < arguments.length; i++) {
if (arguments[i] instanceof Dygraph) {
dygraphs.push(arguments[i]);
} else {
break;
}
}
if (i < arguments.length - 1) {
throw 'Invalid invocation of Dygraph.synchronize(). ' +
'All but the last argument must be Dygraph objects.';
} else if (i == arguments.length - 1) {
parseOpts(arguments[arguments.length - 1]);
}
} else if (arguments[0].length) {
// Invoked w/ list of dygraphs, options
for (var i = 0; i < arguments[0].length; i++) {
dygraphs.push(arguments[0][i]);
}
if (arguments.length == 2) {
parseOpts(arguments[1]);
} else if (arguments.length > 2) {
throw 'Invalid invocation of Dygraph.synchronize(). ' +
'Expected two arguments: array and optional options argument.';
} // otherwise arguments.length == 1, which is fine.
} else {
throw 'Invalid invocation of Dygraph.synchronize(). ' +
'First parameter must be either Dygraph or list of Dygraphs.';
}
if (dygraphs.length < 2) {
throw 'Invalid invocation of Dygraph.synchronize(). ' +
'Need two or more dygraphs to synchronize.';
}
var readycount = dygraphs.length;
for (var i = 0; i < dygraphs.length; i++) {
var g = dygraphs[i];
g.ready(function () {
if (--readycount == 0) {
// store original callbacks
var callBackTypes = ['drawCallback', 'highlightCallback', 'unhighlightCallback'];
for (var j = 0; j < dygraphs.length; j++) {
if (!prevCallbacks[j]) {
prevCallbacks[j] = {};
}
for (var k = callBackTypes.length - 1; k >= 0; k--) {
prevCallbacks[j][callBackTypes[k]] = dygraphs[j].getFunctionOption(callBackTypes[k]);
}
}
// Listen for draw, highlight, unhighlight callbacks.
if (opts.zoom) {
attachZoomHandlers(dygraphs, opts, prevCallbacks);
}
if (opts.selection) {
attachSelectionHandlers(dygraphs, prevCallbacks);
}
}
});
}
return {
detach: function () {
for (var i = 0; i < dygraphs.length; i++) {
var g = dygraphs[i];
if (opts.zoom) {
g.updateOptions({drawCallback: prevCallbacks[i].drawCallback});
}
if (opts.selection) {
g.updateOptions({
highlightCallback: prevCallbacks[i].highlightCallback,
unhighlightCallback: prevCallbacks[i].unhighlightCallback
});
}
}
// release references & make subsequent calls throw.
dygraphs = null;
opts = null;
prevCallbacks = null;
}
};
};
function arraysAreEqual(a, b) {
if (!Array.isArray(a) || !Array.isArray(b)) return false;
var i = a.length;
if (i !== b.length) return false;
while (i--) {
if (a[i] !== b[i]) return false;
}
return true;
}
function attachZoomHandlers(gs, syncOpts, prevCallbacks) {
var block = false;
for (var i = 0; i < gs.length; i++) {
var g = gs[i];
g.updateOptions({
drawCallback: function (me, initial) {
if (block || initial) return;
block = true;
var opts = {
dateWindow: me.xAxisRange()
};
if (syncOpts.range) opts.valueRange = me.yAxisRange();
for (var j = 0; j < gs.length; j++) {
if (gs[j] == me) {
if (prevCallbacks[j] && prevCallbacks[j].drawCallback) {
prevCallbacks[j].drawCallback.apply(this, arguments);
}
continue;
}
// Only redraw if there are new options
if (arraysAreEqual(opts.dateWindow, gs[j].getOption('dateWindow')) &&
arraysAreEqual(opts.valueRange, gs[j].getOption('valueRange'))) {
continue;
}
gs[j].updateOptions(opts);
}
block = false;
}
}, true /* no need to redraw */);
}
}
function attachSelectionHandlers(gs, prevCallbacks) {
var block = false;
for (var i = 0; i < gs.length; i++) {
var g = gs[i];
g.updateOptions({
highlightCallback: function (event, x, points, row, seriesName) {
if (block) return;
block = true;
var me = this;
for (var i = 0; i < gs.length; i++) {
if (me == gs[i]) {
if (prevCallbacks[i] && prevCallbacks[i].highlightCallback) {
prevCallbacks[i].highlightCallback.apply(this, arguments);
}
continue;
}
var idx = gs[i].getRowForX(x);
if (idx !== null) {
gs[i].setSelection(idx, seriesName);
}
}
block = false;
},
unhighlightCallback: function (event) {
if (block) return;
block = true;
var me = this;
for (var i = 0; i < gs.length; i++) {
if (me == gs[i]) {
if (prevCallbacks[i] && prevCallbacks[i].unhighlightCallback) {
prevCallbacks[i].unhighlightCallback.apply(this, arguments);
}
continue;
}
gs[i].clearSelection();
}
block = false;
}
}, true /* no need to redraw */);
}
}
Dygraph.synchronize = synchronize;
})();
</script>
<style> .dygraph-legend {
text-align: right;
}</style>
<h1>Experimental duckhunt statistics</h1>
<!--<h2>Number of servers seen by the bot</h2>-->
<div id="servers"
style="height:300px;"></div>
<script type="text/javascript">
g1 = new Dygraph(
document.getElementById("servers"),
"csv/servers.csv", // path to CSV file
{
title: 'Number of servers seen by the bot',
ylabel: 'Servers',
legend: 'always',
//showRangeSelector: true,
labelsKMB: true,
} // options
);
</script>
<!--<h2>Number of channels seen by the bot</h2>-->
<div id="channels"
style="height:300px;"></div>
<script type="text/javascript">
g2 = new Dygraph(
document.getElementById("channels"),
"csv/channels.csv", // path to CSV file
{
title: 'Number of channels seen by the bot',
ylabel: 'Channels',
legend: 'always',
//showRangeSelector: true,
labelsKMB: true,
} // options
);
</script>
<!--<h2>Number of users (no bots) seen by the bot</h2>-->
<div id="users"
style="height:300px;"></div>
<script type="text/javascript">
g3 = new Dygraph(
document.getElementById("users"),
"csv/users.csv", // path to CSV file
{
title: 'Number of users (no bots) seen by the bot',
ylabel: 'Users',
legend: 'always',
//showRangeSelector: true,
labelsKMB: true,
} // options
);
</script>
<!--<h2>Memory used by the bot</h2>-->
<div id="memory"
style="height:300px;"></div>
<script type="text/javascript">
g4 = new Dygraph(
document.getElementById("memory"),
"csv/memory.csv", // path to CSV file
{
title: 'Memory used by the bot',
ylabel: 'Memory (mb)',
legend: 'always',
//showRangeSelector: true,
} // options
);
</script>
<!--<h2>Bot latency</h2>-->
<div id="latency"
style="height:300px;"></div>
<script type="text/javascript">
g5 = new Dygraph(
document.getElementById("latency"),
"csv/latency.csv", // path to CSV file
{
title: 'Bot latency',
ylabel: 'Latency (sec) - more is better',
legend: 'always',
//showRangeSelector: true,
} // options
);
</script>
<!--<h2>Number of ducks spawned</h2>-->
<div id="ducks"
style="height:300px;"></div>
<script type="text/javascript">
g6 = new Dygraph(
document.getElementById("ducks"),
"csv/ducks.csv", // path to CSV file
{
title: 'Number of ducks spawned',
ylabel: 'Ducks',
legend: 'always',
//showRangeSelector: true,
labelsKMB: true,
} // options
);
</script>
<script>
var sync = Dygraph.synchronize([g1, g2, g3, g4, g5, g6], {selection: true, zoom: true, range: false})
</script>
</body>
</html>