Sha256: 4bdeefbf9c0802019fbaa8cd6041bec77d25fd40ca6ba9a01444c67860f34bdd
Contents?: true
Size: 1.1 KB
Versions: 4
Compression:
Stored size: 1.1 KB
Contents
module Sufia module WorkStatUtils 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(work_id, start_date, _method) stats = where(work_id: work_id).order(date: :asc) ga_start_date = !stats.empty? ? 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(work_id, start_date, object_method, ga_key, user_id = nil) stat_cache_info = cached_stats(work_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], work_id) ga_stats.each do |stat| lstat = new work_id: work_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