Class: ForestLiana::ValueStatGetter

Inherits:
StatGetter show all
Defined in:
app/services/forest_liana/value_stat_getter.rb

Direct Known Subclasses

ObjectiveStatGetter

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from StatGetter

#get_resource, #initialize, #validate_params

Methods inherited from BaseGetter

#get_collection, #get_resource, #includes_for_serialization

Constructor Details

This class inherits a constructor from ForestLiana::StatGetter

Instance Attribute Details

#recordObject

Returns the value of attribute record.



3
4
5
# File 'app/services/forest_liana/value_stat_getter.rb', line 3

def record
  @record
end

Instance Method Details

#performObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/forest_liana/value_stat_getter.rb', line 5

def perform
  return if @params[:aggregator].blank?
  resource = optimize_record_loading(@resource, get_resource)

  filters = ForestLiana::ScopeManager.append_scope_for_user(@params[:filter], @user, @resource.name, @params['contextVariables'])

  unless filters.blank?
    filter_parser = FiltersParser.new(filters, resource, @params[:timezone], @params)
    resource = filter_parser.apply_filters
    raw_previous_interval = filter_parser.get_previous_interval_condition

    if raw_previous_interval
      previous_value = filter_parser.apply_filters_on_previous_interval(raw_previous_interval)
    end
  end

  @record = Model::Stat.new(value: {
    countCurrent: aggregate(resource),
    countPrevious: previous_value ? aggregate(previous_value) : nil
  })
end