Class: CodeSunset::AnalyticsFilters

Inherits:
Object
  • Object
show all
Defined in:
lib/code_sunset/analytics_filters.rb

Constant Summary collapse

RAW_DIMENSION_KEYS =
%i[org_id user_id plan paid_only exclude_internal].freeze

Instance Method Summary collapse

Constructor Details

#initialize(filters = {}) ⇒ AnalyticsFilters

Returns a new instance of AnalyticsFilters.



5
6
7
# File 'lib/code_sunset/analytics_filters.rb', line 5

def initialize(filters = {})
  @filters = filters.to_h.symbolize_keys
end

Instance Method Details

#raw_dimension_filters? ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/code_sunset/analytics_filters.rb', line 9

def raw_dimension_filters?
  raw_dimension_keys.any? { |key| filters[key].present? }
end

#raw_dimension_keys ⇒ Object



13
14
15
# File 'lib/code_sunset/analytics_filters.rb', line 13

def raw_dimension_keys
  (RAW_DIMENSION_KEYS + CodeSunset.configuration.custom_filters.keys).select { |key| filters[key].present? }
end

#raw_filter_notice ⇒ Object



37
38
39
40
41
42
# File 'lib/code_sunset/analytics_filters.rb', line 37

def raw_filter_notice
  return unless raw_dimension_filters?

  keys = raw_dimension_keys.map { |key| filter_label_for(key) }.join(", ")
  "Filters for #{keys} use retained raw events only. Historical results are limited to the last #{CodeSunset.configuration.event_retention_days} days."
end

#raw_filters ⇒ Object



17
18
19
# File 'lib/code_sunset/analytics_filters.rb', line 17

def raw_filters
  filters.slice(:app_env, :plan, :org_id, :user_id, :paid_only, :exclude_internal, :from, :to, *CodeSunset.configuration.custom_filters.keys)
end

#raw_retained_range ⇒ Object



33
34
35
# File 'lib/code_sunset/analytics_filters.rb', line 33

def raw_retained_range
  raw_retention_start..Time.current.end_of_day
end

#recent_raw_filters ⇒ Object



21
22
23
# File 'lib/code_sunset/analytics_filters.rb', line 21

def recent_raw_filters
  filters.slice(:app_env)
end

#retain_range(range) ⇒ Object



29
30
31
# File 'lib/code_sunset/analytics_filters.rb', line 29

def retain_range(range)
  [range.begin, raw_retention_start].max..range.end
end

#rollup_filters ⇒ Object



25
26
27
# File 'lib/code_sunset/analytics_filters.rb', line 25

def rollup_filters
  filters.slice(:app_env, :from, :to)
end