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

#initialize

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[:aggregate].blank?
  resource = get_resource().eager_load(@includes)

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

  unless filters.blank?
    filter_parser = FiltersParser.new(filters, resource, @params[:timezone])
    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: count(resource),
    countPrevious: previous_value ? count(previous_value) : nil
  })
end