Sha256: 18b433aa30204334332b4e8d2aa8fb6d9299b6daba37ff9452a701faf655dfd4

Contents?: true

Size: 1.85 KB

Versions: 19

Compression:

Stored size: 1.85 KB

Contents

module Hyrax
  class AdminStatsPresenter
    attr_reader :limit, :stats_filters

    def initialize(stats_filters, limit)
      @stats_filters = stats_filters
      @limit = limit
    end

    def start_date
      @start_date ||= extract_date_from_stats_filters(key: :start_date, as_of: :beginning_of_day)
    end

    def end_date
      @end_date ||= extract_date_from_stats_filters(key: :end_date, as_of: :end_of_day)
    end

    private

      def extract_date_from_stats_filters(key:, as_of:)
        return if stats_filters[key].blank?
        Time.zone.parse(stats_filters[key]).public_send(as_of)
      end

    public

    # @see Hyrax::Statistics::Depositors::Summary
    def depositors
      @depositors ||= Hyrax::Statistics::Depositors::Summary.depositors(start_date: start_date, end_date: end_date)
    end

    # @see Hyrax::Statistics::SystemStats.recent_users
    def recent_users
      @recent_users ||= Hyrax::Statistics::SystemStats.recent_users(limit: limit, start_date: start_date, end_date: end_date)
    end

    # @see Hyrax::Statistics::Works::ByDepositor
    def active_users
      @active_users ||= Hyrax::Statistics::Works::ByDepositor.query(limit: limit)
    end

    # @see Hyrax::Statistics::FileSets::ByFormat
    def top_formats
      @top_formats ||= Hyrax::Statistics::FileSets::ByFormat.query(limit: limit)
    end

    # @see Hyrax::Statistics::Works::Count
    def works_count
      @works_count ||= Hyrax::Statistics::Works::Count.by_permission(start_date: start_date, end_date: end_date)
    end

    def date_filter_string
      if start_date.blank?
        "unfiltered"
      elsif end_date.blank?
        "#{start_date.to_date.to_formatted_s(:standard)} to #{Date.current.to_formatted_s(:standard)}"
      else
        "#{start_date.to_date.to_formatted_s(:standard)} to #{end_date.to_date.to_formatted_s(:standard)}"
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
hyrax-2.0.3 app/presenters/hyrax/admin_stats_presenter.rb
hyrax-2.1.0 app/presenters/hyrax/admin_stats_presenter.rb
hyrax-2.1.0.rc4 app/presenters/hyrax/admin_stats_presenter.rb
hyrax-2.1.0.rc3 app/presenters/hyrax/admin_stats_presenter.rb
hyrax-2.1.0.rc2 app/presenters/hyrax/admin_stats_presenter.rb
hyrax-2.1.0.rc1 app/presenters/hyrax/admin_stats_presenter.rb
hyrax-2.1.0.beta2 app/presenters/hyrax/admin_stats_presenter.rb
hyrax-2.0.2 app/presenters/hyrax/admin_stats_presenter.rb
hyrax-2.1.0.beta1 app/presenters/hyrax/admin_stats_presenter.rb
hyrax-2.0.1 app/presenters/hyrax/admin_stats_presenter.rb
hyrax-2.0.0 app/presenters/hyrax/admin_stats_presenter.rb
hyrax-2.0.0.rc3 app/presenters/hyrax/admin_stats_presenter.rb
hyrax-2.0.0.rc2 app/presenters/hyrax/admin_stats_presenter.rb
hyrax-2.0.0.rc1 app/presenters/hyrax/admin_stats_presenter.rb
hyrax-2.0.0.beta5 app/presenters/hyrax/admin_stats_presenter.rb
hyrax-2.0.0.beta4 app/presenters/hyrax/admin_stats_presenter.rb
hyrax-2.0.0.beta3 app/presenters/hyrax/admin_stats_presenter.rb
hyrax-2.0.0.beta2 app/presenters/hyrax/admin_stats_presenter.rb
hyrax-2.0.0.beta1 app/presenters/hyrax/admin_stats_presenter.rb