-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
295 lines (230 loc) · 7.72 KB
/
index.html
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
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/angular-chart.js/0.10.0/angular-chart.css">
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<h1>Usage statistics for <a href="https://www.duplicati.com">Duplicati</a></h1>
<table>
<tr>
<td>Range</td>
<td>
<select id="granularity" ng-model="rangetype">
<option value="day">Day</option>
<option value="week">Week</option>
<option value="month">Month</option>
<option value="year">Year</option>
</select>
</td>
</tr>
<tr>
<td>Feature</td>
<td>
<select id="valuetype" ng-model="valuetype">
<option value="USE_BACKEND">Backend</option>
<option value="USE_ENCRYPTION">Encryption</option>
<option value="USE_COMPRESSION">Compression</option>
<option value="DURATION">Duration</option>
<option value="SIZE">Size</option>
<option value="OS">Operating system</option>
</select>
</td>
</tr>
</table>
<canvas id="line" class="chart chart-line" chart-data="data" chart-labels="labels" chart-legend="true" chart-series="series" chart-options="{}" chart-click="onClick" >
</canvas>
<a href="https://github.com/duplicati/usage-reporter">Source code for this site is on GitHub</a>
<p>Data was last updated {{lastupdated}}</p>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-chart.js/0.10.0/angular-chart.min.js"></script>
<script type="text/javascript">
// The isoWeek handling is from here:
// http://techblog.procurios.nl/k/news/view/33796/14863/calculate-iso-8601-week-and-year-in-javascript.html
Date.prototype.getWeek = function () {
var target = new Date(this.valueOf());
var dayNr = (this.getDay() + 6) % 7;
target.setDate(target.getDate() - dayNr + 3);
var firstThursday = target.valueOf();
target.setMonth(0, 1);
if (target.getDay() != 4) {
target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
}
return 1 + Math.ceil((firstThursday - target) / 604800000); // 604800000 = 7 * 24 * 3600 * 1000
}
Date.prototype.getWeekYear = function ()
{
var target = new Date(this.valueOf());
target.setDate(target.getDate() - ((this.getDay() + 6) % 7) + 3);
return target.getFullYear();
}
var supportedbackends = {
'aftp': 'Alternative FTP',
'amzcd': 'Amazon Cloud Drive',
'azure': 'Azure Blob',
'b2': 'Backblaze',
'box': 'box.com',
'cloudfiles': 'CloudFiles',
'dropbox': 'DropBox',
'file': 'File storage',
'ftp': 'FTP',
'gcs': 'Google Cloud Storage',
'googledrive': 'Google Drive',
'hubic': 'HubiC',
'mega': 'Mega.nz',
'onedrive': 'OneDrive',
'openstack': 'OpenStack',
's3': 'S3 compatible',
'od4b': 'OneDrive for Business',
'mssp': 'Sharepoint',
'ssh': 'SSH (SFTP)',
'tahoe': 'Tahoe LAFS',
'webdav': 'WebDAV',
'': 'Other'
}
var app = angular.module('myApp', ['chart.js']);
app.controller('myCtrl', function($scope, $http) {
$scope.isLoading = false;
$scope.shouldReload = false;
$scope.rangetype = 'day';
$scope.valuetype = 'OS';
$scope.last_data = null;
$scope.last_range = null;
$scope.lastupdated_timestamp = 0;
function parseResults(data, range, filter) {
var label_lookup = {};
var labels = [];
for (var i = data.items.length - 1; i >= 0; i--) {
var el = data.items[i];
$scope.lastupdated_timestamp = Math.max($scope.lastupdated_timestamp, el.lastupdated);
if (label_lookup[el.timestamp] == null) {
var date = new Date(el.timestamp*1000);
var label = date.toISOString();
if (range == 'day')
label = label.match(/(\d{4}-\d{2}-\d{2})/)[0];
else if (range == 'week')
{
var w = date.getWeek() + '';
if (w.length == 1)
w = '0' + w;
label = date.getWeekYear() + ', Week ' + w;
}
else if (range == 'month')
label = label.match(/(\d{4}-\d{2})/)[0];
else if (range == 'year')
label = label.match(/(\d{4})/)[0];
label_lookup[el.timestamp] = label;
labels[labels.length] = label;
}
}
labels.sort();
for(var i in label_lookup) {
for (var j = labels.length - 1; j >= 0; j--) {
if (label_lookup[i] == labels[j]) {
label_lookup[i] = j;
break;
}
}
}
var series_lookup = {};
var entrycounts = [];
var entrysums = [];
var series_labels = [];
for (var i = data.items.length - 1; i >= 0; i--) {
var el = data.items[i];
var series_key = null;
if (filter == 'OS')
series_key = el.ostype;
else if (filter == 'DURATION' && el.name == 'BACKUP_DURATION')
series_key = el.ostype;
else if (filter == 'SIZE' && el.name == 'BACKUP_FILESIZE')
series_key = el.ostype;
else if (el.name == filter)
series_key = el.value;
else
continue;
if (filter == 'USE_ENCRYPTION' && series_key == '')
series_key = 'none';
if (filter == 'USE_BACKEND') {
if (series_key == null)
series_key = 'Other';
var lookup = supportedbackends[series_key];
if (lookup == null && series_key.length > 0 && series_key.substr(series_key.length - 1) == 's')
lookup = supportedbackends[series_key.substr(0, series_key.length - 1)];
series_key = lookup == null ? 'Other' : lookup;
if (series_key == 'Other') {
//console.log('Using ' + el.value + ' as Other');
lookup = null;
}
}
if (filter == 'OS' && el.name != 'USE_BACKEND')
continue;
if (series_key != null) {
if (series_lookup[series_key] == null) {
series_labels[entrycounts.length] = series_key;
series_lookup[series_key] = entrycounts.length;
entrysums[entrycounts.length] = [];
entrycounts[entrycounts.length] = [];
for (var j = labels.length - 1; j >= 0; j--) {
entrysums[entrycounts.length - 1][j] = 0;
entrycounts[entrycounts.length - 1][j] = 0;
}
}
var entry_array = entrycounts[series_lookup[series_key]];
entry_array[label_lookup[el.timestamp]] += el.count;
var entry_array = entrysums[series_lookup[series_key]];
entry_array[label_lookup[el.timestamp]] += el.sum;
}
}
if (filter == "DURATION" || filter == "SIZE")
for (var i = entrysums.length - 1; i >= 0; i--)
for (var j = entrysums[i].length - 1; j >= 0; j--)
entrycounts[i][j] = entrysums[i][j] / Math.max(1, entrycounts[i][j]);
$scope.labels = labels;
$scope.series = series_labels;
$scope.data = entrycounts;
};
$scope.load = function() {
var range = $scope.rangetype;
var filter = $scope.valuetype;
if ($scope.last_data != null) {
if ($scope.last_range == range && $scope.last_filter == filter)
return;
if ($scope.last_range == range) {
$scope.last_filter = filter;
parseResults($scope.last_data, $scope.last_range, filter);
return;
}
}
if ($scope.isLoading) {
$scope.shouldReload = true;
return;
}
$scope.isLoading = true;
$scope.shouldReload = false;
$http.get('/api/v1/view?page_size=7&page_offset=0&rangetype=' + range).then(function(response) {
$scope.isLoading = false;
$scope.last_data = response.data;
$scope.last_range = range;
$scope.last_filter = filter;
parseResults(response.data, range, filter);
if ($scope.shouldReload)
$scope.load();
}, function(response) {
alert('Failed to load data: ' + response.status);
$scope.isLoading = false;
if ($scope.shouldReload)
$scope.load();
});
};
$scope.onClick = function (points, evt) {
console.log(points, evt);
};
$scope.load();
$scope.$watch('rangetype', function() { $scope.load(); });
$scope.$watch('valuetype', function() { $scope.load(); });
$scope.$watch('lastupdated_timestamp', function() { $scope.lastupdated = (new Date($scope.lastupdated_timestamp*1000)).toISOString(); });
});
</script>
</body>
</html>