Sha256: 01f74a01e5790da1bdf6feb230fda4a8981fbd305778553243fe5374f0599541

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 KB

Contents

module Sufia
  module FileStatUtils
    def to_flots(stats)
      stats.map(&: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 = 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 = 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

6 entries across 6 versions & 1 rubygems

Version Path
sufia-models-6.7.0 app/models/concerns/sufia/file_stat_utils.rb
sufia-models-6.6.1 app/models/concerns/sufia/file_stat_utils.rb
sufia-models-6.6.0 app/models/concerns/sufia/file_stat_utils.rb
sufia-models-6.5.0 app/models/concerns/sufia/file_stat_utils.rb
sufia-models-6.4.0 app/models/concerns/sufia/file_stat_utils.rb
sufia-models-6.3.0 app/models/concerns/sufia/file_stat_utils.rb