Sha256: f47c67b0904bbc224170b477ee52eb544a90dce50eabbf89a31c57442e4f26a1

Contents?: true

Size: 1.15 KB

Versions: 42

Compression:

Stored size: 1.15 KB

Contents

module ForestLiana
  class LineStatGetter < StatGetter
    attr_accessor :record

    def client_timezone
      @params[:timezone]
    end

    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

    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

    private

    def group_by_date_field
      "#{@resource.table_name}.#{@params[:group_by_date_field]}"
    end

    def time_range
      "group_by_#{@params[:time_range].try(:downcase) || 'month'}"
    end

  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
forest_liana-6.0.0.pre.beta.4 app/services/forest_liana/line_stat_getter.rb
forest_liana-6.0.0.pre.beta.3 app/services/forest_liana/line_stat_getter.rb
forest_liana-5.4.0 app/services/forest_liana/line_stat_getter.rb
forest_liana-6.0.0.pre.beta.2 app/services/forest_liana/line_stat_getter.rb
forest_liana-6.0.0.pre.beta.1 app/services/forest_liana/line_stat_getter.rb
forest_liana-5.3.3 app/services/forest_liana/line_stat_getter.rb
forest_liana-5.3.2 app/services/forest_liana/line_stat_getter.rb
forest_liana-5.3.1 app/services/forest_liana/line_stat_getter.rb
forest_liana-5.3.0 app/services/forest_liana/line_stat_getter.rb
forest_liana-5.2.3 app/services/forest_liana/line_stat_getter.rb
forest_liana-5.2.2 app/services/forest_liana/line_stat_getter.rb
forest_liana-5.2.1 app/services/forest_liana/line_stat_getter.rb
forest_liana-5.2.0 app/services/forest_liana/line_stat_getter.rb
forest_liana-5.1.3 app/services/forest_liana/line_stat_getter.rb
forest_liana-5.1.2 app/services/forest_liana/line_stat_getter.rb
forest_liana-5.1.1 app/services/forest_liana/line_stat_getter.rb
forest_liana-5.1.0 app/services/forest_liana/line_stat_getter.rb
forest_liana-5.0.0 app/services/forest_liana/line_stat_getter.rb
forest_liana-5.0.0.pre.beta.0 app/services/forest_liana/line_stat_getter.rb
forest_liana-4.2.0 app/services/forest_liana/line_stat_getter.rb