Sha256: 9b587789b43e9cf8ba4f26dd0ecc4642fb85ee6cb4c3019979eafafdd9f82f55

Contents?: true

Size: 1.15 KB

Versions: 9

Compression:

Stored size: 1.15 KB

Contents

module Workarea
  module Metrics
    class SearchByDay
      include ByDay

      field :query_id, type: String
      field :query_string, type: String
      field :searches, type: Integer, default: 0
      field :total_results, type: Integer, default: 0
      field :orders, type: Integer, default: 0
      field :units_sold, type: Integer, default: 0
      field :discounted_units_sold, type: Integer, default: 0
      field :merchandise, type: Float, default: 0.0
      field :shipping, type: Float, default: 0.0
      field :discounts, type: Float, default: 0.0
      field :tax, type: Float, default: 0.0
      field :revenue, type: Float, default: 0.0

      index(reporting_on: 1, total_results: 1)
      scope :by_query_id, ->(id) { where(query_id: id) }

      def self.save_search(query_string, total_results, at: Time.current)
        query_string = QueryString.new(query_string)
        return if query_string.id.blank? || query_string.short?

        inc(
          key: { query_id: query_string.id },
          set: { total_results: total_results.to_i, query_string: query_string.pretty },
          at: at,
          searches: 1
        )
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
workarea-core-3.4.20 app/models/workarea/metrics/search_by_day.rb
workarea-core-3.4.19 app/models/workarea/metrics/search_by_day.rb
workarea-core-3.4.18 app/models/workarea/metrics/search_by_day.rb
workarea-core-3.4.17 app/models/workarea/metrics/search_by_day.rb
workarea-core-3.4.16 app/models/workarea/metrics/search_by_day.rb
workarea-core-3.4.15 app/models/workarea/metrics/search_by_day.rb
workarea-core-3.4.14 app/models/workarea/metrics/search_by_day.rb
workarea-core-3.4.13 app/models/workarea/metrics/search_by_day.rb
workarea-core-3.4.12 app/models/workarea/metrics/search_by_day.rb