Sha256: 299a3e1dbdaa8f0b9dbeb6d8280c1573d6450a319f03c3b784cf2511d6f20550
Contents?: true
Size: 1.16 KB
Versions: 1
Compression:
Stored size: 1.16 KB
Contents
module Saulabs module Reportable # A special report class that cumulates all data (see {Saulabs::Reportable::Report}) # # @example Cumulated reports as opposed to regular reports # # [[<DateTime today>, 1], [<DateTime yesterday>, 2], etc.] # [[<DateTime today>, 3], [<DateTime yesterday>, 2], etc.] # class CumulatedReport < Report # Runs the report (see {Saulabs::Reportable::Report#run}) # def run(options = {}) cumulate(super, options_for_run(options)) end private def cumulate(data, options) first_reporting_period = ReportingPeriod.first(options[:grouping], options[:limit], options[:end_date]) acc = initial_cumulative_value(first_reporting_period.date_time, options) result = [] data.each do |element| acc += element[1].to_f result << [element[0], acc] end result end def initial_cumulative_value(date, options) conditions = setup_conditions(nil, date, options[:conditions]) @klass.send(@aggregation, @value_column, :conditions => conditions) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
reportable-1.0.0 | lib/saulabs/reportable/cumulated_report.rb |