-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
44 lines (41 loc) · 1.61 KB
/
main.js
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
function render(tweets, sents, time) {
$("#main").html(time.toTimeString());
for(var i = 0; i < tweets.length; i++) {
var tweetsHTML = "";
var words = tweets[i].split(" ");
for(var j = 0; j < words.length; j++) {
var word = words[j];
var sent = sents[word];
if(!sent) {sent = 0;}
var neg = sent < 0;
sent = Math.min(Math.floor(Math.abs(sent)), 4);
if(neg) {sent = -sent;}
tweetsHTML += '<span class="sent-' + sent + '">' + word + '</span> ';
}
$("#main").append("<div>" + tweetsHTML + "</div><br>");
}
}
function ready(periodsData, sentiments) {
var val = 0;
var old = null;
var startDate = new Date("February 2, 2014 18:30:00");
$("#periodSel").change(function() {
val = $(this).val();
clearTimeout(old);
old = setTimeout(function() {
console.log("render");
render(periodsData[val], sentiments, new Date(startDate.getTime() + val * 1000 * 60));
}, 100);
});
render(periodsData[0], sentiments, startDate);
}
$.ajax("https://cdn.rawgit.com/gt-big-data/SuperBowl2014/431a0a09/ridiculous-sentences.json", {success: function(data){
periodsData = {};
max = (min = data[0].per);
for(var i = 0; i < data.length; i++) {
periodsData[data[i].per] = data[i].tweets;
if(data[i].per > max) {max = data[i].per;}
if(data[i].per < min) {min = data[i].per;}
}
$.ajax("https://cdn.rawgit.com/gt-big-data/SuperBowl2014/431a0a09/sentiments.json", {success: function(data) {ready(periodsData, data);}});
}});