Sha256: 333d08eadf21defa02b6a462ce4f2905e3e37561f9a76b10b45bc5fb738c9693
Contents?: true
Size: 1.3 KB
Versions: 59
Compression:
Stored size: 1.3 KB
Contents
module ForestLiana class ValueStatGetter < StatGetter attr_accessor :record def perform return if @params[:aggregate].blank? resource = get_resource().eager_load(@includes) unless @params[:filters].blank? filter_parser = FiltersParser.new(@params[: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 private def count(value) uniq = @params[:aggregate].downcase == 'count' if Rails::VERSION::MAJOR >= 4 if uniq # NOTICE: uniq is deprecated since Rails 5.0 value = Rails::VERSION::MAJOR >= 5 ? value.distinct : value.uniq end value.send(@params[:aggregate].downcase, aggregate_field) else value.send(@params[:aggregate].downcase, aggregate_field, distinct: uniq) end end def aggregate_field @params[:aggregate_field] || @resource.primary_key end end end
Version data entries
59 entries across 59 versions & 1 rubygems