This repository has been archived by the owner on Oct 3, 2023. It is now read-only.
forked from IBM/watson-twitch-tone-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
191 lines (166 loc) · 5.96 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
<!doctype html>
<html>
<head>
<title>Watson: Twitch Chat Sentiment Anaysis</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font: 13px Helvetica, Arial; }
form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
#messages { list-style-type: none; margin: 0; padding: 0; }
#messages li { padding: 5px 10px; }
#messages li:nth-child(odd) { background: #eee; }
</style>
<style>
#chart {
position: relative;
left: 40px;
}
#y_axis {
position: absolute;
top: 0;
bottom: 0;
width: 40px;
}
</style>
<script src="/socket.io/socket.io.js"></script>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script src="js/md5.min.js"></script>
<script src="js/d3.min.js"></script>
<script src="js/d3.layout.min.js"></script>
<script src="js/rickshaw.min.js"></script>
<!-- bootstrap -->
<!-- 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">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<!-- bootstrap tables -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.11.0/bootstrap-table.min.css">
</head>
<body>
<div class="container">
<div class="page-header">
<h1>Watson: Twitch Chat Tone Analysis</h1>
<p class="lead">Watson Tone analysis of twitch chat. Uses node, socket.io, tmi, and rickshaw. Github: https://github.com/nibalizer/watson-twitch-tone-analysis</p>
</div>
<div class="col-md-4">
<h2>Conscientiousness</h2>
<div id="chart-Conscientiousness"></div>
</div>
<div class="col-md-4">
<h2>Openness</h2>
<div id="chart-Openness"></div>
</div>
<div class="col-md-4">
<h2>Extraversion</h2>
<div id="chart-Extraversion"></div>
</div>
<div class="col-md-4">
<h2>Agreeableness</h2>
<div id="chart-Agreeableness"></div>
</div>
<div class="col-md-4">
<h2>Anger</h2>
<div id="chart-Anger"></div>
</div>
<div class="col-md-4">
<h2>Joy</h2>
<div id="chart-Joy"></div>
</div>
<div class="col-md-4">
<h2>Disgust</h2>
<div id="chart-Disgust"></div>
</div>
<div class="col-md-4">
<h2>Sadness</h2>
<div id="chart-Sadness"></div>
</div>
<div class="col-md-4">
<h2>Fear</h2>
<div id="chart-Fear"></div>
</div>
<div class="col-md-4">
<h2>Analytical</h2>
<div id="chart-Analytical"></div>
</div>
<div class="col-md-4">
<h2>Confident</h2>
<div id="chart-Confident"></div>
</div>
<div class="col-md-4">
<h2>Tentative</h2>
<div id="chart-Tentative"></div>
</div>
</div>
<script>
$(function () {
var socket = io();
$('form').submit(function(){
socket.emit('chat message', $('#m').val());
$('#m').val('');
return false;
});
});
</script>
<script>
var tone_categories = [
[ "Anger", "Disgust", "Fear", "Joy", "Sadness"],
[ "Analytical", "Confident", "Tentative"],
[ "Conscientiousness", "Openness", "Extraversion", "Agreeableness"]
];
$(tone_categories).each( function(index,val) {
$(val).each( function(jndex,value) {
var tone = value;
var graph_selector = "#chart-" + tone;
var tv = 250;
var historical_data = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
var data = [ { x: 0, y: 0.4 }, { x: 1, y: 0.49 }, { x: 2, y: 0.17 }, { x: 3, y: 0.21 } ];
var color = "#" + md5(tone).substr(26);
console.log(color);
// create graph
var graph = new Rickshaw.Graph( {
element: document.querySelector(graph_selector),
//width: 900,
height: 250,
min: 0,
max: 1,
renderer: 'line',
series: new Rickshaw.Series.FixedDuration([{ name: 'one', 'color': color}], undefined, {
timeInterval: tv,
maxDataPoints: 100,
timeBase: new Date().getTime() / 1000
})
} );
graph.render();
// add some data every so often
var i = 0;
var iv = setInterval( function() {
var sum = 0;
$(historical_data).each(function(index, value) {
sum += value;
});
avg = sum / 20.;
var data = { one: avg};
graph.series.addData(data);
graph.render();
}, tv );
var socket = io();
socket.on('chat message', function(msg){
var score = msg['tone_categories'][index]['tones'][jndex]['score']
var tone_name = msg['tone_categories'][index]['tones'][jndex]['tone_name']
//$('#messages').append($('<li>').text(tone_name + ": " + score));
historical_data.shift();
historical_data.push(score);
var data = { one: score };
graph.series.addData(data);
graph.render();
});
});
});
</script>
</body>
</html>