Sha256: 5122b72e6ccf7a9df48314fe9dbfa6ec1c9d2b0c7eeaa4aec091217e7d47e76d

Contents?: true

Size: 1.33 KB

Versions: 58

Compression:

Stored size: 1.33 KB

Contents

module Hyrax
  # Methods used by both WorkUsage and FileUsage
  class StatsUsagePresenter
    attr_accessor :id, :model

    def created
      @created ||= date_for_analytics
    end

    private

      def user_id
        @user_id ||= begin
                       user = Hydra::Ability.user_class.find_by_user_key(model.depositor)
                       user ? user.id : nil
                     end
      end

      # TODO: make this a lazy enumerator
      def to_flots(stats)
        stats.map(&:to_flot)
      end

      # model.date_uploaded reflects the date the object was uploaded by the user
      # and therefore (if available) the date that we want to use for the stats
      # model.create_date reflects the date the file was added to Fedora. On data
      # migrated from one repository to another the created_date can be later
      # than the date the file was uploaded.
      def date_for_analytics
        earliest = Hyrax.config.analytic_start_date
        date_uploaded = string_to_date(model.date_uploaded)
        date_analytics = date_uploaded ? date_uploaded : model.create_date
        return date_analytics if earliest.blank?
        earliest > date_analytics ? earliest : date_analytics
      end

      def string_to_date(date_str)
        Time.zone.parse(date_str)
      rescue ArgumentError, TypeError
        nil
      end
  end
end

Version data entries

58 entries across 58 versions & 2 rubygems

Version Path
hyrax-2.9.6 app/presenters/hyrax/stats_usage_presenter.rb
hyrax-2.9.5 app/presenters/hyrax/stats_usage_presenter.rb
hyrax-2.9.4 app/presenters/hyrax/stats_usage_presenter.rb
hyrax-2.9.3 app/presenters/hyrax/stats_usage_presenter.rb
hyrax-2.9.2 app/presenters/hyrax/stats_usage_presenter.rb
hyrax-2.9.1 app/presenters/hyrax/stats_usage_presenter.rb
hyrax-2.9.0 app/presenters/hyrax/stats_usage_presenter.rb
hyrax-2.8.0 app/presenters/hyrax/stats_usage_presenter.rb
hyrax-2.7.2 app/presenters/hyrax/stats_usage_presenter.rb
hyrax-2.7.1 app/presenters/hyrax/stats_usage_presenter.rb
hyrax-2.7.0 app/presenters/hyrax/stats_usage_presenter.rb
hyrax-2.6.0 app/presenters/hyrax/stats_usage_presenter.rb
hyrax-3.0.0.pre.rc1 app/presenters/hyrax/stats_usage_presenter.rb
hyrax-3.0.0.pre.beta3 app/presenters/hyrax/stats_usage_presenter.rb
hyrax-2.5.1 app/presenters/hyrax/stats_usage_presenter.rb
hyrax-2.5.0 app/presenters/hyrax/stats_usage_presenter.rb
hyrax-3.0.0.pre.beta2 app/presenters/hyrax/stats_usage_presenter.rb
hyrax-2.4.1 app/presenters/hyrax/stats_usage_presenter.rb
hyrax-3.0.0.pre.beta1 app/presenters/hyrax/stats_usage_presenter.rb
hyrax-2.4.0 app/presenters/hyrax/stats_usage_presenter.rb