-
Notifications
You must be signed in to change notification settings - Fork 28
/
index.html
398 lines (345 loc) · 19.3 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>All in one</title>
<script src="https://code.jquery.com/jquery-2.2.3.min.js" integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo=" crossorigin="anonymous"></script>
<!-- Latest compiled and minified CSS -->
<!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> -->
<link rel="stylesheet" href="https://bootswatch.com/4/flatly/bootstrap.min.css" media="screen" title="no title" charset="utf-8">
<!-- Latest compiled and minified JavaScript -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container-fluid">
<div class="row row-centered page-header">
<div class="col-sm-12 col-centered">
<div class="page-header">
<h1>More <a target="_blank" href="https://www.rescuetime.com/">RescueTime</a> Charts <a
href="https://github.com/ilbonte/rescuetime-again/blob/gh-pages/CHANGELOG.md">v2.0.1</a>
<small>Cuz <a href="https://www.reddit.com/r/dataisbeautiful/top/?sort=top&t=month"
target="_blank">data
are beautiful!</a></small>
</h1>
<h5>Psssst: you really should read the <a href="https://github.com/ilbonte/rescuetime-again"
TARGET="_blank">README</a> before using this tool!
</h5>
</div>
</div>
</div>
<div class="row">
<div class="spinner" hidden></div>
</div>
<div class="row row-centered page-nav-bar">
<main>
<input id="tab1" type="radio" name="tabs" checked>
<label for="tab1">Get the data from RescueTime</label>
<input id="tab2" type="radio" name="tabs">
<label for="tab2">Upload your files</label>
<input id="tab3" type="radio" name="tabs">
<label for="tab3">Merge files</label>
<section id="content1">
<div class="row" id="controls">
<div class="col-sm-6">
<div class="form-group">
<label><a href="https://www.rescuetime.com/anapi/manage" target="_blank">Choose your API
Key</a>
</label>
<input type="text" class="form-control" id="api_key" placeholder="Enter API key"
value="">
<br>
<label>Pick the date
</label>
<div id="reportrange">
<i class="fa fa-calendar"></i>
<span></span> <i class="fa fa-caret-down"></i>
</div>
<script type="text/javascript">
$(function () {
$(".chart").hide();
//set default values
var start = moment().subtract(1, 'month').startOf('month');
var end = moment().subtract(1, 'month').endOf('month');
function cb(start, end) {
$('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
}
$('#reportrange').daterangepicker({
startDate: start,
endDate: end,
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
}
}, cb);
cb(start, end);
});
</script>
</div>
<div id="downloadSection">
</div>
</div>
<div class="col-sm-6">
<br>NOTE: It may take a few seconds to retrieve and elaborate the data
<br>
<br>
<button type="button" class="btn btn-primary" onClick="init()">Start analysis</button>
<br>
<br>
<div class="checkbox">
<label>
<input type="checkbox" id="download"> Download JSON file for the selected range. <a
href="https://github.com/ilbonte/rescuetime-again#notes"
target="_blank">Why?</a><br>
<input type="checkbox" id="save" checked> Save API Key
</label>
</div>
</div>
</div>
</section>
<section id="content2">
<div class="row">
<div class="col-sm-6">
<strong>Efficiency</strong>
<br>
<input id="fileEfficiency" type="file" />
<br>
<br>
<strong>Activity</strong>
<br>
<input id="fileActivity" type="file" />
<br>
<br>
<button type="button" class="btn btn-info" onClick="checkFiles()">Analyze uploaded
data</button>
</div>
</div>
</section>
<section id="content3">
<div class="row">
<div class="col-sm-6">
<h5>Which type of file do you want to merge?</h5>
<input type="radio" name="type" value="hour" id="efficiency" checked>Productivity/Efficiency
<br>
<input type="radio" name="type" value="activity" id="activity">Activity
<br>
<br>
<p><strong>Upload Files:</strong>
<input type="file" name="filesToUpload" id="filesToUpload" multiple=""
onChange="makeFileList();" />
</p>
<button onClick="merge()">MERGE!</button>
<button onClick="removeOldFiles()">ResetAll</button>
</div>
<div class="col-sm-3">
<div id="downloadMergedSection">
</div>
<p>
<strong>Files You Selected:</strong>
</p>
<ul id="fileList">
<li>No Files Selected</li>
</ul>
</div>
</div>
<script src="https://cdn.jsdelivr.net/lodash/4.11.2/lodash.core.min.js"
integrity="sha256-wMmYI13CCKWf57eu6cwv4vXS+vvjk3A4RMx95QIaVCc="
crossorigin="anonymous"></script>
<script>
var input = document.getElementById("filesToUpload");
var uploadedFiles = [];
//load the files
function makeFileList() {
var ul = document.getElementById("fileList");
uploadedFiles.clear();
removeOldFiles();
for (var i = 0; i < input.files.length; i++) {
var li = document.createElement("li");
li.innerHTML = input.files[i].name;
ul.appendChild(li);
}
var counter = 0;
for (var file in input.files) {
if (input.files.hasOwnProperty(file)) {
var reader = new FileReader();
reader.onload = function (e) {
uploadedFiles.push({
name: input.files[counter].name,
file: JSON.parse(e.target.result)
});
counter++;
};
reader.readAsText(input.files[file]);
}
}
if (!ul.hasChildNodes()) {
var li = document.createElement("li");
li.innerHTML = 'No Files Selected';
ul.appendChild(li);
}
}
//checks which operation to perform
function merge() {
if (document.getElementById('efficiency').checked) {
mergeEfficiency();
} else if (document.getElementById('activity').checked) {
mergeActivity();
}
}
function mergeEfficiency() {
var allRows = [];
uploadedFiles.forEach(function (item, index, array) {
if (!checkFile(item, ['Date', 'Time Spent (seconds)', 'Number of People', 'Efficiency (-2:2)', 'Efficiency (percent)'], 'Activity')) {
return;
}
allRows = allRows.concat(item.file.rows);
});
uploadedFiles[0].file.rows = _.sortBy(allRows);
//TODO: add check uniq?
var JSONString = JSON.stringify(uploadedFiles[0].file);
var data = "text/json;charset=utf-8," + encodeURIComponent(JSONString);
$('<a href="data:' + data + '" download="Efficiency.json">[Efficiency] download JSON</a> <br>').appendTo('#downloadMergedSection');
}
function mergeActivity() {
uploadedFiles.forEach(function (item) {
if (!checkFile(item, ['Rank', 'Time Spent (seconds)', 'Number of People', 'Activity', 'Category', 'Productivity'], 'Activity')) {
return;
}
});
var result = uploadedFiles[0].file;
for (var i = 1; i < uploadedFiles.length; i++) {
result = mergeActivityFile(result, uploadedFiles[i].file);
}
result.rows = result.rows.sort(function (a, b) {
return b[1] - a[1];
});
var data = "text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(result));
$('<a href="data:' + data + '" download="Activity.json">[Activity] download JSON</a> <br>').appendTo('#downloadMergedSection');
}
function mergeActivityFile(total, current) {
for (var i = 0; i < total.rows.length; i++) {
for (var j = 0; j < current.rows.length; j++) {
if (total.rows[i][3] === current.rows[j][3]) {
total.rows[i][1] += current.rows[j][1];
current.rows.splice(j, 1);
}
}
}
total.rows = total.rows.concat(current.rows);
return total;
}
function removeOldFiles() {
var ul = document.getElementById("fileList");
while (ul.hasChildNodes()) {
ul.removeChild(ul.firstChild);
}
}
//cehck if the file we need to merge is consistent
function checkFile(file, correctHeader, type) {
var header = file.file.row_headers;
for (var i = 0; i < header.length; i++) {
if (header[i] !== correctHeader[i]) {
alert(file.name + ' is not an ' + type + ' file! Can not merge');
return false;
}
}
return true;
}
Array.prototype.clear = function () {
while (this.length) {
this.pop();
}
};
</script>
</section>
</main>
</div>
<div class="row chart">
<div class="col-sm-12">
<blockquote class="col-sm-offset-1 col-sm-10">
<p>This chart shows your productivity during the selected range. Productivity is calculated with
this formula:
<br>(Time*RescueTime's Productivity Score)/3600.
<br>This means that if you do 60 minutes with 100 as Productivity Score your productivity will
be 100 too, but if you do only 30 minutes with 100 Productivity Score your productivity will be
50!
<br>You can think at the blue line as "things you got done".
<br>Weekends are shown with gray plot bands.
</p>
</blockquote>
<!--<h2>Productivity for the selected range</h2>-->
<div class="input-group">
<span class="input-group-addon">Trendline smoothness (1 to 50)</span>
<input type="number" id="trendLineSpinner" min="1" max="50" class="form-control" value="5">
</div>
<br>
<br>
<div id="efficiency_chart"></div>
</div>
</div>
<div class="row chart">
<div class="col-sm-12">
<!--<h2>Total minutes for hour</h2>-->
<blockquote class="col-sm-offset-1 col-sm-10">
<p>This chart shows your average productivity and the total time spent for each hour of the day in
the selected period. The formula for productivity is the same as above. <br>
The higher the line compared to the bar, the more efficient you have been</p>
</blockquote>
<div id="combo_hour_chart"></div>
</div>
</div>
<div class="row chart">
<div class="col-sm-12">
<br>
<blockquote class="col-sm-offset-1 col-sm-10">
<p>Same chart as above but grouped by days of the week instead of by hour.</p>
</blockquote>
<div id="avg_day_chart"></div>
</div>
</div>
<div class="row chart">
<div class="col-sm-12">
<div id="combo_day_chart"></div>
</div>
</div>
<div class="row chart">
<div class="col-sm-12">
<h2>Top activities </h2>
<blockquote class="col-sm-offset-1 col-sm-10">
<p>This chart simply show your top activities for the selected range. Bar's color is based on
RescueTime's colors.
</p>
</blockquote>
<div id="customControls">
<div class="input-group">
<span class="input-group-addon">Top x activities. x=</span>
<input type="number" id="activitiesNumberSpinner" min="3" max="100" class="form-control"
value="30" />
</span>
</div>
</div>
<div id="act_chart"></div>
</div>
</div>
<script src="app.js"></script>
<a href="https://github.com/ilbonte/rescuetime-again"><img
style="position: absolute; top: 0; right: 0; border: 0;"
src="https://camo.githubusercontent.com/365986a132ccd6a44c23a9169022c0b5c890c387/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f7265645f6161303030302e706e67"
alt="Fork me on GitHub"
data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png"></a>
<!-- highcharts -->
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<script src="https://rawgithub.com/phpepe/highcharts-regression/master/highcharts-regression.js">
</script>
<script
src="https://rawgit.com/highcharts/highcharts/70f37e4c09f5fb5f6547b2bc6945b52c6afeb50e/js/themes/sand-signika.js"
charset="utf-8"></script>
</body>
</html>