Class: ForestLiana::LineStatGetter
- Inherits:
-
StatGetter
- Object
- BaseGetter
- StatGetter
- ForestLiana::LineStatGetter
- Defined in:
- app/services/forest_liana/line_stat_getter.rb
Instance Attribute Summary collapse
-
#record ⇒ Object
Returns the value of attribute record.
Instance Method Summary collapse
Methods inherited from StatGetter
Methods inherited from BaseGetter
#get_collection, #get_resource, #includes_for_serialization
Constructor Details
This class inherits a constructor from ForestLiana::StatGetter
Instance Attribute Details
#record ⇒ Object
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_timezone ⇒ Object
5 6 7 |
# File 'app/services/forest_liana/line_stat_getter.rb', line 5 def client_timezone @params[:timezone] end |
#get_format ⇒ Object
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 |
#perform ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/services/forest_liana/line_stat_getter.rb', line 22 def perform value = get_resource().eager_load(@includes) if @params[:filterType] && @params[:filters] conditions = [] filter_operator = " #{@params[:filterType]} ".upcase @params[:filters].try(:each) do |filter| operator, filter_value = OperatorValueParser.parse(filter[:value]) conditions << OperatorValueParser.get_condition(filter[:field], operator, filter_value, @resource, @params[:timezone]) end value = value.where(conditions.join(filter_operator)) 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 |