Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

limiting news feed by user

  • Loading branch information...
commit aff1733832d0cd41f6bdae7401f648e7d9ea9097 1 parent d8db864
@baygross authored
Showing with 96 additions and 60 deletions.
  1. +24 −40 tests/hbase.rb
  2. +21 −20 tests/pg.rb
  3. +51 −0 tests/saddle.rb
View
64 tests/hbase.rb
@@ -4,30 +4,31 @@
require_relative '../seeds/generate.rb'
-class hbase_tester
+class HBaseTest
+
+ def initialize (num_users_requested, num_hashtags_requested, num_users, num_hashtags)
+ @db = Stargate::Client.new( "http://ec2-23-22-57-68.compute-1.amazonaws.com:8080" )
+ end
#params: num_users/num_hashtags requested and total num_users/num_hashtags
#returns object with user_ids and hashtags to be used in the next 3 functions
- def initialize (num_users_requested, num_hashtags_requested, num_users, num_hashtags)
-
- @db=Stargate::Client.new("http://ec2-23-22-57-68.compute-1.amazonaws.com:8080")
-
+ def getTargets
#arrays for users and hashes to be returned
- users=Array.new
- hash=Array.new
+ users = Array.new
+ hash = Array.new
#users
num_users_requested.times do |i|
- users.push((rand*num_users).floor)
+ users.push( (rand*num_users).floor )
end
#hashtags
num_hashtags_requested.times do |i|
- hash.push((rand*num_hashtags).floor)
+ hash.push( (rand*num_hashtags).floor )
end
- ret=Hash.new
- ret={'users' => users, 'hashtags' => hash}
+ # return our final hash
+ {:users => users, :hashtags => hash}
end
#params: user_id and current max tweet_id and current max_tag
@@ -39,41 +40,24 @@ def tweet (user_id, max_tweet, max_tag)
tweet = Generate.randTweet
@db.create_row('users', user_id, Time.now.to_i, {:name => 'info:tweet', :value => max_tweet})
@db.create_row('tweets', max_tweet, Time.now.to_i, {:name => 'content:body', :value => tweet})
-
-
- #add 0-2 hashtags. when adding hashtag, make it new 10% of time
- r = rand
- count=0
-
- #add one hastag to this tweet
- if r < 1/3.to_f
- if r1 < .1
- tag=max_tag
- count+=1
- max_tag+=1
- else
- r1 = rand
- tag = (rand * max_tag).floor
- end
- @db.create_row('hastags', tag, Time.now.to_i, {:name => 'tag:tweet'+max_tweet.to_s, :value => max_tweet})
- end
-
- #add a second hashtag to this tweet
- if r < 2/3.to_f
- if r1 < .1
- tag=max_tag
- count+=1
+
+ #add 0-2 hashtags. when adding hashtag, make it new 10% of time
+ rand(2) .times do
+
+ # 30% of time create new hashtag
+ if rand(3) < 1
+ @db.create_row('hastags', max_tag, Time.now.to_i, {:name => 'tag:body', :value => 'blahNewHashtag'})
+ @db.create_row('hastags', max_tag, Time.now.to_i, {:name => 'tag:tweet' + max_tweet.to_s, :value => max_tweet})
max_tag+=1
+ # otherwise, use an existing hashtag
else
- r1 = rand
tag = (rand * max_tag).floor
+ @db.create_row('hastags', tag, Time.now.to_i, {:name => 'tag:tweet' + max_tweet.to_s, :value => max_tweet})
end
- @db.create_row('hastags', tag, Time.now.to_i, {:name => 'tag:tweet'+max_tweet.to_s, :value => max_tweet})
+
end
-
- #else no hashtags!
- return count
+ return max_tag
end
View
41 tests/pg.rb
@@ -1,30 +1,31 @@
#!/usr/bin/env ruby
-
-#
-# TODO: where do we want to put the db connection?
-#
-
-
-
require 'pg'
require_relative 'generate.rb'
class pg_tester
- #TODO: Add conn
+ def initialize
+ @db = PGconn.open({
+ :host => '',
+ :port => '',
+ :login => '',
+ :password => '',
+ :dbname => 'app1'
+ })
+ end
#params: num_users/num_hashtags requested and total num_users/num_hashtags
#returns object with user_ids and hashtags to be used in the next 3 functions
- def init (num_users_requested, num_hashtags_requested)
+ def getTargets (num_users_requested, num_hashtags_requested)
#Get bounds, assume no delete
- min_user=conn.exec("SELECT MIN(id) FROM users;")
- max_user=conn.exec("SELECT MAX(id) FROM users;")
- min_hash=conn.exec("SELECT MIN(id) FROM hashtags;")
- max_hash=conn.exec("SELECT MIN(id) FROM hashtags;")
+ min_user=@db.exec("SELECT MIN(id) FROM users;")
+ max_user=@db.exec("SELECT MAX(id) FROM users;")
+ min_hash=@db.exec("SELECT MIN(id) FROM hashtags;")
+ max_hash=@db.exec("SELECT MIN(id) FROM hashtags;")
#users
users = (min_user..max_user).to_a.sample(num_users_requested)
@@ -32,8 +33,8 @@ def init (num_users_requested, num_hashtags_requested)
#hashtags
hashtags = (min_hash..max_hash).to_a.sample(num_users_requested)
- ret=Hash.new
- ret={'users' => users, 'hashtags' => hashtags}
+ #return our targets
+ {:users => users, :hashtags => hashtags}
end
#params: user_id and current max tweet_id
@@ -49,19 +50,19 @@ def tweet (user_id, max_tweet)
end
# TODO: Parse the return of this properly
- new_id = conn.exec('INSERT INTO tweets(tweet, user_id) VALUES($1, $2)', [tweet, user_id])
+ new_id = @db.exec('INSERT INTO tweets(tweet, user_id) VALUES($1, $2)', [tweet, user_id])
#random 0-2 hashtags per tweet
r=rand
#add one hastag to this tweet
if r < 2/3.to_f
- conn.exec('INSERT INTO hashtags_tweets(tweet_id, hashtag_id) VALUES ($1, $2)', [new_id, (rand*(max_hash+1-min_hash)+min_hash).floor])
+ @db.exec('INSERT INTO hashtags_tweets(tweet_id, hashtag_id) VALUES ($1, $2)', [new_id, (rand*(max_hash+1-min_hash)+min_hash).floor])
end
#add a second hashtag to this tweet
if r < 1/3.to_f
- conn.exec('INSERT INTO hashtags_tweets(tweet_id, hashtag_id) VALUES ($1, $2)', [new_id, (rand*(max_hash+1-min_hash)+min_hash).floor])
+ @db.exec('INSERT INTO hashtags_tweets(tweet_id, hashtag_id) VALUES ($1, $2)', [new_id, (rand*(max_hash+1-min_hash)+min_hash).floor])
end
end
@@ -69,12 +70,12 @@ def tweet (user_id, max_tweet)
#returns all tweets with a given hashtag (incl assoc user)
def lookup_hashtag (hashtag)
# TODO: If bad performance, we might do a seondary query instead of a join
- conn.exec('SELECT * from tweets t INNER JOIN hashtags_tweets ht ON ht.tweet_id = t.id INNER JOIN users u ON t.user_id = u.id WHERE hashtag_id = $1', [hashtag])
+ @db.exec('SELECT * from tweets t INNER JOIN hashtags_tweets ht ON ht.tweet_id = t.id INNER JOIN users u ON t.user_id = u.id WHERE hashtag_id = $1', [hashtag])
end
#params: user_id
#returns all tweets from a specific user
def lookup_user (user_id)
- conn.exec('SELECT * from tweets t WHERE user_id = $1', [user_id])
+ @db.exec('SELECT * from tweets t WHERE user_id = $1', [user_id])
end
end
View
51 tests/saddle.rb
@@ -0,0 +1,51 @@
+#!/usr/bin/env ruby
+
+require_relative 'db2.rb'
+require_relative 'hbase.rb'
+require_relative 'mongo.rb'
+require_relative 'pg.rb'
+
+#------- Config Variables ----------------------------------------------------
+
+@num_users_requested = 2000
+@num_hashtags_requested = 200
+
+
+#------------------------------------------------------------------------------
+def main
+
+ testSaddle( :pg )
+ testSaddle( :mongo )
+ testSaddle( :hbase )
+ testSaddle( :db2 )
+
+end
+
+#run it
+main
+
+#------------------------------------------------------------------------------
+
+
+def testSaddle( dbslug )
+
+ # Grab the correct DB
+ [ dbslug ] case
+ when :pg
+ @client = PGTest.new();
+ when :mongo
+ @client = MongoTest.new();
+ when :hbase
+ @client = HBaseTest.new();
+ when :db2
+ @client = DB2test.new();
+ end
+
+ #initialize the client
+ targets = @client.getTargets( @num_users_requested, @num_hashtags_requested)
+
+
+
+
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.