Class: ForestLiana::LineStatGetter

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

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/line_stat_getter.rb', line 3

def record
  @record
end

Instance Method Details

#client_timezoneObject



5
6
7
# File 'app/services/forest_liana/line_stat_getter.rb', line 5

def client_timezone
  @params[:timezone]
end

#get_formatObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/services/forest_liana/line_stat_getter.rb', line 9

def get_format
  case @params[:time_range].try(:downcase)
    when 'day'
      '%d/%m/%Y'
    when 'week'
      'W%V-%Y'
    when 'month'
      '%b %Y'
    when 'year'
      '%Y'
  end
end

#performObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/services/forest_liana/line_stat_getter.rb', line 22

def perform
  value = get_resource().eager_load(@includes)

  unless @params[:filters].blank?
    value = FiltersParser.new(@params[:filters], value, @params[:timezone]).apply_filters
  end

  value = value.send(time_range, group_by_date_field, {
    time_zone: client_timezone,
    week_start: :mon
  })

  value = value.send(@params[:aggregate].downcase, @params[:aggregate_field])
    .map do |k, v|
      { label: k.strftime(get_format), values: { value: v }}
    end

  @record = Model::Stat.new(value: value)
end