Created
June 22, 2012 10:27
-
-
Save plotti/2971911 to your computer and use it in GitHub Desktop.
Finding at-connectiosn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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