Sha256: 4c382d9bfc23980c01f26281101cfbf495bf5a7ddbe1213ddf323704d12ecc0c

Contents?: true

Size: 1.09 KB

Versions: 4

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.any? ? 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] < Time.zone.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]) == Time.zone.today
            stats << lstat
          end
        end
        stats
      end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sufia-7.0.0.beta4 app/models/concerns/sufia/file_stat_utils.rb
sufia-7.0.0.beta3 app/models/concerns/sufia/file_stat_utils.rb
sufia-7.0.0.beta2 app/models/concerns/sufia/file_stat_utils.rb
sufia-7.0.0.beta1 app/models/concerns/sufia/file_stat_utils.rb