Sha256: 33b6e6d49d42da911d6d88ca210f3c8b850b221a7d9bb02c1200b4cd3bee1e34

Contents?: true

Size: 1.07 KB

Versions: 20

Compression:

Stored size: 1.07 KB

Contents

module Sufia
  module FileStatUtils

    def to_flots stats
      stats.map {|stat| stat.to_flot}
    end

    def convert_date date_time
      date_time.to_datetime.to_i * 1000
    end

    private

    def cached_stats(file_id, start_date, method)
      stats = self.where(file_id:file_id).order(date: :asc)
      ga_start_date = stats.size > 0 ? stats[stats.size-1].date + 1.day : start_date.to_date
      {ga_start_date: ga_start_date, cached_stats: stats.to_a }
    end

    def combined_stats file_id, start_date, object_method, ga_key, user_id=nil
      stat_cache_info = cached_stats( file_id, start_date, object_method)
      stats = stat_cache_info[:cached_stats]
      if stat_cache_info[:ga_start_date] < Date.today
        ga_stats =  ga_statistics(stat_cache_info[:ga_start_date], file_id)
        ga_stats.each do |stat|
          lstat = self.new file_id: file_id, date: stat[:date], object_method => stat[ga_key], user_id: user_id
          lstat.save unless Date.parse(stat[:date]) == Date.today
          stats << lstat
        end
      end
      stats
    end

  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
sufia-models-6.2.0 app/models/concerns/sufia/file_stat_utils.rb
sufia-models-6.1.0 app/models/concerns/sufia/file_stat_utils.rb
sufia-5.0.0 sufia-models/app/models/concerns/sufia/file_stat_utils.rb
sufia-models-5.0.0 app/models/concerns/sufia/file_stat_utils.rb
sufia-models-6.0.0 app/models/concerns/sufia/file_stat_utils.rb
sufia-6.0.0 sufia-models/app/models/concerns/sufia/file_stat_utils.rb
sufia-6.0.0.rc4 sufia-models/app/models/concerns/sufia/file_stat_utils.rb
sufia-models-6.0.0.rc4 app/models/concerns/sufia/file_stat_utils.rb
sufia-6.0.0.rc3 sufia-models/app/models/concerns/sufia/file_stat_utils.rb
sufia-models-6.0.0.rc3 app/models/concerns/sufia/file_stat_utils.rb
sufia-5.0.0.rc1 sufia-models/app/models/concerns/sufia/file_stat_utils.rb
sufia-models-5.0.0.rc1 app/models/concerns/sufia/file_stat_utils.rb
sufia-6.0.0.rc2 sufia-models/app/models/concerns/sufia/file_stat_utils.rb
sufia-models-6.0.0.rc2 app/models/concerns/sufia/file_stat_utils.rb
sufia-6.0.0.rc1 sufia-models/app/models/concerns/sufia/file_stat_utils.rb
sufia-models-6.0.0.rc1 app/models/concerns/sufia/file_stat_utils.rb
sufia-4.3.1 sufia-models/app/models/concerns/sufia/file_stat_utils.rb
sufia-models-4.3.1 app/models/concerns/sufia/file_stat_utils.rb
sufia-6.0.0.beta1 sufia-models/app/models/concerns/sufia/file_stat_utils.rb
sufia-models-6.0.0.beta1 app/models/concerns/sufia/file_stat_utils.rb