-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
382 lines (374 loc) · 13.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
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>DarnBot</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/js/materialize.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script async defer data-website-id="3d5bdb36-4af0-4411-8e7e-ad1a7d6965d3" src="https://umami.htools.work/u.js"></script>
<script>
var freqSubsChart, countByDateChart, freqSubsChart, freqSubsData = [], commentCountByDateData = [], darnCountByDateData = [];
var chartColors = {
red: 'rgb(255, 99, 132)',
orange: 'rgb(255, 159, 64)',
yellow: 'rgb(255, 205, 86)',
green: 'rgb(75, 192, 192)',
blue: 'rgb(54, 162, 235)',
purple: 'rgb(153, 102, 255)',
grey: 'rgb(201, 203, 207)'
};
function processNewStats(newStats) {
freqSubsData = newStats.frequentSubs;
commentCountByDateData = JSON.parse(JSON.stringify(newStats.countByDate));
darnCountByDateData = JSON.parse(JSON.stringify(newStats.countByDate));
for (var i = 0; i < newStats.countByDate.length; i++) {
darnCountByDateData[i].t = commentCountByDateData[i].t = moment(newStats.countByDate[i].date, 'YYYY-M-D').valueOf();
commentCountByDateData[i].y = newStats.countByDate[i].count;
darnCountByDateData[i].y = newStats.countByDate[i].darnCount;
}
console.log('commentCountByDate', commentCountByDateData);
console.log('darnCountByDate', darnCountByDateData);
freqSubsChart.data.datasets[0].data = freqSubsData.map(x=>x.commentCount);
freqSubsChart.data.labels = freqSubsData.map(x=>x._id);
freqAuthorsChart.data.datasets[0].data = newStats.frequentAuthors.map(x=>x.commentCount);
freqAuthorsChart.data.labels = newStats.frequentAuthors.map(x=>x._id);
countByDateChart.data.labels = commentCountByDateData.map(x=>x.t);
countByDateChart.data.datasets[0].data = commentCountByDateData;
countByDateChart.data.datasets[1].data = darnCountByDateData;
freqSubsChart.update();
countByDateChart.update();
freqAuthorsChart.update();
$('#topAuthorsList').children('a').remove();
$('#freqSubsList').children('a').remove();
for (author of newStats.frequentAuthors) {
$('#topAuthorsList').append(`<a href="https://www.reddit.com/u/${author._id}" target="_blank" class="collection-item smallerCollection">${author._id}<span class="badge">${author.commentCount}</span></a>`);
}
for (sub of newStats.frequentSubs) {
$('#freqSubsList').append(`<a href="https://www.reddit.com/r/${sub._id}" target="_blank" class="collection-item smallerCollection">${sub._id}<span class="badge">${sub.commentCount}</span></a>`);
}
$('#lastUpdated').text('Last updated: ' + moment(newStats.lastUpdated).format('MMMM Do YYYY, h:mm:ss a') + ' (' + moment(newStats.lastUpdated).fromNow() + ')');
}
$(function () {
var app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!',
counter: 0,
comments: [],
subs: []
}
});
// Subreddit pie chart
freqSubsChart = new Chart($("#freqSubsChart"),{
type: 'pie',
data: {
datasets: [{
backgroundColor: Object.values(chartColors),
data: []
}],
labels: []
},
options: {
title: {
display: true,
position: 'bottom',
fontSize: 20,
text: 'Comment count by subreddit (Top 10)'
}
}
});
// Authors bar graph
freqAuthorsChart = new Chart($("#freqAuthors"),{
type: 'horizontalBar',
data: {
datasets: [{
backgroundColor: Object.values(chartColors),
data: []
}],
labels: []
},
options: {
legend: {
display: false
},
title: {
display: true,
position: 'bottom',
fontSize: 20,
text: 'Frequent commenters (All time)'
}
}
});
// Count line graph
countByDateChart = new Chart($('#countByDate'), {
type: 'line',
data: {
labels: [],
datasets: [
{
yAxisID: 'commentCountByDateAxis',
label: 'Comment count by date',
data: [],
type: 'line',
pointRadius: 5,
borderColor: chartColors.blue,
backgroundColor: chartColors.blue,
fill: false,
lineTension: 0,
borderWidth: 2
},
{
yAxisID: 'darnCountByDateAxis',
label: 'Darn count by date',
data: [],
type: 'line',
pointRadius: 5,
borderColor: chartColors.red,
backgroundColor: chartColors.red,
fill: false,
lineTension: 0,
borderWidth: 2
}
]
},
options: {
title: {
display: true,
position: 'bottom',
fontSize: 20,
text: 'Comment / Darn counts (30 days)'
},
scales: {
xAxes: [{
type: 'time',
distribution: 'series',
time: {
unit: 'day'
},
ticks: {
source: 'labels'
}
}],
yAxes: [
{
id: 'commentCountByDateAxis',
display: true,
position: 'left',
labelString: 'Comment Count'
},
{
id: 'darnCountByDateAxis',
display: true,
position: 'right',
labelString: 'Darn Count',
gridLines: {
drawOnChartArea: false, // only want the grid lines for one axis to show up
}
}
]
}
}
});
var socket = io.connect('/');
socket.on('connect', function(){
$('#connectionStatus').removeClass('orange').addClass('green').text('Connected (live counter)');
});
socket.on('disconnect', function(){
$('#connectionStatus').removeClass('green').addClass('orange').text('Connecting...');
});
socket.on('updateCounter', function (count) {
app.counter = count;
console.log(count);
});
socket.on('updateSubs', function (subs) {
app.subs = subs;
console.log(subs);
});
socket.on('newComment', function (comment) {
app.comments.splice(0, 0, comment);
if (app.comments.length > 5) {
app.comments.pop();
}
console.log(comment);
});
socket.on('newStats', function (newStats) {
console.log(newStats);
if (newStats) {
processNewStats(newStats);
}
});
socket.on('GBBB', function (res) {
console.log('GBBB', res);
$('#gbbbContainer div:eq(1) span span').text(res.rank);
$('#gbbbContainer div:eq(2) span span').text(res.score);
$('#gbbbContainer div:eq(3) span:eq(0) span').text(res.good);
$('#gbbbContainer div:eq(3) span:eq(2) span').text(res.bad);
});
});
</script>
<style>
#connectionStatus {
font-size: 1.1rem;
line-height: 30px;
height: 30px;
color: white;
border-radius: 25px;
font-weight: 400;
padding-left: 15px;
padding-right: 15px;
}
#subsList span {
border: 1px solid black;
border-radius: 6px;
padding: 3px;
line-height: 2.4;
word-break: keep-all;
margin-right: 10px;
background-color: #e3f2fd;
border-color: #e3f2fd;
}
.slide-fade-enter-active {
transition: all .3s ease;
}
.slide-fade-leave-active {
transition: all .8s cubic-bezier(1.0, 0.5, 0.8, 1.0);
}
.slide-fade-enter, .slide-fade-leave-to
/* .slide-fade-leave-active below version 2.1.8 */ {
transform: translateX(10px);
opacity: 0;
}
#lastUpdated {
font-size: 1.1rem;
line-height: 30px;
height: 30px;
color: white;
border-radius: 25px;
font-weight: 400;
padding-left: 15px;
padding-right: 15px;
}
#gbbbContainer {
border: solid #2196f3 4px;
border-radius: 6px;
line-height: 50px;
}
#gbbbContainer > div:not(:first-child) span {
font-weight: bold;
}
.smallerCollection {
line-height: 1.1 !important;
}
</style>
</head>
<body>
<div id="app">
<nav>
<div class="nav-wrapper blue">
<a href="#" class="brand-logo center">DarnBot</a>
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href=""><span id="connectionStatus" class="badge orange">Connecting...</span></a></li>
<!-- <li><a href=""><span id="lastUpdated" class="badge orange">Last updated: ...</span></a></li> -->
</ul>
</div>
</nav>
<div class="container-fluid">
<br><br>
<div class="row">
<div class="col s12 m6 center" style="border-right: 2px solid #eee;">
<h4>Darn Count</h4>
<h2>{{counter}}</h2>
<br>
<div class="col s4 m4">
<h4>--</h4><h5>Today</h5>
</div>
<div class="col s4 m4">
<h4>--</h4><h5>This week</h5>
</div>
<div class="col s4 m4">
<h4>--</h4><h5>This month</h5>
</div>
</div>
<div class="col s12 m6">
<ul class="collection with-header">
<li class="collection-header center"><h5>Latest Darns</h5></li>
<transition-group name="slide-fade">
<li class="collection-item" v-for="comment in comments" :key="comment"><div><a target="_blank" :href="comment.link"><span class="truncate">{{comment.author}} - {{comment.body}}</span></a></div></li>
</transition-group>
</ul>
</div>
</div>
<div class="row">
<div class="col s12 m12 center">
<h6 id="subsList">Currently monitoring:
<span v-for="sub in subs"><a target="_blank" :href="'https://www.reddit.com/r/'+sub">r/{{sub}} </a></span>
</h6>
</div>
</div>
<div class="row">
<div class="col s12 m12 center">
<h3>Stats</h3>
<span id="lastUpdated" class="badge orange center">Last updated: ...</span>
</div>
</div>
<div class="row">
<div id="gbbbContainer" class="col s12 m10 offset-m1 center">
<div class="col m3">
<span style="font-size: 1.4em;">GoodBot_BadBot Info</span>
</div>
<div class="col m3">
<span>Rank: <span>...</span></span>
</div>
<div class="col m3">
<span>Score: <span>...</span></span>
</div>
<div class="col m3">
<span>Good: <span>...</span></span>
<span>Bad: <span>...</span></span>
</div>
</div>
</div>
<div class="row">
<div class="col s12 m4">
<div id="freqSubsList" class="collection with-header">
<li class="collection-header"><h5>Top subreddits (comments)</h5></li>
<a href="#!" class="collection-item"><span class="badge">...</span>Loading...</a>
</div>
</div>
<div class="col s12 m8">
<div class="chart-container">
<canvas id="freqSubsChart"></canvas>
</div>
</div>
</div><br>
<div class="row">
<div class="col s12 m8 offset-m2">
<div class="chart-container">
<canvas id="countByDate"></canvas>
</div>
</div>
</div><br>
<div class="row">
<div class="col s12 m4">
<div id="topAuthorsList" class="collection with-header">
<li class="collection-header"><h5>Top darn commenters</h5></li>
<a href="#!" class="collection-item"><span class="badge">...</span>Loading...</a>
</div>
</div>
<div class="col s12 m8">
<div class="chart-container">
<canvas id="freqAuthors"></canvas>
</div>
</div>
</div>
</div>
</div>
</body>
</html>