Sha256: 377f35b418ff76f69d4208ddc1b31a5fa253490c0633eb2c5849b785446e750e

Contents?: true

Size: 1.74 KB

Versions: 15

Compression:

Stored size: 1.74 KB

Contents

# Gather information about the depositors who have contributed to the repository
module Sufia
  module Statistics
    module Depositors
      class Summary
        include Blacklight::SearchHelper

        # @param [Time] start_date optionally specify the start date to gather the stats from
        # @param [Time] end_date optionally specify the end date to gather the stats from
        def initialize(start_date, end_date)
          @start_dt = start_date
          @end_dt = end_date
        end

        attr_accessor :start_dt, :end_dt

        def depositors
          # step through the array by twos to get each pair
          results.map do |key, deposits|
            user = ::User.find_by_user_key(key)
            { key: key, deposits: deposits, user: user }
          end
        end

        private

          delegate :blacklight_config, to: CatalogController
          delegate :depositor_field, to: DepositSearchBuilder

          # results come from Solr in an array where the first item is the user and
          # the second item is the count
          # [ abc123, 55, ccczzz, 205 ]
          # @return [#each] an enumerable object of tuples (user and count)
          def results
            facet_results = repository.search(query)
            facet_results.facet_fields[depositor_field].each_slice(2)
          end

          def search_builder
            DepositSearchBuilder.new([:include_depositor_facet], self)
          end

          # TODO: This can probably be pushed into the DepositSearchBuilder
          def query
            search_builder.merge(q: date_query).query
          end

          def date_query
            Sufia::QueryService.new.build_date_query(start_dt, end_dt) unless start_dt.blank?
          end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
sufia-7.4.1 app/services/sufia/statistics/depositors/summary.rb
sufia-7.4.0 app/services/sufia/statistics/depositors/summary.rb
sufia-7.3.1 app/services/sufia/statistics/depositors/summary.rb
sufia-7.3.0 app/services/sufia/statistics/depositors/summary.rb
sufia-7.3.0.rc3 app/services/sufia/statistics/depositors/summary.rb
sufia-7.3.0.rc2 app/services/sufia/statistics/depositors/summary.rb
sufia-7.3.0.rc1 app/services/sufia/statistics/depositors/summary.rb
sufia-7.2.0 app/services/sufia/statistics/depositors/summary.rb
sufia-7.1.0 app/services/sufia/statistics/depositors/summary.rb
sufia-7.0.0 app/services/sufia/statistics/depositors/summary.rb
sufia-7.0.0.rc2 app/services/sufia/statistics/depositors/summary.rb
sufia-7.0.0.rc1 app/services/sufia/statistics/depositors/summary.rb
sufia-7.0.0.beta4 app/services/sufia/statistics/depositors/summary.rb
sufia-7.0.0.beta3 app/services/sufia/statistics/depositors/summary.rb
sufia-7.0.0.beta2 app/services/sufia/statistics/depositors/summary.rb