Skip to content

Instantly share code, notes, and snippets.

@kimyoutora
Created August 9, 2010 21:13
Show Gist options
  • Save kimyoutora/516131 to your computer and use it in GitHub Desktop.
Save kimyoutora/516131 to your computer and use it in GitHub Desktop.
require 'chronic_duration'
ps0=Post.all(:conditions => ["? <= created_at and created_at <= ? ", Time.parse("06/29/2010"), Time.parse("07/05/2010")], :include => :replies)
ps1=Post.all(:conditions => ["? <= created_at and created_at <= ? ", Time.parse("07/06/2010"), Time.parse("07/12/2010")], :include => :replies)
ps2=Post.all(:conditions => ["? <= created_at and created_at <= ? ", Time.parse("07/13/2010"), Time.parse("07/19/2010")], :include => :replies)
ps3=Post.all(:conditions => ["? <= created_at and created_at <= ? ", Time.parse("07/20/2010"), Time.parse("07/26/2010")], :include => :replies)
ps4=Post.all(:conditions => ["? <= created_at and created_at <= ? ", Time.parse("07/27/2010"), Time.parse("08/02/2010")], :include => :replies)
def ttfr(posts, discard_elapsed_time = 7.days)
sum_resp_time = 0
unanswered_count = 0
ttfr_15_min = 0
ttfr_60_min = 0
total_posts = posts.size
total_replies = 0
posts.each do |p|
ttfr_duration = (p.replies.first.created_at - p.created_at) rescue 0
if p.replies.blank? || ttfr_duration >= discard_elapsed_time
unanswered_count += 1
else
sum_resp_time += ttfr_duration
ttfr_15_min += 1 if ttfr_duration <= 15.minutes
ttfr_60_min += 1 if ttfr_duration <= 60.minutes
end
total_replies += p.replies.size
end
puts "Total Posts: #{total_posts}, Total Replies: #{total_replies}, Average TTFR: #{sum_resp_time/total_posts} (#{ChronicDuration.output(sum_resp_time/total_posts)}), % TTFR <= 15min: #{ttfr_15_min/total_posts.to_f}, % TTFR <= 60min: #{ttfr_60_min/total_posts.to_f}, unanswered: #{unanswered_count}"
end
%w(ps0 ps1 ps2 ps3 ps4).each do |ps|
ttfr(ps)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment