Skip to content

Commit 312139d

Browse files
committed
comments
1 parent 4f36311 commit 312139d

File tree

5 files changed

+46
-35
lines changed

5 files changed

+46
-35
lines changed

public/javascripts/vendor/d3.layout.cloud.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,9 @@
6363
event.end(tags, bounds);
6464
BirdWatch.renderingFinished = true;
6565
BirdWatch.lastCloudUpdate = new Date().getTime();
66-
67-
console.log(" BirdWatch.renderingFinished = true;")
6866
}
6967
}
70-
}
68+
};
7169

7270
cloud.stop = function() {
7371
if (timer) {

public/js/react-app.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var BirdWatch = BirdWatch || {};
4141

4242
/** single Tweet component */
4343
var Tweet = React.createClass({
44-
render: function() { return (
44+
render: function () { return (
4545
<div className="tweet">
4646
<span>
4747
<a href={"http://www.twitter.com/" + this.props.t.screen_name} target="_blank">
@@ -60,7 +60,7 @@ var BirdWatch = BirdWatch || {};
6060
<FavoriteCount count={this.props.t.favorite_count} />
6161
</div>
6262
</div>
63-
);}
63+
); }
6464
});
6565

6666
/** Tweet list component, renders all Tweet items (above) */
@@ -75,6 +75,8 @@ var BirdWatch = BirdWatch || {};
7575
}
7676
});
7777

78+
var tweetListComp = React.renderComponent(<TweetList />, document.getElementById('tweet-frame'));
79+
7880
/** TweetCount shows the number of tweets analyzed */
7981
var TweetCount = React.createClass({
8082
render: function () { return <span>{this.props.count}</span>;}
@@ -96,7 +98,6 @@ var BirdWatch = BirdWatch || {};
9698
/** render BirdWatch components */
9799
var tweetCount = React.renderComponent(<TweetCount count={0}/>, document.getElementById('tweet-count'));
98100
var WordQueueSize = React.renderComponent(<WordQueueSize count={0}/>, document.getElementById('word-queue-size'));
99-
var tweetListComp = React.renderComponent(<TweetList />, document.getElementById('tweet-frame'));
100101

101102
BirdWatch.setTweetCount = function (n) { tweetCount.setProps({count: n}); };
102103
BirdWatch.setPQueueSize = function (n) { WordQueueSize.setProps({count: n}); };
@@ -113,7 +114,6 @@ var BirdWatch = BirdWatch || {};
113114

114115
if (BirdWatch.renderingFinished && (new Date().getTime() - BirdWatch.lastCloudUpdate) > 10000) {
115116
BirdWatch.renderingFinished = false;
116-
console.log("cloud render started")
117117
//BirdWatch.haltQueue();
118118
wordCloud.redraw(wordCounts);
119119
}

scala-js/src/main/scala/com/matthiasnehlsen/birdwatch/App.scala

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,28 @@ object App {
1313

1414
/** application state modeled as immutable maps in vars (not shared with other application parts) */
1515
private var tweetMap: TreeMap[Long, TypedTweet] = TreeMap.empty(reverseLongOrdering)
16+
17+
/** set for keeping track of number of tweets immediately (so that tweetMap still has previous tweet available
18+
* when adding to other sorting maps) */
1619
private val tweetIds: scala.collection.mutable.TreeSet[Long] = scala.collection.mutable.TreeSet.empty(reverseLongOrdering)
17-
private var followersMap: TreeMap[Int, HashSet[TypedTweet]] = TreeMap.empty(reverseIntOrdering)
18-
private var rtMap: TreeMap[Int, HashSet[TypedTweet]] = TreeMap.empty(reverseIntOrdering)
19-
private var favoritesMap: TreeMap[Int, HashSet[TypedTweet]] = TreeMap.empty(reverseIntOrdering)
2020

21-
private def addToSortingMap[T](id: Int, t: T, map: TreeMap[Int, HashSet[T]]): TreeMap[Int, HashSet[T]] = {
22-
map + (id -> (map.getOrElse(id, HashSet[T]()) + t))
23-
}
21+
/** maps for keeping followers / retweets / favorites count as key and Set with all matching Tweets as value
22+
* on update tweet will be removed from old set and inserted into set at new position when updated tweet is received
23+
* by means of retweets (e.g remove at 100 retweets, insert new tweet representation at 101 retweets) */
24+
private var followersMap: TreeMap[Int, Set[TypedTweet]] = TreeMap.empty(reverseIntOrdering)
25+
private var rtMap: TreeMap[Int, Set[TypedTweet]] = TreeMap.empty(reverseIntOrdering)
26+
private var favoritesMap: TreeMap[Int, Set[TypedTweet]] = TreeMap.empty(reverseIntOrdering)
2427

25-
def removeFromSortingMap[T](id: Int, t: T, map: TreeMap[Int, HashSet[T]]): TreeMap[Int, HashSet[T]] = {
26-
map + (id -> (map.getOrElse(id, HashSet[T]()) - t))
28+
/** adding and removing from data structures above -> should probably be refactored into its own class */
29+
private def addToSortingMap[T](id: Int, t: T, map: TreeMap[Int, Set[T]]): TreeMap[Int, Set[T]] = {
30+
map + (id -> (map.getOrElse(id, Set[T]()) + t))
2731
}
28-
29-
def addTweetImmediately(t: TypedTweet): Unit = {
30-
tweetIds += t.id
31-
BirdWatch.setTweetCount(tweetCount)
32-
33-
tweetMap.get(t.id).map {
34-
prev => {
35-
rtMap = removeFromSortingMap(prev.retweet_count, prev, rtMap)
36-
followersMap = removeFromSortingMap(prev.followers_count, prev, followersMap)
37-
favoritesMap = removeFromSortingMap(prev.favorite_count, prev, favoritesMap)
38-
}
39-
}
40-
41-
if (t.retweet_count > 0) { rtMap = addToSortingMap(t.retweet_count, t, rtMap) }
42-
if (t.followers_count > 0) { followersMap = addToSortingMap(t.followers_count, t, followersMap) }
43-
if (t.favorite_count > 0) { favoritesMap = addToSortingMap(t.favorite_count, t, favoritesMap) }
44-
45-
tweetMap = tweetMap + (t.id -> t)
32+
def removeFromSortingMap[T](id: Int, t: T, map: TreeMap[Int, Set[T]]): TreeMap[Int, Set[T]] = {
33+
map + (id -> (map.getOrElse(id, Set[T]()) - t))
4634
}
4735

36+
/** function for adding tweets, only called for previous tweets. previous tweets are loaded backwards in time,
37+
* therefore updating tweets existing tweets is not necessary (as the previous tweet going back in time will be older) */
4838
def addTweet(t: TypedTweet)(): Unit = {
4939
/** if previous version exists: remove from map and sets first */
5040
if (!tweetMap.contains(t.id)) {
@@ -55,6 +45,7 @@ object App {
5545
}
5646
}
5747

48+
/** put curried addTweet function call on priority queue in order to be performed later */
5849
def enqueueTweet(t: TypedTweet): Unit = {
5950
if (!tweetMap.contains(t.id)) {
6051
tweetIds += t.id
@@ -64,12 +55,34 @@ object App {
6455
}
6556
}
6657

58+
/** add new tweet from SSE stream, needs to update existing tweets as whatever comes in here will be newer
59+
* (retweeted tweets re-appear in their entirety in the retweet_status property of a tweets JSON representation) */
60+
def addTweetImmediately(t: TypedTweet): Unit = {
61+
tweetIds += t.id
62+
BirdWatch.setTweetCount(tweetCount) // update UI with new count
63+
tweetMap.get(t.id).map {
64+
prev => {
65+
rtMap = removeFromSortingMap(prev.retweet_count, prev, rtMap)
66+
followersMap = removeFromSortingMap(prev.followers_count, prev, followersMap)
67+
favoritesMap = removeFromSortingMap(prev.favorite_count, prev, favoritesMap)
68+
}
69+
}
70+
71+
if (t.retweet_count > 0) { rtMap = addToSortingMap(t.retweet_count, t, rtMap) }
72+
if (t.followers_count > 0) { followersMap = addToSortingMap(t.followers_count, t, followersMap) }
73+
if (t.favorite_count > 0) { favoritesMap = addToSortingMap(t.favorite_count, t, favoritesMap) }
74+
75+
tweetMap = tweetMap + (t.id -> t)
76+
}
77+
78+
/** lazily evaluate sorted tweets for each sort order */
6779
def tweetsByIdDesc(n: Int, skip: Int) = tweetMap.values.toIterator.drop(skip).take(n)
6880
def tweetsByFollowersDesc(n: Int, skip: Int) = followersMap.values.toIterator.flatten.drop(skip).take(n)
6981
def tweetsByRetweetsDesc(n: Int, skip: Int) = rtMap.values.flatten.toIterator.drop(skip).take(n)
7082
def tweetsByFavoritesDesc(n: Int, skip: Int) = favoritesMap.values.flatten.toIterator.drop(skip).take(n)
7183
def tweetCount = tweetIds.size
7284

85+
/** reset application state when starting new query*/
7386
def empty(): Unit = {
7487
tweetMap = TreeMap.empty(reverseLongOrdering)
7588
followersMap = TreeMap.empty(reverseIntOrdering)

scala-js/src/main/scala/com/matthiasnehlsen/birdwatch/PrioExecQueue.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object PrioExecQueue {
2121
if (exec.timeout > 0) { InterOp.setTimeout(pQueueNext, exec.timeout) }
2222
else if (dequeueCounter % 200 == 0) {
2323
InterOp.setTimeout(pQueueNext, 0)
24-
InterOp.triggerReactWordcount()
24+
InterOp.triggerReact()
2525
BirdWatch.setPQueueSize(execPQueue.size)
2626
}
2727
else pQueueNext()

scala-js/src/main/scala/com/matthiasnehlsen/birdwatch/WordCount.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ object WordCount {
3131
def addWord(word: String): Unit = {
3232
val lowerCaseWord = word.toLowerCase
3333
if (!stopWords.contains(lowerCaseWord) && lowerCaseWord.length > 2) {
34-
addToPQueue(Exec(Some(countWord(lowerCaseWord)_), 0, 20))
34+
addToPQueue(Exec(Some(countWord(lowerCaseWord)_), 0, 0))
3535
}
3636
}
3737

0 commit comments

Comments
 (0)