Created
June 22, 2012 10:47
-
-
Save plotti/2972028 to your computer and use it in GitHub Desktop.
delayed Jobs
This file contains hidden or 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
# A version that used delayed jobs to split the work among a lot of workers | |
# Deprecated because the bottleneck was querying the DB | |
# Same as find all valued connections only trying to make it faster | |
def find_delayed_at_connections(friend = true, follower = false, category = false) | |
usernames = persons.collect{|p| p.username} | |
persons.each do |person| | |
Delayed::Job.enqueue(AggregateAtConnectionsJob.new(person.id,self.id,usernames)) | |
end | |
wait_for_jobs("AggregateAtConnectionsJob") | |
self.return_delayed_at_connections | |
end | |
def return_delayed_at_connections | |
values = [] | |
persons.each do |person| | |
filename = "#{RAILS_ROOT}/analysis/data/tmp/person_#{person.id}_project_#{self.id}_AT.edges" | |
puts "Working on #{filename}" | |
values += FasterCSV.read(filename) | |
end | |
#Merge counted pairs | |
hash = values.group_by { |first, second, third| [first,second] } | |
return hash.map{|k,v| [k,v.count].flatten} | |
end | |
# A version that used delayed jobs to split the work among a lot of workers | |
# Deprecated because the bottleneck was querying the DB | |
def self.find_delayed_at_connections_for_person_and_project(person_id,project_id,usernames) | |
person = Person.find(person_id) | |
project = Project.find(project_id) | |
filename = "#{RAILS_ROOT}/analysis/data/tmp/person_#{person.id}_project_#{project.id}_AT.edges" | |
if File.exists? filename | |
puts "Skipping person #{person.username}" | |
else | |
outfile = File.open(filename, "w+") | |
person.feed_entries.each do |tweet| | |
usernames.each do |tmp_user| | |
if tmp_user != person.username && tweet.retweet_ids == [] && tweet.text.include?("@#{tmp_user} ") && !tweet.text.include?("RT") | |
puts tweet.text | |
outfile.puts "#{person.username},#{tmp_user},#{1},#{tweet.id}" | |
end | |
end | |
end | |
outfile.close | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment