require 'statsample' class Statistics attr_reader :start_time, :range def initialize #@start_time = start_time #@range = range end def posts_count_sql < 1 , "count" => 123}] post_count_array = User.connection.select_all(self.posts_count_sql) post_count_hash = {} post_count_array.each{ |h| post_count_hash[h[id]] = h["count"]} end ###\ #def correlate(thing) # sql = self.send("#{thing}_count_sql".to_sym) # self.correlation(User.connection.select_all(sql), #end ### def correlation(x_array, y_array) x = x_array.to_scale y = y_array.to_scale pearson = Statsample::Bivariate::Pearson.new(x,y) pearson.r end ### % of cohort came back last week def retention(n) week_created(n).where("current_sign_in_at > ?", Time.now - 1.week).count.to_f/week_created(n).count end protected def week_created(n) User.where("username IS NOT NULL").where("created_at > ? and created_at < ?", Time.now - (n+1).weeks, Time.now - n.weeks) end end