-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodel.js
More file actions
59 lines (51 loc) · 1.3 KB
/
model.js
File metadata and controls
59 lines (51 loc) · 1.3 KB
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
var metrics = {
seconds: 0,
positiveTweetCount: 0,
neutralTweetCount: 0,
negativeTweetCount: 0,
positivePerSecond: 0,
neutralPerSecond: 0,
negativePerSecond: 0
}
function analyzeSentimentValue(new_tweet){
updateTally(new_tweet.score);
if (new_tweet.score > 0){
insertTweet(new_tweet, "green");
} else if (new_tweet.score == 0){
insertTweet(new_tweet, "black");
} else {
insertTweet(new_tweet, "red");
}
$('#tweets')[0].scrollTop = $('#tweets')[0].scrollHeight;
};
function updateTally(score){
updateViewMetrics();
if (score > 0){
metrics.positiveTweetCount++;
metrics.positivePerSecond = Math.round(100*metrics.positiveTweetCount/metrics.seconds)/100;
} else if (score == 0){
metrics.neutralTweetCount++;
metrics.neutralPerSecond = Math.round(100*metrics.neutralTweetCount/metrics.seconds)/100;
} else {
metrics.negativeTweetCount++;
metrics.negativePerSecond = Math.round(100*metrics.negativeTweetCount/metrics.seconds)/100;
}
}
$(document).ready(function(){
bindEventListeners();
})
function bindEventListeners(){
$("button").click(function(){
resetMetrics();
})
}
// resets metrics when the 'restart clock' button is selected.
function resetMetrics(){
for(property in metrics){
metrics[property] = 0;
}
clearFirebase();
}
function clearFirebase(){
dataRef.remove();
}