Skip to content

Instantly share code, notes, and snippets.

@plotti
Created June 22, 2012 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plotti/2971911 to your computer and use it in GitHub Desktop.
Save plotti/2971911 to your computer and use it in GitHub Desktop.
Finding at-connectiosn
def find_at_connections()
values = []
usernames = persons.collect{|p| p.username}
i = 0
persons.each do |person|
t1 = Time.now
i += 1
person.feed_entries.each do |tweet|
#puts "#Analyzing tweet #{tweet.id}"
usernames.each do |tmp_user|
if tweet.text.include?("@" + tmp_user + " ") && !tweet.text.include?("RT")
#if the tweet has not been retweeted hence is not a retweet
if tweet.retweet_ids == [] && person.username != tmp_user
values << [person.username,tmp_user,1]
end
end
end
end
t2 = Time.now
puts("Analyzing ( " + i.to_s + "/" + persons.count.to_s + ") " + person.username + " for talk connections. Time per person: #{t2- t1}")
end
#Merge counted pairs
hash = values.group_by { |first, second, third| [first,second] }
return hash.map{|k,v| [k,v.count].flatten}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment