| changed namespacing to better reflect authorship - reportable - Fork of reporta… | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit a48dd3186dd2cf21e90f5b2056eca0ab9570991e | |
| parent 9d1f09ef263b73516cb4668d0936eb8fcac694f5 | |
| Author: Marco Otte-Witte <[email protected]> | |
| Date: Wed, 15 Apr 2009 17:55:25 +0200 | |
| changed namespacing to better reflect authorship | |
| Diffstat: | |
| M README.rdoc | 16 +++++++++++----- | |
| M init.rb | 6 +++--- | |
| D lib/kvlr/reports_as_sparkline.rb | 57 -----------------------------… | |
| D lib/kvlr/reports_as_sparkline/cumu… | 45 ---------------------------… | |
| D lib/kvlr/reports_as_sparkline/grou… | 119 ---------------------------… | |
| D lib/kvlr/reports_as_sparkline/repo… | 131 ---------------------------… | |
| D lib/kvlr/reports_as_sparkline/repo… | 122 ---------------------------… | |
| D lib/kvlr/reports_as_sparkline/repo… | 90 ---------------------------… | |
| D lib/kvlr/reports_as_sparkline/spar… | 39 ---------------------------… | |
| A lib/simplabs/reports_as_sparkline.… | 58 +++++++++++++++++++++++++++… | |
| A lib/simplabs/reports_as_sparkline/… | 45 +++++++++++++++++++++++++++… | |
| A lib/simplabs/reports_as_sparkline/… | 119 +++++++++++++++++++++++++++… | |
| A lib/simplabs/reports_as_sparkline/… | 129 +++++++++++++++++++++++++++… | |
| A lib/simplabs/reports_as_sparkline/… | 116 +++++++++++++++++++++++++++… | |
| A lib/simplabs/reports_as_sparkline/… | 94 +++++++++++++++++++++++++++… | |
| A lib/simplabs/reports_as_sparkline/… | 39 +++++++++++++++++++++++++++… | |
| M rdoc/classes/Kvlr/ReportsAsSparkli… | 16 ++++++++-------- | |
| M rdoc/classes/Kvlr/ReportsAsSparkli… | 18 +++++++++--------- | |
| M rdoc/classes/Kvlr/ReportsAsSparkli… | 12 ++++++------ | |
| M rdoc/classes/Kvlr/ReportsAsSparkli… | 16 ++++++++-------- | |
| M rdoc/classes/Kvlr/ReportsAsSparkli… | 20 ++++++++++---------- | |
| M rdoc/classes/Kvlr/ReportsAsSparkli… | 10 +++++----- | |
| M rdoc/files/README_rdoc.html | 2 +- | |
| M rdoc/files/lib/kvlr/reports_as_spa… | 2 +- | |
| M rdoc/files/lib/kvlr/reports_as_spa… | 2 +- | |
| M rdoc/files/lib/kvlr/reports_as_spa… | 2 +- | |
| M rdoc/files/lib/kvlr/reports_as_spa… | 2 +- | |
| M rdoc/files/lib/kvlr/reports_as_spa… | 2 +- | |
| M rdoc/files/lib/kvlr/reports_as_spa… | 2 +- | |
| M rdoc/files/lib/kvlr/reports_as_spa… | 2 +- | |
| M rdoc/fr_class_index.html | 12 ++++++------ | |
| M rdoc/fr_file_index.html | 14 +++++++------- | |
| M rdoc/fr_method_index.html | 22 +++++++++++----------- | |
| M spec/classes/cumulated_report_spec… | 38 ++++++++++++++++-----------… | |
| M spec/classes/grouping_spec.rb | 38 ++++++++++++++++-------------… | |
| M spec/classes/report_cache_spec.rb | 128 ++++++++++++++++-------------… | |
| M spec/classes/report_spec.rb | 66 ++++++++++++++++-------------… | |
| M spec/classes/reporting_period_spec… | 78 ++++++++++++++-------------… | |
| M spec/other/report_method_spec.rb | 4 ++-- | |
| M spec/other/sparkline_tag_helper_sp… | 4 ++-- | |
| 40 files changed, 867 insertions(+), 870 deletions(-) | |
| --- | |
| diff --git a/README.rdoc b/README.rdoc | |
| @@ -15,7 +15,7 @@ to it with the following options: | |
| * :conditions - Conditions like in ActiveRecord::Base#find; only records that … | |
| * :cumulate - Sets whether to cumulate the numbers (instead of [1, 2, 3] retur… | |
| * :live_data - Specified whether data for the current reporting period is read… | |
| -* :end_date - When specified, the report will be for the periods before this d… | |
| +* :end_date - When specified, the report will only include data for the period… | |
| <b>Example:</b> | |
| @@ -66,11 +66,11 @@ Installation requires 3 simple steps: | |
| From your RAILS_ROOT in Rails >= 2.1, do | |
| - ./script/plugin install git://github.com/myronmarston/reports_as_sparkline.g… | |
| + ./script/plugin install git://github.com/marcoow/reports_as_sparkline.git | |
| If you are on Rails < 2.1, do this from your RAILS_ROOT | |
| - git clone git://github.com/myronmarston/reports_as_sparkline.git vendor/plug… | |
| + git clone git://github.com/marcoow/reports_as_sparkline.git vendor/plugins/r… | |
| <b>generate migration</b> | |
| @@ -83,7 +83,7 @@ If you are on Rails < 2.1, do this from your RAILS_ROOT | |
| == Performance | |
| To achieve best performance, you should add indices to your tables on the date… | |
| -used for grouping the records (see Kvlr::ReportsAsSparkline::ClassMethods.repo… | |
| +used for grouping the records (see Simplabs::ReportsAsSparkline::ClassMethods.… | |
| add_index :[table], :[date_column] | |
| @@ -103,4 +103,10 @@ If you are on PostgreSQL, you should add functional indice… | |
| If you want ot suggest any new features or report bugs, do so at http://simpla… | |
| -© 2008-2009 Martin Kavalar, Marco Otte-Witte (http://simplabs.com/#projects),… | |
| +== Contributors | |
| + | |
| +* myronmarston (http://github.com/myronmarston) | |
| + | |
| +== Author | |
| + | |
| +© 2008-2009 Marco Otte-Witte (http://simplabs.com/#projects), Martin Kavalar,… | |
| diff --git a/init.rb b/init.rb | |
| @@ -1,9 +1,9 @@ | |
| -require 'kvlr/reports_as_sparkline' | |
| +require 'simplabs/reports_as_sparkline' | |
| ActiveRecord::Base.class_eval do | |
| - include Kvlr::ReportsAsSparkline | |
| + include Simplabs::ReportsAsSparkline | |
| end | |
| ActionView::Base.class_eval do | |
| - include Kvlr::ReportsAsSparkline::SparklineTagHelper | |
| + include Simplabs::ReportsAsSparkline::SparklineTagHelper | |
| end | |
| diff --git a/lib/kvlr/reports_as_sparkline.rb b/lib/kvlr/reports_as_sparkline.rb | |
| @@ -1,57 +0,0 @@ | |
| -module Kvlr #:nodoc: | |
| - | |
| - module ReportsAsSparkline | |
| - | |
| - def self.included(base) #:nodoc: | |
| - base.extend ClassMethods | |
| - end | |
| - | |
| - module ClassMethods | |
| - | |
| - # Generates a report on a model. That report can then be executed via th… | |
| - # | |
| - # ==== Parameters | |
| - # | |
| - # * <tt>name</tt> - The name of the report, defines the name of the gene… | |
| - # | |
| - # ==== Options | |
| - # | |
| - # * <tt>:date_column</tt> - The name of the date column on that the reco… | |
| - # * <tt>:value_column</tt> - The name of the column that holds the value… | |
| - # * <tt>:aggregation</tt> - The aggregation to use (one of :count, :sum,… | |
| - # * <tt>:grouping</tt> - The period records are grouped on (:hour, :day,… | |
| - # * <tt>:limit</tt> - The number of periods to get (see :grouping) | |
| - # * <tt>:conditions</tt> - Conditions like in ActiveRecord::Base#find; o… | |
| - # * <tt>:live_data</tt> - Specified whether data for the current reporti… | |
| - # | |
| - # ==== Examples | |
| - # | |
| - # class Game < ActiveRecord::Base | |
| - # reports_as_sparkline :games_per_day | |
| - # reports_as_sparkline :games_played_total, :cumulate => true | |
| - # end | |
| - # class User < ActiveRecord::Base | |
| - # reports_as_sparkline :registrations, :aggregation => :count | |
| - # reports_as_sparkline :activations, :aggregation => :count, :date_… | |
| - # reports_as_sparkline :total_users, :cumulate => true | |
| - # reports_as_sparkline :rake, :aggregation => :sum, :value… | |
| - # end | |
| - def reports_as_sparkline(name, options = {}) | |
| - (class << self; self; end).instance_eval do | |
| - define_method "#{name.to_s}_report".to_sym do |*args| | |
| - if options.delete(:cumulate) | |
| - report = Kvlr::ReportsAsSparkline::CumulatedReport.new(self, nam… | |
| - else | |
| - report = Kvlr::ReportsAsSparkline::Report.new(self, name, option… | |
| - end | |
| - raise ArgumentError.new unless args.length == 0 || (args.length ==… | |
| - report.run(args.length == 0 ? {} : args[0]) | |
| - end | |
| - end | |
| - end | |
| - | |
| - end | |
| - | |
| - end | |
| - | |
| -end | |
| diff --git a/lib/kvlr/reports_as_sparkline/cumulated_report.rb b/lib/kvlr/repor… | |
| @@ -1,45 +0,0 @@ | |
| -module Kvlr #:nodoc: | |
| - | |
| - module ReportsAsSparkline #:nodoc: | |
| - | |
| - # A special report class that cumulates all data (see Kvlr::ReportsAsSpark… | |
| - # | |
| - # ==== Examples | |
| - # | |
| - # When Kvlr::ReportsAsSparkline::Report returns | |
| - # | |
| - # [[<DateTime today>, 1], [<DateTime yesterday>, 2], etc.] | |
| - # | |
| - # Kvlr::ReportsAsSparkline::CumulatedReport returns | |
| - # | |
| - # [[<DateTime today>, 3], [<DateTime yesterday>, 2], etc.] | |
| - class CumulatedReport < Report | |
| - | |
| - # Runs the report (see Kvlr::ReportsAsSparkline::Report#run) | |
| - def run(options = {}) | |
| - cumulate(super, options_for_run(options)) | |
| - end | |
| - | |
| - protected | |
| - | |
| - def cumulate(data, options) #:nodoc: | |
| - first_reporting_period = ReportingPeriod.first(options[:grouping], o… | |
| - acc = initial_cumulative_value(first_reporting_period.date_time, opt… | |
| - 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 | |
| diff --git a/lib/kvlr/reports_as_sparkline/grouping.rb b/lib/kvlr/reports_as_sp… | |
| @@ -1,119 +0,0 @@ | |
| -module Kvlr #:nodoc: | |
| - | |
| - module ReportsAsSparkline #:nodoc: | |
| - | |
| - # This is the grouping a report uses to group records in the database | |
| - class Grouping | |
| - | |
| - # ==== Parameters | |
| - # * <tt>identifier</tt> - The identifier of the grouping - one of :hour,… | |
| - def initialize(identifier) | |
| - raise ArgumentError.new("Invalid grouping #{identifier}") unless [:hou… | |
| - @identifier = identifier | |
| - end | |
| - | |
| - # Returns the Grouping's identifier | |
| - def identifier | |
| - @identifier | |
| - end | |
| - | |
| - def date_parts_from_db_string(db_string) #:nodoc: | |
| - return case ActiveRecord::Base.connection.adapter_name | |
| - when /mysql/i | |
| - from_mysql_db_string(db_string) | |
| - when /sqlite/i | |
| - from_sqlite_db_string(db_string) | |
| - when /postgres/i | |
| - from_postgresql_db_string(db_string) | |
| - end | |
| - end | |
| - | |
| - def to_sql(date_column) #:nodoc: | |
| - return case ActiveRecord::Base.connection.adapter_name | |
| - when /mysql/i | |
| - mysql_format(date_column) | |
| - when /sqlite/i | |
| - sqlite_format(date_column) | |
| - when /postgres/i | |
| - postgresql_format(date_column) | |
| - end | |
| - end | |
| - | |
| - private | |
| - | |
| - def from_mysql_db_string(db_string) | |
| - if @identifier == :week | |
| - parts = [db_string[0..3], db_string[4..5]].map(&:to_i) | |
| - else | |
| - db_string.split('/').map(&:to_i) | |
| - end | |
| - end | |
| - | |
| - def from_sqlite_db_string(db_string) | |
| - if @identifier == :week | |
| - parts = db_string.split('-').map(&:to_i) | |
| - date = Date.new(parts[0], parts[1], parts[2]) | |
| - return [date.cwyear, date.cweek] | |
| - end | |
| - db_string.split('/').map(&:to_i) | |
| - end | |
| - | |
| - def from_postgresql_db_string(db_string) | |
| - case @identifier | |
| - when :hour | |
| - return (db_string[0..9].split('-') + [db_string[11..12]]).map(&:… | |
| - when :day | |
| - return db_string[0..9].split('-').map(&:to_i) | |
| - when :week | |
| - parts = db_string[0..9].split('-').map(&:to_i) | |
| - date = Date.new(parts[0], parts[1], parts[2]) | |
| - return [date.cwyear, date.cweek] | |
| - when :month | |
| - return db_string[0..6].split('-')[0..1].map(&:to_i) | |
| - end | |
| - end | |
| - | |
| - def mysql_format(date_column) | |
| - return case @identifier | |
| - when :hour | |
| - "DATE_FORMAT(#{date_column}, '%Y/%m/%d/%H')" | |
| - when :day | |
| - "DATE_FORMAT(#{date_column}, '%Y/%m/%d')" | |
| - when :week | |
| - "YEARWEEK(#{date_column}, 3)" | |
| - when :month | |
| - "DATE_FORMAT(#{date_column}, '%Y/%m')" | |
| - end | |
| - end | |
| - | |
| - def sqlite_format(date_column) | |
| - return case @identifier | |
| - when :hour | |
| - "strftime('%Y/%m/%d/%H', #{date_column})" | |
| - when :day | |
| - "strftime('%Y/%m/%d', #{date_column})" | |
| - when :week | |
| - "date(#{date_column}, 'weekday 0')" | |
| - when :month | |
| - "strftime('%Y/%m', #{date_column})" | |
| - end | |
| - end | |
| - | |
| - def postgresql_format(date_column) | |
| - return case @identifier | |
| - when :hour | |
| - "date_trunc('hour', #{date_column})" | |
| - when :day | |
| - "date_trunc('day', #{date_column})" | |
| - when :week | |
| - "date_trunc('week', #{date_column})" | |
| - when :month | |
| - "date_trunc('month', #{date_column})" | |
| - end | |
| - end | |
| - | |
| - end | |
| - | |
| - end | |
| - | |
| -end | |
| diff --git a/lib/kvlr/reports_as_sparkline/report.rb b/lib/kvlr/reports_as_spar… | |
| @@ -1,131 +0,0 @@ | |
| -module Kvlr #:nodoc: | |
| - | |
| - module ReportsAsSparkline #:nodoc: | |
| - | |
| - # The Report class that does all the data retrieval and calculations | |
| - class Report | |
| - | |
| - attr_reader :klass, :name, :date_column, :value_column, :aggregation, :o… | |
| - | |
| - # ==== Parameters | |
| - # * <tt>klass</tt> - The model the report works on (This is the class yo… | |
| - # * <tt>name</tt> - The name of the report (as in Kvlr::ReportsAsSparkli… | |
| - # | |
| - # ==== Options | |
| - # | |
| - # * <tt>:date_column</tt> - The name of the date column on that the reco… | |
| - # * <tt>:value_column</tt> - The name of the column that holds the value… | |
| - # * <tt>:aggregation</tt> - The aggregation to use (one of :count, :sum,… | |
| - # * <tt>:grouping</tt> - The period records are grouped on (:hour, :day,… | |
| - # * <tt>:limit</tt> - The number of periods to get (see :grouping) | |
| - # * <tt>:conditions</tt> - Conditions like in ActiveRecord::Base#find; o… | |
| - # * <tt>:live_data</tt> - Specified whether data for the current reporti… | |
| - # * <tt>:end_date</tt> - When specified, the report will be for the peri… | |
| - def initialize(klass, name, options = {}) | |
| - ensure_valid_options(options) | |
| - @klass = klass | |
| - @name = name | |
| - @date_column = (options[:date_column] || 'created_at').to_s | |
| - @aggregation = options[:aggregation] || :count | |
| - @value_column = (options[:value_column] || (@aggregation == :count ? '… | |
| - @options = { | |
| - :limit => options[:limit] || 100, | |
| - :conditions => options[:conditions] || [], | |
| - :grouping => Grouping.new(options[:grouping] || :day), | |
| - :live_data => options[:live_data] || false, | |
| - :end_date => options[:end_date] | |
| - } | |
| - @options.merge!(options) | |
| - @options.freeze | |
| - end | |
| - | |
| - # Runs the report and returns an array of array of DateTimes and Floats | |
| - # | |
| - # ==== Options | |
| - # * <tt>:limit</tt> - The number of periods to get | |
| - # * <tt>:conditions</tt> - Conditions like in ActiveRecord::Base#find; o… | |
| - # * <tt>:grouping</tt> - The period records are grouped on (:hour, :day,… | |
| - # * <tt>:live_data</tt> - Specified whether data for the current reporti… | |
| - # * <tt>:end_date</tt> - When specified, the report will be for the peri… | |
| - def run(options = {}) | |
| - custom_conditions = options.key?(:conditions) | |
| - options = options_for_run(options) | |
| - ReportCache.process(self, options, !custom_conditions) do |begin_at, e… | |
| - read_data(begin_at, end_at, options) | |
| - end | |
| - end | |
| - | |
| - private | |
| - | |
| - def options_for_run(options = {}) | |
| - options = options.dup | |
| - ensure_valid_options(options, :run) | |
| - options.reverse_merge!(@options) | |
| - options[:grouping] = Grouping.new(options[:grouping]) unless options… | |
| - return options | |
| - end | |
| - | |
| - def read_data(begin_at, end_at, options) | |
| - conditions = setup_conditions(begin_at, end_at, options[:conditions]) | |
| - @klass.send(@aggregation, | |
| - @value_column, | |
| - :conditions => conditions, | |
| - :group => options[:grouping].to_sql(@date_column), | |
| - :order => "#{options[:grouping].to_sql(@date_column)} ASC" | |
| - ) | |
| - end | |
| - | |
| - def setup_conditions(begin_at, end_at, custom_conditions = []) | |
| - conditions = [''] | |
| - if custom_conditions.is_a?(Hash) | |
| - conditions = [custom_conditions.map do |k, v| | |
| - if v.nil? | |
| - "#{k.to_s} IS NULL" | |
| - elsif v.is_a?(Array) || v.is_a?(Range) | |
| - "#{k.to_s} IN (?)" | |
| - else | |
| - "#{k.to_s} = ?" | |
| - end | |
| - end.join(' AND '), *custom_conditions.map { |k, v| v }.compact] | |
| - elsif custom_conditions.size > 0 | |
| - conditions = [(custom_conditions[0] || ''), *custom_conditions[1..… | |
| - end | |
| - conditions[0] += "#{(conditions[0].blank? ? '' : ' AND ') + @date_co… | |
| - | |
| - conditions[0] += if begin_at && end_at | |
| - 'BETWEEN ? AND ?' | |
| - elsif begin_at | |
| - '>= ?' | |
| - elsif end_at | |
| - '<= ?' | |
| - else | |
| - raise ArgumentError.new('You must pass either begin_at, end_at or … | |
| - end | |
| - | |
| - conditions << begin_at if begin_at | |
| - conditions << end_at if end_at | |
| - conditions | |
| - end | |
| - | |
| - def ensure_valid_options(options, context = :initialize) | |
| - case context | |
| - when :initialize | |
| - options.each_key do |k| | |
| - raise ArgumentError.new("Invalid option #{k}") unless [:limit,… | |
| - end | |
| - raise ArgumentError.new("Invalid aggregation #{options[:aggregat… | |
| - raise ArgumentError.new('The name of the column holding the valu… | |
| - when :run | |
| - options.each_key do |k| | |
| - raise ArgumentError.new("Invalid option #{k}") unless [:limit,… | |
| - end | |
| - end | |
| - raise ArgumentError.new("Invalid grouping #{options[:grouping]}") if… | |
| - raise ArgumentError.new("Invalid conditions: #{options[:conditions].… | |
| - end | |
| - | |
| - end | |
| - | |
| - end | |
| - | |
| -end | |
| diff --git a/lib/kvlr/reports_as_sparkline/report_cache.rb b/lib/kvlr/reports_a… | |
| @@ -1,122 +0,0 @@ | |
| -module Kvlr #:nodoc: | |
| - | |
| - module ReportsAsSparkline #:nodoc: | |
| - | |
| - class ReportCache < ActiveRecord::Base #:nodoc: | |
| - | |
| - def self.process(report, options, cache = true, &block) | |
| - raise ArgumentError.new('A block must be given') unless block_given? | |
| - self.transaction do | |
| - cached_data = [] | |
| - first_reporting_period = ReportingPeriod.first(options[:grouping], o… | |
| - last_reporting_period = options[:end_date] ? ReportingPeriod.new(opt… | |
| - | |
| - if cache | |
| - cached_data = find_cached_data(report, options, first_reporting_pe… | |
| - first_cached_reporting_period = cached_data.empty? ? nil : Reporti… | |
| - last_cached_reporting_period = cached_data.empty? ? nil : Reportin… | |
| - end | |
| - | |
| - # Get any missing data that comes after our cached data... | |
| - new_after_cache_data = if !options[:live_data] && last_cached_report… | |
| - [] | |
| - else | |
| - end_date = options[:live_data] ? nil : last_reporting_period && la… | |
| - yield((last_cached_reporting_period.next rescue first_reporting_pe… | |
| - end | |
| - | |
| - # Get any mising data that comes before our cached data.... | |
| - new_before_cache_data = if cached_data.empty? || # after_cache_data … | |
| - first_cached_reporting_period.date_time == first_reporting_period.… | |
| - [] | |
| - else | |
| - yield(first_reporting_period.date_time, first_cached_reporting_per… | |
| - end | |
| - | |
| - prepare_result(new_before_cache_data, new_after_cache_data, cached_d… | |
| - end | |
| - end | |
| - | |
| - private | |
| - | |
| - def self.prepare_result(new_before_cache_data, new_after_cache_data, c… | |
| - cache_map_proc = lambda { |data| [ReportingPeriod.from_db_string(opt… | |
| - | |
| - new_after_cache_data = new_after_cache_data.map &cache_map_proc | |
| - new_before_cache_data = new_before_cache_data.map &cache_map_proc | |
| - result = cached_data.map { |cached| [cached.reporting_period, cached… | |
| - | |
| - first_reporting_period = ReportingPeriod.first(options[:grouping], o… | |
| - last_reporting_period = ReportingPeriod.new(options[:grouping], opti… | |
| - first_cached_reporting_period = cached_data.empty? ? nil : Reporting… | |
| - last_cached_reporting_period = cached_data.empty? ? nil : ReportingP… | |
| - | |
| - if first_cached_reporting_period | |
| - reporting_period = first_reporting_period | |
| - while reporting_period < first_cached_reporting_period | |
| - cached = build_cached_data(report, options[:grouping], reporting… | |
| - cached.save! if cache | |
| - result.insert(0, [reporting_period.date_time, cached.value]) | |
| - reporting_period = reporting_period.next | |
| - end | |
| - end | |
| - | |
| - reporting_period = cached_data.empty? ? first_reporting_period : las… | |
| - | |
| - while reporting_period < last_reporting_period | |
| - cached = build_cached_data(report, options[:grouping], reporting_p… | |
| - cached.save! if cache | |
| - result << [reporting_period.date_time, cached.value] | |
| - reporting_period = reporting_period.next | |
| - end | |
| - | |
| - if options[:live_data] | |
| - result << [last_reporting_period.date_time, find_value(new_after_c… | |
| - end | |
| - result | |
| - end | |
| - | |
| - def self.find_value(data, reporting_period) | |
| - data = data.detect { |d| d[0] == reporting_period } | |
| - data ? data[1] : 0.0 | |
| - end | |
| - | |
| - def self.build_cached_data(report, grouping, reporting_period, value) | |
| - self.new( | |
| - :model_name => report.klass.to_s, | |
| - :report_name => report.name.to_s, | |
| - :grouping => grouping.identifier.to_s, | |
| - :aggregation => report.aggregation.to_s, | |
| - :reporting_period => reporting_period.date_time, | |
| - :value => value | |
| - ) | |
| - end | |
| - | |
| - def self.find_cached_data(report, options, first_reporting_period, las… | |
| - conditions = [ | |
| - 'model_name = ? AND report_name = ? AND grouping = ? AND aggregati… | |
| - report.klass.to_s, | |
| - report.name.to_s, | |
| - options[:grouping].identifier.to_s, | |
| - report.aggregation.to_s, | |
| - first_reporting_period.date_time | |
| - ] | |
| - | |
| - if last_reporting_period | |
| - conditions.first.sub!(/>= \?\z/, 'BETWEEN ? AND ?') | |
| - conditions << last_reporting_period.date_time | |
| - end | |
| - | |
| - self.find( | |
| - :all, | |
| - :conditions => conditions, | |
| - :limit => options[:limit], | |
| - :order => 'reporting_period ASC' | |
| - ) | |
| - end | |
| - | |
| - end | |
| - | |
| - end | |
| - | |
| -end | |
| diff --git a/lib/kvlr/reports_as_sparkline/reporting_period.rb b/lib/kvlr/repor… | |
| @@ -1,90 +0,0 @@ | |
| -module Kvlr #:nodoc: | |
| - | |
| - module ReportsAsSparkline #:nodoc: | |
| - | |
| - # A ReportingPeriod is - depending on the Grouping - either a specific ho… | |
| - class ReportingPeriod | |
| - | |
| - attr_reader :date_time, :grouping | |
| - | |
| - # ==== Parameters | |
| - # * <tt>grouping</tt> - The Kvlr::ReportsAsSparkline::Grouping of the re… | |
| - # * <tt>date_time</tt> - The DateTime that reporting period is created f… | |
| - def initialize(grouping, date_time = nil) | |
| - @grouping = grouping | |
| - @date_time = parse_date_time(date_time || DateTime.now) | |
| - end | |
| - | |
| - # Returns the first reporting period for a grouping and a limit; e.g. th… | |
| - # | |
| - # ==== Parameters | |
| - # * <tt>grouping</tt> - The Kvlr::ReportsAsSparkline::Grouping of the re… | |
| - # * <tt>limit</tt> - The number of reporting periods until the first one | |
| - def self.first(grouping, limit, end_date = nil) | |
| - self.new(grouping, end_date).offset(-limit) | |
| - end | |
| - | |
| - def self.from_db_string(grouping, db_string) #:nodoc: | |
| - parts = grouping.date_parts_from_db_string(db_string) | |
| - result = case grouping.identifier | |
| - when :hour | |
| - self.new(grouping, DateTime.new(parts[0], parts[1], parts[2], part… | |
| - when :day | |
| - self.new(grouping, Date.new(parts[0], parts[1], parts[2])) | |
| - when :week | |
| - self.new(grouping, Date.commercial(parts[0], parts[1], 1)) | |
| - when :month | |
| - self.new(grouping, Date.new(parts[0], parts[1], 1)) | |
| - end | |
| - result | |
| - end | |
| - | |
| - # Returns the next reporting period (that is next hour/day/month/year) | |
| - def next | |
| - self.offset(1) | |
| - end | |
| - | |
| - # Returns the previous reporting period (that is next hour/day/month/yea… | |
| - def previous | |
| - self.offset(-1) | |
| - end | |
| - | |
| - def offset(val) | |
| - self.class.new(@grouping, @date_time + val.send(@grouping.identifier)) | |
| - end | |
| - | |
| - def ==(other) #:nodoc: | |
| - if other.class == Kvlr::ReportsAsSparkline::ReportingPeriod | |
| - return @date_time.to_s == other.date_time.to_s && @grouping.identifi… | |
| - end | |
| - false | |
| - end | |
| - | |
| - def <(other) #:nodoc: | |
| - if other.class == Kvlr::ReportsAsSparkline::ReportingPeriod | |
| - return @date_time < other.date_time | |
| - end | |
| - raise ArgumentError.new("Can only compare instances of #{Kvlr::Reports… | |
| - end | |
| - | |
| - private | |
| - | |
| - def parse_date_time(date_time) | |
| - return case @grouping.identifier | |
| - when :hour | |
| - DateTime.new(date_time.year, date_time.month, date_time.day, dat… | |
| - when :day | |
| - date_time.to_date | |
| - when :week | |
| - date_time = (date_time - date_time.wday.days) + 1.day | |
| - Date.new(date_time.year, date_time.month, date_time.day) | |
| - when :month | |
| - Date.new(date_time.year, date_time.month, 1) | |
| - end | |
| - end | |
| - | |
| - end | |
| - | |
| - end | |
| - | |
| -end | |
| diff --git a/lib/kvlr/reports_as_sparkline/sparkline_tag_helper.rb b/lib/kvlr/r… | |
| @@ -1,39 +0,0 @@ | |
| -module Kvlr #:nodoc: | |
| - | |
| - module ReportsAsSparkline #:nodoc: | |
| - | |
| - module SparklineTagHelper | |
| - | |
| - # Renders a sparkline with the given data. | |
| - # | |
| - # ==== Parameters | |
| - # | |
| - # * <tt>data</tt> - The data to render the sparkline for | |
| - # | |
| - # ==== Options | |
| - # | |
| - # * <tt>width</tt> - The width of the generated image | |
| - # * <tt>height</tt> - The height of the generated image | |
| - # * <tt>line_color</tt> - The line color of the sparkline (hex code) | |
| - # * <tt>fill_color</tt> - The color to fill the area below the sparkline… | |
| - # * <tt>labels</tt> - The axes to render lables for (Array of :x, :y, :r… | |
| - # | |
| - # ==== Example | |
| - # <%= sparkline_tag(User.registrations_report, :width => 200, :height =>… | |
| - def sparkline_tag(data, options = {}) | |
| - options.reverse_merge!({ :width => 300, :height => 34, :line_color => … | |
| - data = data.collect { |d| d[1] } | |
| - labels = "" | |
| - unless options[:labels].empty? | |
| - labels = "&chxt=#{options[:labels].map(&:to_s).join(',')}&chxr=0,0,#… | |
| - end | |
| - image_tag( | |
| - "http://chart.apis.google.com/chart?cht=ls&chs=#{options[:width]}x#{… | |
| - ) | |
| - end | |
| - | |
| - end | |
| - | |
| - end | |
| - | |
| -end | |
| diff --git a/lib/simplabs/reports_as_sparkline.rb b/lib/simplabs/reports_as_spa… | |
| @@ -0,0 +1,58 @@ | |
| +module Simplabs #:nodoc: | |
| + | |
| + module ReportsAsSparkline | |
| + | |
| + def self.included(base) #:nodoc: | |
| + base.extend ClassMethods | |
| + end | |
| + | |
| + module ClassMethods | |
| + | |
| + # Generates a report on a model. That report can then be executed via th… | |
| + # | |
| + # ==== Parameters | |
| + # | |
| + # * <tt>name</tt> - The name of the report, defines the name of the gene… | |
| + # | |
| + # ==== Options | |
| + # | |
| + # * <tt>:date_column</tt> - The name of the date column on that the reco… | |
| + # * <tt>:value_column</tt> - The name of the column that holds the value… | |
| + # * <tt>:aggregation</tt> - The aggregation to use (one of :count, :sum,… | |
| + # * <tt>:grouping</tt> - The period records are grouped on (:hour, :day,… | |
| + # * <tt>:limit</tt> - The number of periods to get (see :grouping) | |
| + # * <tt>:conditions</tt> - Conditions like in ActiveRecord::Base#find; o… | |
| + # * <tt>:live_data</tt> - Specified whether data for the current reporti… | |
| + # * <tt>:end_date</tt> - When specified, the report will only include da… | |
| + # | |
| + # ==== Examples | |
| + # | |
| + # class Game < ActiveRecord::Base | |
| + # reports_as_sparkline :games_per_day | |
| + # reports_as_sparkline :games_played_total, :cumulate => true | |
| + # end | |
| + # class User < ActiveRecord::Base | |
| + # reports_as_sparkline :registrations, :aggregation => :count | |
| + # reports_as_sparkline :activations, :aggregation => :count, :date_… | |
| + # reports_as_sparkline :total_users, :cumulate => true | |
| + # reports_as_sparkline :rake, :aggregation => :sum, :value… | |
| + # end | |
| + def reports_as_sparkline(name, options = {}) | |
| + (class << self; self; end).instance_eval do | |
| + define_method "#{name.to_s}_report".to_sym do |*args| | |
| + if options.delete(:cumulate) | |
| + report = Simplabs::ReportsAsSparkline::CumulatedReport.new(self,… | |
| + else | |
| + report = Simplabs::ReportsAsSparkline::Report.new(self, name, op… | |
| + end | |
| + raise ArgumentError.new unless args.length == 0 || (args.length ==… | |
| + report.run(args.length == 0 ? {} : args[0]) | |
| + end | |
| + end | |
| + end | |
| + | |
| + end | |
| + | |
| + end | |
| + | |
| +end | |
| diff --git a/lib/simplabs/reports_as_sparkline/cumulated_report.rb b/lib/simpla… | |
| @@ -0,0 +1,45 @@ | |
| +module Simplabs #:nodoc: | |
| + | |
| + module ReportsAsSparkline #:nodoc: | |
| + | |
| + # A special report class that cumulates all data (see Simplabs::ReportsAsS… | |
| + # | |
| + # ==== Examples | |
| + # | |
| + # When Simplabs::ReportsAsSparkline::Report returns | |
| + # | |
| + # [[<DateTime today>, 1], [<DateTime yesterday>, 2], etc.] | |
| + # | |
| + # Simplabs::ReportsAsSparkline::CumulatedReport returns | |
| + # | |
| + # [[<DateTime today>, 3], [<DateTime yesterday>, 2], etc.] | |
| + class CumulatedReport < Report | |
| + | |
| + # Runs the report (see Simplabs::ReportsAsSparkline::Report#run) | |
| + def run(options = {}) | |
| + cumulate(super, options_for_run(options)) | |
| + end | |
| + | |
| + protected | |
| + | |
| + def cumulate(data, options) #:nodoc: | |
| + first_reporting_period = ReportingPeriod.first(options[:grouping], o… | |
| + acc = initial_cumulative_value(first_reporting_period.date_time, opt… | |
| + 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 | |
| diff --git a/lib/simplabs/reports_as_sparkline/grouping.rb b/lib/simplabs/repor… | |
| @@ -0,0 +1,119 @@ | |
| +module Simplabs #:nodoc: | |
| + | |
| + module ReportsAsSparkline #:nodoc: | |
| + | |
| + # This is the grouping a report uses to group records in the database | |
| + class Grouping | |
| + | |
| + # ==== Parameters | |
| + # * <tt>identifier</tt> - The identifier of the grouping - one of :hour,… | |
| + def initialize(identifier) | |
| + raise ArgumentError.new("Invalid grouping #{identifier}") unless [:hou… | |
| + @identifier = identifier | |
| + end | |
| + | |
| + # Returns the Grouping's identifier | |
| + def identifier | |
| + @identifier | |
| + end | |
| + | |
| + def date_parts_from_db_string(db_string) #:nodoc: | |
| + return case ActiveRecord::Base.connection.adapter_name | |
| + when /mysql/i | |
| + from_mysql_db_string(db_string) | |
| + when /sqlite/i | |
| + from_sqlite_db_string(db_string) | |
| + when /postgres/i | |
| + from_postgresql_db_string(db_string) | |
| + end | |
| + end | |
| + | |
| + def to_sql(date_column) #:nodoc: | |
| + return case ActiveRecord::Base.connection.adapter_name | |
| + when /mysql/i | |
| + mysql_format(date_column) | |
| + when /sqlite/i | |
| + sqlite_format(date_column) | |
| + when /postgres/i | |
| + postgresql_format(date_column) | |
| + end | |
| + end | |
| + | |
| + private | |
| + | |
| + def from_mysql_db_string(db_string) | |
| + if @identifier == :week | |
| + parts = [db_string[0..3], db_string[4..5]].map(&:to_i) | |
| + else | |
| + db_string.split('/').map(&:to_i) | |
| + end | |
| + end | |
| + | |
| + def from_sqlite_db_string(db_string) | |
| + if @identifier == :week | |
| + parts = db_string.split('-').map(&:to_i) | |
| + date = Date.new(parts[0], parts[1], parts[2]) | |
| + return [date.cwyear, date.cweek] | |
| + end | |
| + db_string.split('/').map(&:to_i) | |
| + end | |
| + | |
| + def from_postgresql_db_string(db_string) | |
| + case @identifier | |
| + when :hour | |
| + return (db_string[0..9].split('-') + [db_string[11..12]]).map(&:… | |
| + when :day | |
| + return db_string[0..9].split('-').map(&:to_i) | |
| + when :week | |
| + parts = db_string[0..9].split('-').map(&:to_i) | |
| + date = Date.new(parts[0], parts[1], parts[2]) | |
| + return [date.cwyear, date.cweek] | |
| + when :month | |
| + return db_string[0..6].split('-')[0..1].map(&:to_i) | |
| + end | |
| + end | |
| + | |
| + def mysql_format(date_column) | |
| + return case @identifier | |
| + when :hour | |
| + "DATE_FORMAT(#{date_column}, '%Y/%m/%d/%H')" | |
| + when :day | |
| + "DATE_FORMAT(#{date_column}, '%Y/%m/%d')" | |
| + when :week | |
| + "YEARWEEK(#{date_column}, 3)" | |
| + when :month | |
| + "DATE_FORMAT(#{date_column}, '%Y/%m')" | |
| + end | |
| + end | |
| + | |
| + def sqlite_format(date_column) | |
| + return case @identifier | |
| + when :hour | |
| + "strftime('%Y/%m/%d/%H', #{date_column})" | |
| + when :day | |
| + "strftime('%Y/%m/%d', #{date_column})" | |
| + when :week | |
| + "date(#{date_column}, 'weekday 0')" | |
| + when :month | |
| + "strftime('%Y/%m', #{date_column})" | |
| + end | |
| + end | |
| + | |
| + def postgresql_format(date_column) | |
| + return case @identifier | |
| + when :hour | |
| + "date_trunc('hour', #{date_column})" | |
| + when :day | |
| + "date_trunc('day', #{date_column})" | |
| + when :week | |
| + "date_trunc('week', #{date_column})" | |
| + when :month | |
| + "date_trunc('month', #{date_column})" | |
| + end | |
| + end | |
| + | |
| + end | |
| + | |
| + end | |
| + | |
| +end | |
| diff --git a/lib/simplabs/reports_as_sparkline/report.rb b/lib/simplabs/reports… | |
| @@ -0,0 +1,129 @@ | |
| +module Simplabs #:nodoc: | |
| + | |
| + module ReportsAsSparkline #:nodoc: | |
| + | |
| + # The Report class that does all the data retrieval and calculations | |
| + class Report | |
| + | |
| + attr_reader :klass, :name, :date_column, :value_column, :aggregation, :o… | |
| + | |
| + # ==== Parameters | |
| + # * <tt>klass</tt> - The model the report works on (This is the class yo… | |
| + # * <tt>name</tt> - The name of the report (as in Simplabs::ReportsAsSpa… | |
| + # | |
| + # ==== Options | |
| + # | |
| + # * <tt>:date_column</tt> - The name of the date column on that the reco… | |
| + # * <tt>:value_column</tt> - The name of the column that holds the value… | |
| + # * <tt>:aggregation</tt> - The aggregation to use (one of :count, :sum,… | |
| + # * <tt>:grouping</tt> - The period records are grouped on (:hour, :day,… | |
| + # * <tt>:limit</tt> - The number of periods to get (see :grouping) | |
| + # * <tt>:conditions</tt> - Conditions like in ActiveRecord::Base#find; o… | |
| + # * <tt>:live_data</tt> - Specified whether data for the current reporti… | |
| + # * <tt>:end_date</tt> - When specified, the report will only include da… | |
| + def initialize(klass, name, options = {}) | |
| + ensure_valid_options(options) | |
| + @klass = klass | |
| + @name = name | |
| + @date_column = (options[:date_column] || 'created_at').to_s | |
| + @aggregation = options[:aggregation] || :count | |
| + @value_column = (options[:value_column] || (@aggregation == :count ? '… | |
| + @options = { | |
| + :limit => options[:limit] || 100, | |
| + :conditions => options[:conditions] || [], | |
| + :grouping => Grouping.new(options[:grouping] || :day), | |
| + :live_data => options[:live_data] || false, | |
| + :end_date => options[:end_date] || false | |
| + } | |
| + @options.merge!(options) | |
| + @options.freeze | |
| + end | |
| + | |
| + # Runs the report and returns an array of array of DateTimes and Floats | |
| + # | |
| + # ==== Options | |
| + # * <tt>:limit</tt> - The number of periods to get | |
| + # * <tt>:conditions</tt> - Conditions like in ActiveRecord::Base#find; o… | |
| + # * <tt>:grouping</tt> - The period records are grouped on (:hour, :day,… | |
| + # * <tt>:live_data</tt> - Specified whether data for the current reporti… | |
| + # * <tt>:end_date</tt> - When specified, the report will only include da… | |
| + def run(options = {}) | |
| + custom_conditions = options.key?(:conditions) | |
| + options = options_for_run(options) | |
| + ReportCache.process(self, options, !custom_conditions) do |begin_at, e… | |
| + read_data(begin_at, end_at, options) | |
| + end | |
| + end | |
| + | |
| + private | |
| + | |
| + def options_for_run(options = {}) | |
| + options = options.dup | |
| + ensure_valid_options(options, :run) | |
| + options.reverse_merge!(@options) | |
| + options[:grouping] = Grouping.new(options[:grouping]) unless options… | |
| + return options | |
| + end | |
| + | |
| + def read_data(begin_at, end_at, options) | |
| + conditions = setup_conditions(begin_at, end_at, options[:conditions]) | |
| + @klass.send(@aggregation, | |
| + @value_column, | |
| + :conditions => conditions, | |
| + :group => options[:grouping].to_sql(@date_column), | |
| + :order => "#{options[:grouping].to_sql(@date_column)} ASC" | |
| + ) | |
| + end | |
| + | |
| + def setup_conditions(begin_at, end_at, custom_conditions = []) | |
| + conditions = [''] | |
| + if custom_conditions.is_a?(Hash) | |
| + conditions = [custom_conditions.map do |k, v| | |
| + if v.nil? | |
| + "#{k.to_s} IS NULL" | |
| + elsif v.is_a?(Array) || v.is_a?(Range) | |
| + "#{k.to_s} IN (?)" | |
| + else | |
| + "#{k.to_s} = ?" | |
| + end | |
| + end.join(' AND '), *custom_conditions.map { |k, v| v }.compact] | |
| + elsif custom_conditions.size > 0 | |
| + conditions = [(custom_conditions[0] || ''), *custom_conditions[1..… | |
| + end | |
| + conditions[0] += "#{(conditions[0].blank? ? '' : ' AND ') + @date_co… | |
| + conditions[0] += if begin_at && end_at | |
| + 'BETWEEN ? AND ?' | |
| + elsif begin_at | |
| + '>= ?' | |
| + elsif end_at | |
| + '<= ?' | |
| + else | |
| + raise ArgumentError.new('You must pass either begin_at, end_at or … | |
| + end | |
| + conditions << begin_at if begin_at | |
| + conditions << end_at if end_at | |
| + conditions | |
| + end | |
| + | |
| + def ensure_valid_options(options, context = :initialize) | |
| + case context | |
| + when :initialize | |
| + options.each_key do |k| | |
| + raise ArgumentError.new("Invalid option #{k}") unless [:limit,… | |
| + end | |
| + raise ArgumentError.new("Invalid aggregation #{options[:aggregat… | |
| + raise ArgumentError.new('The name of the column holding the valu… | |
| + when :run | |
| + options.each_key do |k| | |
| + raise ArgumentError.new("Invalid option #{k}") unless [:limit,… | |
| + end | |
| + end | |
| + raise ArgumentError.new("Invalid grouping #{options[:grouping]}") if… | |
| + raise ArgumentError.new("Invalid conditions: #{options[:conditions].… | |
| + end | |
| + | |
| + end | |
| + | |
| + end | |
| + | |
| +end | |
| diff --git a/lib/simplabs/reports_as_sparkline/report_cache.rb b/lib/simplabs/r… | |
| @@ -0,0 +1,116 @@ | |
| +module Simplabs #:nodoc: | |
| + | |
| + module ReportsAsSparkline #:nodoc: | |
| + | |
| + class ReportCache < ActiveRecord::Base #:nodoc: | |
| + | |
| + def self.process(report, options, cache = true, &block) | |
| + raise ArgumentError.new('A block must be given') unless block_given? | |
| + self.transaction do | |
| + cached_data = [] | |
| + first_reporting_period = ReportingPeriod.first(options[:grouping], o… | |
| + last_reporting_period = options[:end_date] ? ReportingPeriod.new(opt… | |
| + if cache | |
| + cached_data = find_cached_data(report, options, first_reporting_pe… | |
| + first_cached_reporting_period = cached_data.empty? ? nil : Reporti… | |
| + last_cached_reporting_period = cached_data.empty? ? nil : Reportin… | |
| + end | |
| + new_after_cache_data = if !options[:live_data] && last_cached_report… | |
| + [] | |
| + else | |
| + end_date = options[:live_data] ? nil : last_reporting_period && la… | |
| + yield((last_cached_reporting_period.next rescue first_reporting_pe… | |
| + end | |
| + new_before_cache_data = if cached_data.empty? || first_cached_report… | |
| + [] | |
| + else | |
| + yield(first_reporting_period.date_time, first_cached_reporting_per… | |
| + end | |
| + prepare_result(new_before_cache_data, new_after_cache_data, cached_d… | |
| + end | |
| + end | |
| + | |
| + private | |
| + | |
| + def self.prepare_result(new_before_cache_data, new_after_cache_data, c… | |
| + cache_map_proc = lambda { |data| [ReportingPeriod.from_db_string(opt… | |
| + | |
| + new_after_cache_data = new_after_cache_data.map &cache_map_proc | |
| + new_before_cache_data = new_before_cache_data.map &cache_map_proc | |
| + result = cached_data.map { |cached| [cached.reporting_period, cached… | |
| + | |
| + first_reporting_period = ReportingPeriod.first(options[:grouping], o… | |
| + last_reporting_period = ReportingPeriod.new(options[:grouping], opti… | |
| + first_cached_reporting_period = cached_data.empty? ? nil : Reporting… | |
| + last_cached_reporting_period = cached_data.empty? ? nil : ReportingP… | |
| + | |
| + if first_cached_reporting_period | |
| + reporting_period = first_reporting_period | |
| + while reporting_period < first_cached_reporting_period | |
| + cached = build_cached_data(report, options[:grouping], reporting… | |
| + cached.save! if cache | |
| + result.insert(0, [reporting_period.date_time, cached.value]) | |
| + reporting_period = reporting_period.next | |
| + end | |
| + end | |
| + | |
| + reporting_period = cached_data.empty? ? first_reporting_period : las… | |
| + | |
| + while reporting_period < last_reporting_period | |
| + cached = build_cached_data(report, options[:grouping], reporting_p… | |
| + cached.save! if cache | |
| + result << [reporting_period.date_time, cached.value] | |
| + reporting_period = reporting_period.next | |
| + end | |
| + | |
| + if options[:live_data] | |
| + result << [last_reporting_period.date_time, find_value(new_after_c… | |
| + end | |
| + result | |
| + end | |
| + | |
| + def self.find_value(data, reporting_period) | |
| + data = data.detect { |d| d[0] == reporting_period } | |
| + data ? data[1] : 0.0 | |
| + end | |
| + | |
| + def self.build_cached_data(report, grouping, reporting_period, value) | |
| + self.new( | |
| + :model_name => report.klass.to_s, | |
| + :report_name => report.name.to_s, | |
| + :grouping => grouping.identifier.to_s, | |
| + :aggregation => report.aggregation.to_s, | |
| + :reporting_period => reporting_period.date_time, | |
| + :value => value | |
| + ) | |
| + end | |
| + | |
| + def self.find_cached_data(report, options, first_reporting_period, las… | |
| + conditions = [ | |
| + 'model_name = ? AND report_name = ? AND grouping = ? AND aggregati… | |
| + report.klass.to_s, | |
| + report.name.to_s, | |
| + options[:grouping].identifier.to_s, | |
| + report.aggregation.to_s | |
| + ] | |
| + if last_reporting_period | |
| + conditions.first << ' AND reporting_period BETWEEN ? AND ?' | |
| + conditions << first_reporting_period.date_time | |
| + conditions << last_reporting_period.date_time | |
| + else | |
| + conditions.first << ' AND reporting_period >= ?' | |
| + conditions << first_reporting_period.date_time | |
| + end | |
| + self.find( | |
| + :all, | |
| + :conditions => conditions, | |
| + :limit => options[:limit], | |
| + :order => 'reporting_period ASC' | |
| + ) | |
| + end | |
| + | |
| + end | |
| + | |
| + end | |
| + | |
| +end | |
| diff --git a/lib/simplabs/reports_as_sparkline/reporting_period.rb b/lib/simpla… | |
| @@ -0,0 +1,94 @@ | |
| +module Simplabs #:nodoc: | |
| + | |
| + module ReportsAsSparkline #:nodoc: | |
| + | |
| + # A ReportingPeriod is - depending on the Grouping - either a specific ho… | |
| + class ReportingPeriod | |
| + | |
| + attr_reader :date_time, :grouping | |
| + | |
| + # ==== Parameters | |
| + # * <tt>grouping</tt> - The Simplabs::ReportsAsSparkline::Grouping of th… | |
| + # * <tt>date_time</tt> - The DateTime that reporting period is created f… | |
| + def initialize(grouping, date_time = nil) | |
| + @grouping = grouping | |
| + @date_time = parse_date_time(date_time || DateTime.now) | |
| + end | |
| + | |
| + # Returns the first reporting period for a grouping and a limit; e.g. th… | |
| + # | |
| + # ==== Parameters | |
| + # * <tt>grouping</tt> - The Simplabs::ReportsAsSparkline::Grouping of th… | |
| + # * <tt>limit</tt> - The number of reporting periods until the first one | |
| + def self.first(grouping, limit, end_date = nil) | |
| + self.new(grouping, end_date).offset(-limit) | |
| + end | |
| + | |
| + def self.from_db_string(grouping, db_string) #:nodoc: | |
| + parts = grouping.date_parts_from_db_string(db_string) | |
| + result = case grouping.identifier | |
| + when :hour | |
| + self.new(grouping, DateTime.new(parts[0], parts[1], parts[2], part… | |
| + when :day | |
| + self.new(grouping, Date.new(parts[0], parts[1], parts[2])) | |
| + when :week | |
| + self.new(grouping, Date.commercial(parts[0], parts[1], 1)) | |
| + when :month | |
| + self.new(grouping, Date.new(parts[0], parts[1], 1)) | |
| + end | |
| + result | |
| + end | |
| + | |
| + # Returns the next reporting period (that is next hour/day/month/year) | |
| + def next | |
| + self.offset(1) | |
| + end | |
| + | |
| + # Returns the previous reporting period (that is next hour/day/month/yea… | |
| + def previous | |
| + self.offset(-1) | |
| + end | |
| + | |
| + # Returns the reporting period with the specified offset from the current | |
| + # | |
| + # ==== Parameters | |
| + # * <tt>offset</tt> - The offset to return the reporting period for (spe… | |
| + def offset(offset) | |
| + self.class.new(@grouping, @date_time + offset.send(@grouping.identifie… | |
| + end | |
| + | |
| + def ==(other) #:nodoc: | |
| + if other.class == Simplabs::ReportsAsSparkline::ReportingPeriod | |
| + return @date_time.to_s == other.date_time.to_s && @grouping.identifi… | |
| + end | |
| + false | |
| + end | |
| + | |
| + def <(other) #:nodoc: | |
| + if other.class == Simplabs::ReportsAsSparkline::ReportingPeriod | |
| + return @date_time < other.date_time | |
| + end | |
| + raise ArgumentError.new("Can only compare instances of #{Simplabs::Rep… | |
| + end | |
| + | |
| + private | |
| + | |
| + def parse_date_time(date_time) | |
| + return case @grouping.identifier | |
| + when :hour | |
| + DateTime.new(date_time.year, date_time.month, date_time.day, dat… | |
| + when :day | |
| + date_time.to_date | |
| + when :week | |
| + date_time = (date_time - date_time.wday.days) + 1.day | |
| + Date.new(date_time.year, date_time.month, date_time.day) | |
| + when :month | |
| + Date.new(date_time.year, date_time.month, 1) | |
| + end | |
| + end | |
| + | |
| + end | |
| + | |
| + end | |
| + | |
| +end | |
| diff --git a/lib/simplabs/reports_as_sparkline/sparkline_tag_helper.rb b/lib/si… | |
| @@ -0,0 +1,39 @@ | |
| +module Simplabs #:nodoc: | |
| + | |
| + module ReportsAsSparkline #:nodoc: | |
| + | |
| + module SparklineTagHelper | |
| + | |
| + # Renders a sparkline with the given data. | |
| + # | |
| + # ==== Parameters | |
| + # | |
| + # * <tt>data</tt> - The data to render the sparkline for | |
| + # | |
| + # ==== Options | |
| + # | |
| + # * <tt>width</tt> - The width of the generated image | |
| + # * <tt>height</tt> - The height of the generated image | |
| + # * <tt>line_color</tt> - The line color of the sparkline (hex code) | |
| + # * <tt>fill_color</tt> - The color to fill the area below the sparkline… | |
| + # * <tt>labels</tt> - The axes to render lables for (Array of :x, :y, :r… | |
| + # | |
| + # ==== Example | |
| + # <%= sparkline_tag(User.registrations_report, :width => 200, :height =>… | |
| + def sparkline_tag(data, options = {}) | |
| + options.reverse_merge!({ :width => 300, :height => 34, :line_color => … | |
| + data = data.collect { |d| d[1] } | |
| + labels = "" | |
| + unless options[:labels].empty? | |
| + labels = "&chxt=#{options[:labels].map(&:to_s).join(',')}&chxr=0,0,#… | |
| + end | |
| + image_tag( | |
| + "http://chart.apis.google.com/chart?cht=ls&chs=#{options[:width]}x#{… | |
| + ) | |
| + end | |
| + | |
| + end | |
| + | |
| + end | |
| + | |
| +end | |
| diff --git a/rdoc/classes/Kvlr/ReportsAsSparkline/ClassMethods.html b/rdoc/clas… | |
| @@ -5,7 +5,7 @@ | |
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
| <head> | |
| - <title>Module: Kvlr::ReportsAsSparkline::ClassMethods</title> | |
| + <title>Module: Simplabs::ReportsAsSparkline::ClassMethods</title> | |
| <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> | |
| <meta http-equiv="Content-Script-Type" content="text/javascript" /> | |
| <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" medi… | |
| @@ -50,13 +50,13 @@ | |
| <table class="header-table"> | |
| <tr class="top-aligned-row"> | |
| <td><strong>Module</strong></td> | |
| - <td class="class-name-in-header">Kvlr::ReportsAsSparkline::ClassMeth… | |
| + <td class="class-name-in-header">Simplabs::ReportsAsSparkline::Class… | |
| </tr> | |
| <tr class="top-aligned-row"> | |
| <td><strong>In:</strong></td> | |
| <td> | |
| - <a href="../../../files/lib/kvlr/reports_as_sparkline_rb.html"> | |
| - lib/kvlr/reports_as_sparkline.rb | |
| + <a href="../../../files/lib/simplabs/reports_as_sparkline_rb.h… | |
| + lib/simplabs/reports_as_sparkline.rb | |
| </a> | |
| <br /> | |
| </td> | |
| @@ -115,7 +115,7 @@ | |
| <p> | |
| Generates a report on a model. That report can then be executed via the new | |
| method <name>_report (see documentation of <a | |
| -href="Report.html#M000011">Kvlr::ReportsAsSparkline::Report#run</a>). | |
| +href="Report.html#M000011">Simplabs::ReportsAsSparkline::Report#run</a>). | |
| </p> | |
| <h4>Parameters</h4> | |
| <ul> | |
| @@ -177,14 +177,14 @@ false) | |
| onclick="toggleCode('M000002-source');return false;">[Source]</a><… | |
| <div class="method-source-code" id="M000002-source"> | |
| <pre> | |
| - <span class="ruby-comment cmt"># File lib/kvlr/reports_as_sparkline.rb, li… | |
| + <span class="ruby-comment cmt"># File lib/simplabs/reports_as_sparkline.rb… | |
| 39: <span class="ruby-keyword kw">def</span> <span class="ruby-identifie… | |
| 40: (<span class="ruby-keyword kw">class</span> <span class="ruby-oper… | |
| 41: <span class="ruby-identifier">define_method</span> <span class="… | |
| 42: <span class="ruby-keyword kw">if</span> <span class="ruby-iden… | |
| -43: <span class="ruby-identifier">report</span> = <span class="r… | |
| +43: <span class="ruby-identifier">report</span> = <span class="r… | |
| 44: <span class="ruby-keyword kw">else</span> | |
| -45: <span class="ruby-identifier">report</span> = <span class="r… | |
| +45: <span class="ruby-identifier">report</span> = <span class="r… | |
| 46: <span class="ruby-keyword kw">end</span> | |
| 47: <span class="ruby-identifier">raise</span> <span class="ruby-c… | |
| 48: <span class="ruby-identifier">report</span>.<span class="ruby-… | |
| diff --git a/rdoc/classes/Kvlr/ReportsAsSparkline/CumulatedReport.html b/rdoc/c… | |
| @@ -5,7 +5,7 @@ | |
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
| <head> | |
| - <title>Class: Kvlr::ReportsAsSparkline::CumulatedReport</title> | |
| + <title>Class: Simplabs::ReportsAsSparkline::CumulatedReport</title> | |
| <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> | |
| <meta http-equiv="Content-Script-Type" content="text/javascript" /> | |
| <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" medi… | |
| @@ -50,13 +50,13 @@ | |
| <table class="header-table"> | |
| <tr class="top-aligned-row"> | |
| <td><strong>Class</strong></td> | |
| - <td class="class-name-in-header">Kvlr::ReportsAsSparkline::Cumulated… | |
| + <td class="class-name-in-header">Simplabs::ReportsAsSparkline::Cumul… | |
| </tr> | |
| <tr class="top-aligned-row"> | |
| <td><strong>In:</strong></td> | |
| <td> | |
| - <a href="../../../files/lib/kvlr/reports_as_sparkline/cumulate… | |
| - lib/kvlr/reports_as_sparkline/cumulated_report.rb | |
| + <a href="../../../files/lib/simplabs/reports_as_sparkline/cumu… | |
| + lib/simplabs/reports_as_sparkline/cumulated_report.rb | |
| </a> | |
| <br /> | |
| </td> | |
| @@ -83,15 +83,15 @@ | |
| <div id="description"> | |
| <p> | |
| A special report class that cumulates all data (see <a | |
| -href="Report.html">Kvlr::ReportsAsSparkline::Report</a>) | |
| +href="Report.html">Simplabs::ReportsAsSparkline::Report</a>) | |
| </p> | |
| <h4>Examples</h4> | |
| <pre> | |
| - When Kvlr::ReportsAsSparkline::Report returns | |
| + When Simplabs::ReportsAsSparkline::Report returns | |
| [[<DateTime today>, 1], [<DateTime yesterday>, 2], etc.] | |
| - Kvlr::ReportsAsSparkline::CumulatedReport returns | |
| + Simplabs::ReportsAsSparkline::CumulatedReport returns | |
| [[<DateTime today>, 3], [<DateTime yesterday>, 2], etc.] | |
| </pre> | |
| @@ -139,13 +139,13 @@ href="Report.html">Kvlr::ReportsAsSparkline::Report</a>) | |
| <div class="method-description"> | |
| <p> | |
| Runs the report (see <a | |
| -href="Report.html#M000011">Kvlr::ReportsAsSparkline::Report#run</a>) | |
| +href="Report.html#M000011">Simplabs::ReportsAsSparkline::Report#run</a>) | |
| </p> | |
| <p><a class="source-toggle" href="#" | |
| onclick="toggleCode('M000003-source');return false;">[Source]</a><… | |
| <div class="method-source-code" id="M000003-source"> | |
| <pre> | |
| - <span class="ruby-comment cmt"># File lib/kvlr/reports_as_sparkline/cumula… | |
| + <span class="ruby-comment cmt"># File lib/simplabs/reports_as_sparkline/cu… | |
| 19: <span class="ruby-keyword kw">def</span> <span class="ruby-identifie… | |
| 20: <span class="ruby-identifier">cumulate</span>(<span class="ruby-ke… | |
| 21: <span class="ruby-keyword kw">end</span> | |
| diff --git a/rdoc/classes/Kvlr/ReportsAsSparkline/Grouping.html b/rdoc/classes/… | |
| @@ -5,7 +5,7 @@ | |
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
| <head> | |
| - <title>Class: Kvlr::ReportsAsSparkline::Grouping</title> | |
| + <title>Class: Simplabs::ReportsAsSparkline::Grouping</title> | |
| <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> | |
| <meta http-equiv="Content-Script-Type" content="text/javascript" /> | |
| <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" medi… | |
| @@ -50,13 +50,13 @@ | |
| <table class="header-table"> | |
| <tr class="top-aligned-row"> | |
| <td><strong>Class</strong></td> | |
| - <td class="class-name-in-header">Kvlr::ReportsAsSparkline::Grouping<… | |
| + <td class="class-name-in-header">Simplabs::ReportsAsSparkline::Group… | |
| </tr> | |
| <tr class="top-aligned-row"> | |
| <td><strong>In:</strong></td> | |
| <td> | |
| - <a href="../../../files/lib/kvlr/reports_as_sparkline/grouping… | |
| - lib/kvlr/reports_as_sparkline/grouping.rb | |
| + <a href="../../../files/lib/simplabs/reports_as_sparkline/grou… | |
| + lib/simplabs/reports_as_sparkline/grouping.rb | |
| </a> | |
| <br /> | |
| </td> | |
| @@ -137,7 +137,7 @@ href="Grouping.html#M000005">identifier</a> of the grouping… | |
| onclick="toggleCode('M000004-source');return false;">[Source]</a><… | |
| <div class="method-source-code" id="M000004-source"> | |
| <pre> | |
| - <span class="ruby-comment cmt"># File lib/kvlr/reports_as_sparkline/groupi… | |
| + <span class="ruby-comment cmt"># File lib/simplabs/reports_as_sparkline/gr… | |
| 10: <span class="ruby-keyword kw">def</span> <span class="ruby-identifie… | |
| 11: <span class="ruby-identifier">raise</span> <span class="ruby-const… | |
| 12: <span class="ruby-ivar">@identifier</span> = <span class="ruby-ide… | |
| @@ -167,7 +167,7 @@ href="Grouping.html#M000005">identifier</a> | |
| onclick="toggleCode('M000005-source');return false;">[Source]</a><… | |
| <div class="method-source-code" id="M000005-source"> | |
| <pre> | |
| - <span class="ruby-comment cmt"># File lib/kvlr/reports_as_sparkline/groupi… | |
| + <span class="ruby-comment cmt"># File lib/simplabs/reports_as_sparkline/gr… | |
| 16: <span class="ruby-keyword kw">def</span> <span class="ruby-identifie… | |
| 17: <span class="ruby-ivar">@identifier</span> | |
| 18: <span class="ruby-keyword kw">end</span> | |
| diff --git a/rdoc/classes/Kvlr/ReportsAsSparkline/Report.html b/rdoc/classes/Kv… | |
| @@ -5,7 +5,7 @@ | |
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
| <head> | |
| - <title>Class: Kvlr::ReportsAsSparkline::Report</title> | |
| + <title>Class: Simplabs::ReportsAsSparkline::Report</title> | |
| <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> | |
| <meta http-equiv="Content-Script-Type" content="text/javascript" /> | |
| <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" medi… | |
| @@ -50,13 +50,13 @@ | |
| <table class="header-table"> | |
| <tr class="top-aligned-row"> | |
| <td><strong>Class</strong></td> | |
| - <td class="class-name-in-header">Kvlr::ReportsAsSparkline::Report</t… | |
| + <td class="class-name-in-header">Simplabs::ReportsAsSparkline::Repor… | |
| </tr> | |
| <tr class="top-aligned-row"> | |
| <td><strong>In:</strong></td> | |
| <td> | |
| - <a href="../../../files/lib/kvlr/reports_as_sparkline/report_r… | |
| - lib/kvlr/reports_as_sparkline/report.rb | |
| + <a href="../../../files/lib/simplabs/reports_as_sparkline/repo… | |
| + lib/simplabs/reports_as_sparkline/report.rb | |
| </a> | |
| <br /> | |
| </td> | |
| @@ -168,12 +168,12 @@ and calculations | |
| <ul> | |
| <li><tt>klass</tt> - The model the report works on (This is the class you | |
| invoke <a | |
| -href="ClassMethods.html#M000002">Kvlr::ReportsAsSparkline::ClassMethods#report… | |
| +href="ClassMethods.html#M000002">Simplabs::ReportsAsSparkline::ClassMethods#re… | |
| on) | |
| </li> | |
| <li><tt>name</tt> - The name of the report (as in <a | |
| -href="ClassMethods.html#M000002">Kvlr::ReportsAsSparkline::ClassMethods#report… | |
| +href="ClassMethods.html#M000002">Simplabs::ReportsAsSparkline::ClassMethods#re… | |
| </li> | |
| </ul> | |
| @@ -216,7 +216,7 @@ false) | |
| onclick="toggleCode('M000010-source');return false;">[Source]</a><… | |
| <div class="method-source-code" id="M000010-source"> | |
| <pre> | |
| - <span class="ruby-comment cmt"># File lib/kvlr/reports_as_sparkline/report… | |
| + <span class="ruby-comment cmt"># File lib/simplabs/reports_as_sparkline/re… | |
| 23: <span class="ruby-keyword kw">def</span> <span class="ruby-identifie… | |
| 24: <span class="ruby-identifier">ensure_valid_options</span>(<span cl… | |
| 25: <span class="ruby-ivar">@klass</span> = <span class="ruby-i… | |
| @@ -279,7 +279,7 @@ false) | |
| onclick="toggleCode('M000011-source');return false;">[Source]</a><… | |
| <div class="method-source-code" id="M000011-source"> | |
| <pre> | |
| - <span class="ruby-comment cmt"># File lib/kvlr/reports_as_sparkline/report… | |
| + <span class="ruby-comment cmt"># File lib/simplabs/reports_as_sparkline/re… | |
| 47: <span class="ruby-keyword kw">def</span> <span class="ruby-identifie… | |
| 48: <span class="ruby-identifier">ensure_valid_options</span>(<span cl… | |
| 49: <span class="ruby-identifier">custom_conditions</span> = <span cla… | |
| diff --git a/rdoc/classes/Kvlr/ReportsAsSparkline/ReportingPeriod.html b/rdoc/c… | |
| @@ -5,7 +5,7 @@ | |
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
| <head> | |
| - <title>Class: Kvlr::ReportsAsSparkline::ReportingPeriod</title> | |
| + <title>Class: Simplabs::ReportsAsSparkline::ReportingPeriod</title> | |
| <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> | |
| <meta http-equiv="Content-Script-Type" content="text/javascript" /> | |
| <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" medi… | |
| @@ -50,13 +50,13 @@ | |
| <table class="header-table"> | |
| <tr class="top-aligned-row"> | |
| <td><strong>Class</strong></td> | |
| - <td class="class-name-in-header">Kvlr::ReportsAsSparkline::Reporting… | |
| + <td class="class-name-in-header">Simplabs::ReportsAsSparkline::Repor… | |
| </tr> | |
| <tr class="top-aligned-row"> | |
| <td><strong>In:</strong></td> | |
| <td> | |
| - <a href="../../../files/lib/kvlr/reports_as_sparkline/reportin… | |
| - lib/kvlr/reports_as_sparkline/reporting_period.rb | |
| + <a href="../../../files/lib/simplabs/reports_as_sparkline/repo… | |
| + lib/simplabs/reports_as_sparkline/reporting_period.rb | |
| </a> | |
| <br /> | |
| </td> | |
| @@ -158,7 +158,7 @@ href="Grouping.html">Grouping</a> :day and limit 2 would be… | |
| <h4>Parameters</h4> | |
| <ul> | |
| <li><tt>grouping</tt> - The <a | |
| -href="Grouping.html">Kvlr::ReportsAsSparkline::Grouping</a> of the | |
| +href="Grouping.html">Simplabs::ReportsAsSparkline::Grouping</a> of the | |
| reporting period | |
| </li> | |
| @@ -171,7 +171,7 @@ href="ReportingPeriod.html#M000007">first</a> one | |
| onclick="toggleCode('M000007-source');return false;">[Source]</a><… | |
| <div class="method-source-code" id="M000007-source"> | |
| <pre> | |
| - <span class="ruby-comment cmt"># File lib/kvlr/reports_as_sparkline/report… | |
| + <span class="ruby-comment cmt"># File lib/simplabs/reports_as_sparkline/re… | |
| 23: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword k… | |
| 24: <span class="ruby-keyword kw">return</span> <span class="ruby-keyw… | |
| 25: <span class="ruby-keyword kw">when</span> <span class="ruby-iden… | |
| @@ -203,7 +203,7 @@ href="ReportingPeriod.html#M000007">first</a> one | |
| <h4>Parameters</h4> | |
| <ul> | |
| <li><tt>grouping</tt> - The <a | |
| -href="Grouping.html">Kvlr::ReportsAsSparkline::Grouping</a> of the | |
| +href="Grouping.html">Simplabs::ReportsAsSparkline::Grouping</a> of the | |
| reporting period | |
| </li> | |
| @@ -215,7 +215,7 @@ reporting period | |
| onclick="toggleCode('M000006-source');return false;">[Source]</a><… | |
| <div class="method-source-code" id="M000006-source"> | |
| <pre> | |
| - <span class="ruby-comment cmt"># File lib/kvlr/reports_as_sparkline/report… | |
| + <span class="ruby-comment cmt"># File lib/simplabs/reports_as_sparkline/re… | |
| 13: <span class="ruby-keyword kw">def</span> <span class="ruby-identifie… | |
| 14: <span class="ruby-ivar">@grouping</span> = <span class="ruby-iden… | |
| 15: <span class="ruby-ivar">@date_time</span> = <span class="ruby-iden… | |
| @@ -246,7 +246,7 @@ hour/day/month/year) | |
| onclick="toggleCode('M000008-source');return false;">[Source]</a><… | |
| <div class="method-source-code" id="M000008-source"> | |
| <pre> | |
| - <span class="ruby-comment cmt"># File lib/kvlr/reports_as_sparkline/report… | |
| + <span class="ruby-comment cmt"># File lib/simplabs/reports_as_sparkline/re… | |
| 53: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword k… | |
| 54: <span class="ruby-keyword kw">return</span> <span class="ruby-keyw… | |
| 55: <span class="ruby-keyword kw">when</span> <span class="ruby-iden… | |
| @@ -283,7 +283,7 @@ hour/day/month/year) | |
| onclick="toggleCode('M000009-source');return false;">[Source]</a><… | |
| <div class="method-source-code" id="M000009-source"> | |
| <pre> | |
| - <span class="ruby-comment cmt"># File lib/kvlr/reports_as_sparkline/report… | |
| + <span class="ruby-comment cmt"># File lib/simplabs/reports_as_sparkline/re… | |
| 67: <span class="ruby-keyword kw">def</span> <span class="ruby-identifie… | |
| 68: <span class="ruby-keyword kw">return</span> <span class="ruby-keyw… | |
| 69: <span class="ruby-keyword kw">when</span> <span class="ruby-iden… | |
| diff --git a/rdoc/classes/Kvlr/ReportsAsSparkline/SparklineTagHelper.html b/rdo… | |
| @@ -5,7 +5,7 @@ | |
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
| <head> | |
| - <title>Module: Kvlr::ReportsAsSparkline::SparklineTagHelper</title> | |
| + <title>Module: Simplabs::ReportsAsSparkline::SparklineTagHelper</title> | |
| <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> | |
| <meta http-equiv="Content-Script-Type" content="text/javascript" /> | |
| <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" medi… | |
| @@ -50,13 +50,13 @@ | |
| <table class="header-table"> | |
| <tr class="top-aligned-row"> | |
| <td><strong>Module</strong></td> | |
| - <td class="class-name-in-header">Kvlr::ReportsAsSparkline::Sparkline… | |
| + <td class="class-name-in-header">Simplabs::ReportsAsSparkline::Spark… | |
| </tr> | |
| <tr class="top-aligned-row"> | |
| <td><strong>In:</strong></td> | |
| <td> | |
| - <a href="../../../files/lib/kvlr/reports_as_sparkline/sparklin… | |
| - lib/kvlr/reports_as_sparkline/sparkline_tag_helper.rb | |
| + <a href="../../../files/lib/simplabs/reports_as_sparkline/spar… | |
| + lib/simplabs/reports_as_sparkline/sparkline_tag_helper.rb | |
| </a> | |
| <br /> | |
| </td> | |
| @@ -151,7 +151,7 @@ href="SparklineTagHelper.html#M000001">sparkline_tag</a>(Us… | |
| onclick="toggleCode('M000001-source');return false;">[Source]</a><… | |
| <div class="method-source-code" id="M000001-source"> | |
| <pre> | |
| - <span class="ruby-comment cmt"># File lib/kvlr/reports_as_sparkline/sparkl… | |
| + <span class="ruby-comment cmt"># File lib/simplabs/reports_as_sparkline/sp… | |
| 23: <span class="ruby-keyword kw">def</span> <span class="ruby-identifie… | |
| 24: <span class="ruby-identifier">options</span>.<span class="ruby-ide… | |
| 25: <span class="ruby-identifier">data</span> = <span class="ruby-iden… | |
| diff --git a/rdoc/files/README_rdoc.html b/rdoc/files/README_rdoc.html | |
| @@ -227,7 +227,7 @@ If you are on Rails &lt; 2.1, do this from your RAILS_R… | |
| <p> | |
| To achieve best performance, you should add indices to your tables on the | |
| date columns that are used for grouping the records (see | |
| -Kvlr::ReportsAsSparkline::ClassMethods.reports_as_sparkline): | |
| +Simplabs::ReportsAsSparkline::ClassMethods.reports_as_sparkline): | |
| </p> | |
| <pre> | |
| add_index :[table], :[date_column] | |
| diff --git a/rdoc/files/lib/kvlr/reports_as_sparkline/cumulated_report_rb.html … | |
| @@ -51,7 +51,7 @@ | |
| <table class="header-table"> | |
| <tr class="top-aligned-row"> | |
| <td><strong>Path:</strong></td> | |
| - <td>lib/kvlr/reports_as_sparkline/cumulated_report.rb | |
| + <td>lib/simplabs/reports_as_sparkline/cumulated_report.rb | |
| </td> | |
| </tr> | |
| <tr class="top-aligned-row"> | |
| diff --git a/rdoc/files/lib/kvlr/reports_as_sparkline/grouping_rb.html b/rdoc/f… | |
| @@ -51,7 +51,7 @@ | |
| <table class="header-table"> | |
| <tr class="top-aligned-row"> | |
| <td><strong>Path:</strong></td> | |
| - <td>lib/kvlr/reports_as_sparkline/grouping.rb | |
| + <td>lib/simplabs/reports_as_sparkline/grouping.rb | |
| </td> | |
| </tr> | |
| <tr class="top-aligned-row"> | |
| diff --git a/rdoc/files/lib/kvlr/reports_as_sparkline/report_cache_rb.html b/rd… | |
| @@ -51,7 +51,7 @@ | |
| <table class="header-table"> | |
| <tr class="top-aligned-row"> | |
| <td><strong>Path:</strong></td> | |
| - <td>lib/kvlr/reports_as_sparkline/report_cache.rb | |
| + <td>lib/simplabs/reports_as_sparkline/report_cache.rb | |
| </td> | |
| </tr> | |
| <tr class="top-aligned-row"> | |
| diff --git a/rdoc/files/lib/kvlr/reports_as_sparkline/report_rb.html b/rdoc/fil… | |
| @@ -51,7 +51,7 @@ | |
| <table class="header-table"> | |
| <tr class="top-aligned-row"> | |
| <td><strong>Path:</strong></td> | |
| - <td>lib/kvlr/reports_as_sparkline/report.rb | |
| + <td>lib/simplabs/reports_as_sparkline/report.rb | |
| </td> | |
| </tr> | |
| <tr class="top-aligned-row"> | |
| diff --git a/rdoc/files/lib/kvlr/reports_as_sparkline/reporting_period_rb.html … | |
| @@ -51,7 +51,7 @@ | |
| <table class="header-table"> | |
| <tr class="top-aligned-row"> | |
| <td><strong>Path:</strong></td> | |
| - <td>lib/kvlr/reports_as_sparkline/reporting_period.rb | |
| + <td>lib/simplabs/reports_as_sparkline/reporting_period.rb | |
| </td> | |
| </tr> | |
| <tr class="top-aligned-row"> | |
| diff --git a/rdoc/files/lib/kvlr/reports_as_sparkline/sparkline_tag_helper_rb.h… | |
| @@ -51,7 +51,7 @@ | |
| <table class="header-table"> | |
| <tr class="top-aligned-row"> | |
| <td><strong>Path:</strong></td> | |
| - <td>lib/kvlr/reports_as_sparkline/sparkline_tag_helper.rb | |
| + <td>lib/simplabs/reports_as_sparkline/sparkline_tag_helper.rb | |
| </td> | |
| </tr> | |
| <tr class="top-aligned-row"> | |
| diff --git a/rdoc/files/lib/kvlr/reports_as_sparkline_rb.html b/rdoc/files/lib/… | |
| @@ -51,7 +51,7 @@ | |
| <table class="header-table"> | |
| <tr class="top-aligned-row"> | |
| <td><strong>Path:</strong></td> | |
| - <td>lib/kvlr/reports_as_sparkline.rb | |
| + <td>lib/simplabs/reports_as_sparkline.rb | |
| </td> | |
| </tr> | |
| <tr class="top-aligned-row"> | |
| diff --git a/rdoc/fr_class_index.html b/rdoc/fr_class_index.html | |
| @@ -20,12 +20,12 @@ | |
| <div id="index"> | |
| <h1 class="section-bar">Classes</h1> | |
| <div id="index-entries"> | |
| - <a href="classes/Kvlr/ReportsAsSparkline/ClassMethods.html">Kvlr::ReportsA… | |
| - <a href="classes/Kvlr/ReportsAsSparkline/CumulatedReport.html">Kvlr::Repor… | |
| - <a href="classes/Kvlr/ReportsAsSparkline/Grouping.html">Kvlr::ReportsAsSpa… | |
| - <a href="classes/Kvlr/ReportsAsSparkline/Report.html">Kvlr::ReportsAsSpark… | |
| - <a href="classes/Kvlr/ReportsAsSparkline/ReportingPeriod.html">Kvlr::Repor… | |
| - <a href="classes/Kvlr/ReportsAsSparkline/SparklineTagHelper.html">Kvlr::Re… | |
| + <a href="classes/Simplabs/ReportsAsSparkline/ClassMethods.html">Simplabs::… | |
| + <a href="classes/Simplabs/ReportsAsSparkline/CumulatedReport.html">Simplab… | |
| + <a href="classes/Simplabs/ReportsAsSparkline/Grouping.html">Simplabs::Repo… | |
| + <a href="classes/Simplabs/ReportsAsSparkline/Report.html">Simplabs::Report… | |
| + <a href="classes/Simplabs/ReportsAsSparkline/ReportingPeriod.html">Simplab… | |
| + <a href="classes/Simplabs/ReportsAsSparkline/SparklineTagHelper.html">Simp… | |
| </div> | |
| </div> | |
| </body> | |
| diff --git a/rdoc/fr_file_index.html b/rdoc/fr_file_index.html | |
| @@ -21,13 +21,13 @@ | |
| <h1 class="section-bar">Files</h1> | |
| <div id="index-entries"> | |
| <a href="files/README_rdoc.html">README.rdoc</a><br /> | |
| - <a href="files/lib/kvlr/reports_as_sparkline_rb.html">lib/kvlr/reports_as_… | |
| - <a href="files/lib/kvlr/reports_as_sparkline/cumulated_report_rb.html">lib… | |
| - <a href="files/lib/kvlr/reports_as_sparkline/grouping_rb.html">lib/kvlr/re… | |
| - <a href="files/lib/kvlr/reports_as_sparkline/report_rb.html">lib/kvlr/repo… | |
| - <a href="files/lib/kvlr/reports_as_sparkline/report_cache_rb.html">lib/kvl… | |
| - <a href="files/lib/kvlr/reports_as_sparkline/reporting_period_rb.html">lib… | |
| - <a href="files/lib/kvlr/reports_as_sparkline/sparkline_tag_helper_rb.html"… | |
| + <a href="files/lib/simplabs/reports_as_sparkline_rb.html">lib/simplabs/rep… | |
| + <a href="files/lib/simplabs/reports_as_sparkline/cumulated_report_rb.html"… | |
| + <a href="files/lib/simplabs/reports_as_sparkline/grouping_rb.html">lib/sim… | |
| + <a href="files/lib/simplabs/reports_as_sparkline/report_rb.html">lib/simpl… | |
| + <a href="files/lib/simplabs/reports_as_sparkline/report_cache_rb.html">lib… | |
| + <a href="files/lib/simplabs/reports_as_sparkline/reporting_period_rb.html"… | |
| + <a href="files/lib/simplabs/reports_as_sparkline/sparkline_tag_helper_rb.h… | |
| </div> | |
| </div> | |
| </body> | |
| diff --git a/rdoc/fr_method_index.html b/rdoc/fr_method_index.html | |
| @@ -20,17 +20,17 @@ | |
| <div id="index"> | |
| <h1 class="section-bar">Methods</h1> | |
| <div id="index-entries"> | |
| - <a href="classes/Kvlr/ReportsAsSparkline/ReportingPeriod.html#M000007">fir… | |
| - <a href="classes/Kvlr/ReportsAsSparkline/Grouping.html#M000005">identifier… | |
| - <a href="classes/Kvlr/ReportsAsSparkline/ReportingPeriod.html#M000006">new… | |
| - <a href="classes/Kvlr/ReportsAsSparkline/Grouping.html#M000004">new (Kvlr:… | |
| - <a href="classes/Kvlr/ReportsAsSparkline/Report.html#M000010">new (Kvlr::R… | |
| - <a href="classes/Kvlr/ReportsAsSparkline/ReportingPeriod.html#M000008">nex… | |
| - <a href="classes/Kvlr/ReportsAsSparkline/ReportingPeriod.html#M000009">pre… | |
| - <a href="classes/Kvlr/ReportsAsSparkline/ClassMethods.html#M000002">report… | |
| - <a href="classes/Kvlr/ReportsAsSparkline/CumulatedReport.html#M000003">run… | |
| - <a href="classes/Kvlr/ReportsAsSparkline/Report.html#M000011">run (Kvlr::R… | |
| - <a href="classes/Kvlr/ReportsAsSparkline/SparklineTagHelper.html#M000001">… | |
| + <a href="classes/Simplabs/ReportsAsSparkline/ReportingPeriod.html#M000007"… | |
| + <a href="classes/Simplabs/ReportsAsSparkline/Grouping.html#M000005">identi… | |
| + <a href="classes/Simplabs/ReportsAsSparkline/ReportingPeriod.html#M000006"… | |
| + <a href="classes/Simplabs/ReportsAsSparkline/Grouping.html#M000004">new (S… | |
| + <a href="classes/Simplabs/ReportsAsSparkline/Report.html#M000010">new (Sim… | |
| + <a href="classes/Simplabs/ReportsAsSparkline/ReportingPeriod.html#M000008"… | |
| + <a href="classes/Simplabs/ReportsAsSparkline/ReportingPeriod.html#M000009"… | |
| + <a href="classes/Simplabs/ReportsAsSparkline/ClassMethods.html#M000002">re… | |
| + <a href="classes/Simplabs/ReportsAsSparkline/CumulatedReport.html#M000003"… | |
| + <a href="classes/Simplabs/ReportsAsSparkline/Report.html#M000011">run (Sim… | |
| + <a href="classes/Simplabs/ReportsAsSparkline/SparklineTagHelper.html#M0000… | |
| </div> | |
| </div> | |
| </body> | |
| diff --git a/spec/classes/cumulated_report_spec.rb b/spec/classes/cumulated_rep… | |
| @@ -1,9 +1,9 @@ | |
| require File.join(File.dirname(__FILE__), '..', 'spec_helper') | |
| -describe Kvlr::ReportsAsSparkline::CumulatedReport do | |
| +describe Simplabs::ReportsAsSparkline::CumulatedReport do | |
| before do | |
| - @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :cumulated_r… | |
| + @report = Simplabs::ReportsAsSparkline::CumulatedReport.new(User, :cumulat… | |
| end | |
| describe '#run' do | |
| @@ -15,13 +15,13 @@ describe Kvlr::ReportsAsSparkline::CumulatedReport do | |
| end | |
| it 'should return an array of the same length as the specified limit when … | |
| - @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :cumulated… | |
| + @report = Simplabs::ReportsAsSparkline::CumulatedReport.new(User, :cumul… | |
| @report.run.length.should == 10 | |
| end | |
| it 'should return an array of the same length as the specified limit + 1 w… | |
| - @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :cumulated… | |
| + @report = Simplabs::ReportsAsSparkline::CumulatedReport.new(User, :cumul… | |
| @report.run.length.should == 11 | |
| end | |
| @@ -35,7 +35,7 @@ describe Kvlr::ReportsAsSparkline::CumulatedReport do | |
| User.create!(:login => 'test 4', :created_at => Time.now - 3.month, :p… | |
| User.create!(:login => 'test 5', :created_at => Time.now - 4.month, :p… | |
| - @report2 = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :cumula… | |
| + @report2 = Simplabs::ReportsAsSparkline::CumulatedReport.new(User, :cu… | |
| :grouping => :month, | |
| :limit => 2 | |
| ) | |
| @@ -76,11 +76,11 @@ describe Kvlr::ReportsAsSparkline::CumulatedReport do | |
| User.create!(:login => 'test 3', :created_at => Time.now - 3.sen… | |
| end | |
| - describe do | |
| + describe 'the returned result' do | |
| before do | |
| - @grouping = Kvlr::ReportsAsSparkline::Grouping.new(grouping) | |
| - @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, … | |
| + @grouping = Simplabs::ReportsAsSparkline::Grouping.new(groupin… | |
| + @report = Simplabs::ReportsAsSparkline::CumulatedReport.new(Us… | |
| :grouping => grouping, | |
| :limit => 10, | |
| :live_data => live_data | |
| @@ -88,24 +88,24 @@ describe Kvlr::ReportsAsSparkline::CumulatedReport do | |
| @result = @report.run | |
| end | |
| - it "should return an array starting reporting period (Time.now -… | |
| - @result.first[0].should == Kvlr::ReportsAsSparkline::Reporting… | |
| + it "should be an array starting reporting period (Time.now - lim… | |
| + @result.first[0].should == Simplabs::ReportsAsSparkline::Repor… | |
| end | |
| if live_data | |
| - it "should return data ending with the current reporting perio… | |
| - @result.last[0].should == Kvlr::ReportsAsSparkline::Reportin… | |
| + it "should be data ending with the current reporting period" do | |
| + @result.last[0].should == Simplabs::ReportsAsSparkline::Repo… | |
| end | |
| else | |
| - it "should return data ending with the reporting period before… | |
| - @result.last[0].should == Kvlr::ReportsAsSparkline::Reportin… | |
| + it "should be data ending with the reporting period before the… | |
| + @result.last[0].should == Simplabs::ReportsAsSparkline::Repo… | |
| end | |
| end | |
| end | |
| it 'should return correct data for aggregation :count' do | |
| - @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :r… | |
| + @report = Simplabs::ReportsAsSparkline::CumulatedReport.new(User… | |
| :aggregation => :count, | |
| :grouping => grouping, | |
| :limit => 10, | |
| @@ -121,7 +121,7 @@ describe Kvlr::ReportsAsSparkline::CumulatedReport do | |
| end | |
| it 'should return correct data for aggregation :sum' do | |
| - @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :r… | |
| + @report = Simplabs::ReportsAsSparkline::CumulatedReport.new(User… | |
| :aggregation => :sum, | |
| :grouping => grouping, | |
| :value_column => :profile_visits, | |
| @@ -138,7 +138,7 @@ describe Kvlr::ReportsAsSparkline::CumulatedReport do | |
| end | |
| it 'should return correct data for aggregation :count when custom … | |
| - @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :r… | |
| + @report = Simplabs::ReportsAsSparkline::CumulatedReport.new(User… | |
| :aggregation => :count, | |
| :grouping => grouping, | |
| :limit => 10, | |
| @@ -154,7 +154,7 @@ describe Kvlr::ReportsAsSparkline::CumulatedReport do | |
| end | |
| it 'should return correct data for aggregation :sum when custom co… | |
| - @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :r… | |
| + @report = Simplabs::ReportsAsSparkline::CumulatedReport.new(User… | |
| :aggregation => :sum, | |
| :grouping => grouping, | |
| :value_column => :profile_visits, | |
| @@ -183,7 +183,7 @@ describe Kvlr::ReportsAsSparkline::CumulatedReport do | |
| end | |
| after(:each) do | |
| - Kvlr::ReportsAsSparkline::ReportCache.destroy_all | |
| + Simplabs::ReportsAsSparkline::ReportCache.destroy_all | |
| end | |
| end | |
| diff --git a/spec/classes/grouping_spec.rb b/spec/classes/grouping_spec.rb | |
| @@ -1,11 +1,11 @@ | |
| require File.join(File.dirname(__FILE__), '..', 'spec_helper') | |
| -describe Kvlr::ReportsAsSparkline::Grouping do | |
| +describe Simplabs::ReportsAsSparkline::Grouping do | |
| describe '#new' do | |
| it 'should raise an error if an unsupported grouping is specified' do | |
| - lambda { Kvlr::ReportsAsSparkline::Grouping.new(:unsupported) }.should r… | |
| + lambda { Simplabs::ReportsAsSparkline::Grouping.new(:unsupported) }.shou… | |
| end | |
| end | |
| @@ -19,19 +19,19 @@ describe Kvlr::ReportsAsSparkline::Grouping do | |
| end | |
| it 'should use DATE_FORMAT with format string "%Y/%m/%d/%H" for grouping… | |
| - Kvlr::ReportsAsSparkline::Grouping.new(:hour).send(:to_sql, 'created_a… | |
| + Simplabs::ReportsAsSparkline::Grouping.new(:hour).send(:to_sql, 'creat… | |
| end | |
| it 'should use DATE_FORMAT with format string "%Y/%m/%d" for grouping :d… | |
| - Kvlr::ReportsAsSparkline::Grouping.new(:day).send(:to_sql, 'created_at… | |
| + Simplabs::ReportsAsSparkline::Grouping.new(:day).send(:to_sql, 'create… | |
| end | |
| it 'should use YEARWEEK with mode 3 for grouping :week' do | |
| - Kvlr::ReportsAsSparkline::Grouping.new(:week).send(:to_sql, 'created_a… | |
| + Simplabs::ReportsAsSparkline::Grouping.new(:week).send(:to_sql, 'creat… | |
| end | |
| it 'should use DATE_FORMAT with format string "%Y/%m" for grouping :mont… | |
| - Kvlr::ReportsAsSparkline::Grouping.new(:month).send(:to_sql, 'created_… | |
| + Simplabs::ReportsAsSparkline::Grouping.new(:month).send(:to_sql, 'crea… | |
| end | |
| end | |
| @@ -45,7 +45,7 @@ describe Kvlr::ReportsAsSparkline::Grouping do | |
| for grouping in [:hour, :day, :week, :month] do | |
| it "should use date_trunc with truncation identifier \"#{grouping.to_s… | |
| - Kvlr::ReportsAsSparkline::Grouping.new(grouping).send(:to_sql, 'crea… | |
| + Simplabs::ReportsAsSparkline::Grouping.new(grouping).send(:to_sql, '… | |
| end | |
| end | |
| @@ -59,19 +59,19 @@ describe Kvlr::ReportsAsSparkline::Grouping do | |
| end | |
| it 'should use strftime with format string "%Y/%m/%d/%H" for grouping :h… | |
| - Kvlr::ReportsAsSparkline::Grouping.new(:hour).send(:to_sql, 'created_a… | |
| + Simplabs::ReportsAsSparkline::Grouping.new(:hour).send(:to_sql, 'creat… | |
| end | |
| it 'should use strftime with format string "%Y/%m/%d" for grouping :day'… | |
| - Kvlr::ReportsAsSparkline::Grouping.new(:day).send(:to_sql, 'created_at… | |
| + Simplabs::ReportsAsSparkline::Grouping.new(:day).send(:to_sql, 'create… | |
| end | |
| it 'should use date with mode "weekday 0" for grouping :week' do | |
| - Kvlr::ReportsAsSparkline::Grouping.new(:week).send(:to_sql, 'created_a… | |
| + Simplabs::ReportsAsSparkline::Grouping.new(:week).send(:to_sql, 'creat… | |
| end | |
| it 'should use strftime with format string "%Y/%m" for grouping :month' … | |
| - Kvlr::ReportsAsSparkline::Grouping.new(:month).send(:to_sql, 'created_… | |
| + Simplabs::ReportsAsSparkline::Grouping.new(:month).send(:to_sql, 'crea… | |
| end | |
| end | |
| @@ -89,7 +89,7 @@ describe Kvlr::ReportsAsSparkline::Grouping do | |
| for grouping in [[:hour, '2008/12/31/12'], [:day, '2008/12/31'], [:month… | |
| it "should split the string with '/' for grouping :#{grouping[0].to_s}… | |
| - Kvlr::ReportsAsSparkline::Grouping.new(grouping[0]).date_parts_from_… | |
| + Simplabs::ReportsAsSparkline::Grouping.new(grouping[0]).date_parts_f… | |
| end | |
| end | |
| @@ -98,7 +98,7 @@ describe Kvlr::ReportsAsSparkline::Grouping do | |
| db_string = '2008-2-1' | |
| expected = [2008, 5] | |
| - Kvlr::ReportsAsSparkline::Grouping.new(:week).date_parts_from_db_strin… | |
| + Simplabs::ReportsAsSparkline::Grouping.new(:week).date_parts_from_db_s… | |
| end | |
| end | |
| @@ -110,19 +110,19 @@ describe Kvlr::ReportsAsSparkline::Grouping do | |
| end | |
| it 'should split the date part of the string with "-" and read out the h… | |
| - Kvlr::ReportsAsSparkline::Grouping.new(:hour).date_parts_from_db_strin… | |
| + Simplabs::ReportsAsSparkline::Grouping.new(:hour).date_parts_from_db_s… | |
| end | |
| it 'should split the date part of the string with "-" for grouping :day'… | |
| - Kvlr::ReportsAsSparkline::Grouping.new(:day).date_parts_from_db_string… | |
| + Simplabs::ReportsAsSparkline::Grouping.new(:day).date_parts_from_db_st… | |
| end | |
| it 'should split the date part of the string with "-" and calculate the … | |
| - Kvlr::ReportsAsSparkline::Grouping.new(:week).date_parts_from_db_strin… | |
| + Simplabs::ReportsAsSparkline::Grouping.new(:week).date_parts_from_db_s… | |
| end | |
| it 'should split the date part of the string with "-" and return year an… | |
| - Kvlr::ReportsAsSparkline::Grouping.new(:month).date_parts_from_db_stri… | |
| + Simplabs::ReportsAsSparkline::Grouping.new(:month).date_parts_from_db_… | |
| end | |
| end | |
| @@ -136,7 +136,7 @@ describe Kvlr::ReportsAsSparkline::Grouping do | |
| for grouping in [[:hour, '2008/12/31/12'], [:day, '2008/12/31'], [:month… | |
| it "should split the string with '/' for grouping :#{grouping[0].to_s}… | |
| - Kvlr::ReportsAsSparkline::Grouping.new(grouping[0]).date_parts_from_… | |
| + Simplabs::ReportsAsSparkline::Grouping.new(grouping[0]).date_parts_f… | |
| end | |
| end | |
| @@ -145,7 +145,7 @@ describe Kvlr::ReportsAsSparkline::Grouping do | |
| db_string = '200852' | |
| expected = [2008, 52] | |
| - Kvlr::ReportsAsSparkline::Grouping.new(:week).date_parts_from_db_strin… | |
| + Simplabs::ReportsAsSparkline::Grouping.new(:week).date_parts_from_db_s… | |
| end | |
| end | |
| diff --git a/spec/classes/report_cache_spec.rb b/spec/classes/report_cache_spec… | |
| @@ -1,28 +1,28 @@ | |
| require File.join(File.dirname(__FILE__), '..', 'spec_helper') | |
| -describe Kvlr::ReportsAsSparkline::ReportCache do | |
| +describe Simplabs::ReportsAsSparkline::ReportCache do | |
| before do | |
| - @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations, :limi… | |
| + @report = Simplabs::ReportsAsSparkline::Report.new(User, :registrations, :… | |
| end | |
| describe '.process' do | |
| before do | |
| - Kvlr::ReportsAsSparkline::ReportCache.stub!(:find).and_return([]) | |
| - Kvlr::ReportsAsSparkline::ReportCache.stub!(:prepare_result).and_return(… | |
| + Simplabs::ReportsAsSparkline::ReportCache.stub!(:find).and_return([]) | |
| + Simplabs::ReportsAsSparkline::ReportCache.stub!(:prepare_result).and_ret… | |
| end | |
| it 'should raise an ArgumentError if no block is given' do | |
| lambda do | |
| - Kvlr::ReportsAsSparkline::ReportCache.process(@report, @report.options) | |
| + Simplabs::ReportsAsSparkline::ReportCache.process(@report, @report.opt… | |
| end.should raise_error(ArgumentError) | |
| end | |
| it 'sould start a transaction' do | |
| - Kvlr::ReportsAsSparkline::ReportCache.should_receive(:transaction) | |
| + Simplabs::ReportsAsSparkline::ReportCache.should_receive(:transaction) | |
| - Kvlr::ReportsAsSparkline::ReportCache.process(@report, @report.options) … | |
| + Simplabs::ReportsAsSparkline::ReportCache.process(@report, @report.optio… | |
| end | |
| describe 'with :live_data = true' do | |
| @@ -33,22 +33,22 @@ describe Kvlr::ReportsAsSparkline::ReportCache do | |
| it 'should yield to the given block' do | |
| lambda { | |
| - Kvlr::ReportsAsSparkline::ReportCache.process(@report, @options) { r… | |
| + Simplabs::ReportsAsSparkline::ReportCache.process(@report, @options)… | |
| }.should raise_error(YieldMatchException) | |
| end | |
| it 'should yield the reporting period after the last one in the cache, a… | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new( | |
| + reporting_period = Simplabs::ReportsAsSparkline::ReportingPeriod.new( | |
| @report.options[:grouping], | |
| Time.now - 3.send(@report.options[:grouping].identifier) | |
| ) | |
| - cached = Kvlr::ReportsAsSparkline::ReportCache.new | |
| + cached = Simplabs::ReportsAsSparkline::ReportCache.new | |
| cached.stub!(:reporting_period).and_return(reporting_period.date_time) | |
| - Kvlr::ReportsAsSparkline::ReportCache.stub!(:find).and_return([cached]) | |
| + Simplabs::ReportsAsSparkline::ReportCache.stub!(:find).and_return([cac… | |
| expected_dates = [[reporting_period.next.date_time, nil], [reporting_p… | |
| yield_count = 0 | |
| - Kvlr::ReportsAsSparkline::ReportCache.process(@report, @options) do |b… | |
| + Simplabs::ReportsAsSparkline::ReportCache.process(@report, @options) d… | |
| [begin_at, end_at].should == expected_dates[yield_count] | |
| yield_count += 1 | |
| [] | |
| @@ -62,32 +62,32 @@ describe Kvlr::ReportsAsSparkline::ReportCache do | |
| describe 'with :live_data = false' do | |
| it 'should not yield to the block if data for the reporting period befor… | |
| - cached = Kvlr::ReportsAsSparkline::ReportCache.new | |
| - cached.stub!(:reporting_period).and_return(Kvlr::ReportsAsSparkline::R… | |
| - Kvlr::ReportsAsSparkline::ReportCache.stub!(:find).and_return([cached]) | |
| + cached = Simplabs::ReportsAsSparkline::ReportCache.new | |
| + cached.stub!(:reporting_period).and_return(Simplabs::ReportsAsSparklin… | |
| + Simplabs::ReportsAsSparkline::ReportCache.stub!(:find).and_return([cac… | |
| lambda { | |
| - Kvlr::ReportsAsSparkline::ReportCache.process(@report, @report.optio… | |
| + Simplabs::ReportsAsSparkline::ReportCache.process(@report, @report.o… | |
| }.should_not raise_error(YieldMatchException) | |
| end | |
| it 'should yield to the block if no data for the reporting period before… | |
| lambda { | |
| - Kvlr::ReportsAsSparkline::ReportCache.process(@report, @report.optio… | |
| + Simplabs::ReportsAsSparkline::ReportCache.process(@report, @report.o… | |
| }.should raise_error(YieldMatchException) | |
| end | |
| it 'should yield the reporting period after the last one in the cache, a… | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new( | |
| + reporting_period = Simplabs::ReportsAsSparkline::ReportingPeriod.new( | |
| @report.options[:grouping], | |
| Time.now - 3.send(@report.options[:grouping].identifier) | |
| ) | |
| - cached = Kvlr::ReportsAsSparkline::ReportCache.new | |
| + cached = Simplabs::ReportsAsSparkline::ReportCache.new | |
| cached.stub!(:reporting_period).and_return(reporting_period.date_time) | |
| - Kvlr::ReportsAsSparkline::ReportCache.stub!(:find).and_return([cached]) | |
| + Simplabs::ReportsAsSparkline::ReportCache.stub!(:find).and_return([cac… | |
| expected_dates = [[reporting_period.next.date_time, nil], [reporting_p… | |
| yield_count = 0 | |
| - Kvlr::ReportsAsSparkline::ReportCache.process(@report, @report.options… | |
| + Simplabs::ReportsAsSparkline::ReportCache.process(@report, @report.opt… | |
| [begin_at, end_at].should == expected_dates[yield_count] | |
| yield_count += 1 | |
| [] | |
| @@ -99,7 +99,7 @@ describe Kvlr::ReportsAsSparkline::ReportCache do | |
| end | |
| it 'should read existing data from the cache' do | |
| - Kvlr::ReportsAsSparkline::ReportCache.should_receive(:find).once.with( | |
| + Simplabs::ReportsAsSparkline::ReportCache.should_receive(:find).once.wit… | |
| :all, | |
| :conditions => [ | |
| 'model_name = ? AND report_name = ? AND grouping = ? AND aggregation… | |
| @@ -107,18 +107,18 @@ describe Kvlr::ReportsAsSparkline::ReportCache do | |
| @report.name.to_s, | |
| @report.options[:grouping].identifier.to_s, | |
| @report.aggregation.to_s, | |
| - Kvlr::ReportsAsSparkline::ReportingPeriod.first(@report.options[:gro… | |
| + Simplabs::ReportsAsSparkline::ReportingPeriod.first(@report.options[… | |
| ], | |
| :limit => 10, | |
| :order => 'reporting_period ASC' | |
| ) | |
| - Kvlr::ReportsAsSparkline::ReportCache.process(@report, @report.options) … | |
| + Simplabs::ReportsAsSparkline::ReportCache.process(@report, @report.optio… | |
| end | |
| it 'should utilize the end_date in the conditions' do | |
| end_date = Time.now | |
| - Kvlr::ReportsAsSparkline::ReportCache.should_receive(:find).once.with( | |
| + Simplabs::ReportsAsSparkline::ReportCache.should_receive(:find).once.wit… | |
| :all, | |
| :conditions => [ | |
| 'model_name = ? AND report_name = ? AND grouping = ? AND aggregation… | |
| @@ -126,19 +126,19 @@ describe Kvlr::ReportsAsSparkline::ReportCache do | |
| @report.name.to_s, | |
| @report.options[:grouping].identifier.to_s, | |
| @report.aggregation.to_s, | |
| - Kvlr::ReportsAsSparkline::ReportingPeriod.first(@report.options[:gro… | |
| - Kvlr::ReportsAsSparkline::ReportingPeriod.new(@report.options[:group… | |
| + Simplabs::ReportsAsSparkline::ReportingPeriod.first(@report.options[… | |
| + Simplabs::ReportsAsSparkline::ReportingPeriod.new(@report.options[:g… | |
| ], | |
| :limit => 10, | |
| :order => 'reporting_period ASC' | |
| ) | |
| - Kvlr::ReportsAsSparkline::ReportCache.process(@report, @report.options.m… | |
| + Simplabs::ReportsAsSparkline::ReportCache.process(@report, @report.optio… | |
| end | |
| it "should read existing data from the cache for the correct grouping if o… | |
| - grouping = Kvlr::ReportsAsSparkline::Grouping.new(:month) | |
| - Kvlr::ReportsAsSparkline::ReportCache.should_receive(:find).once.with( | |
| + grouping = Simplabs::ReportsAsSparkline::Grouping.new(:month) | |
| + Simplabs::ReportsAsSparkline::ReportCache.should_receive(:find).once.wit… | |
| :all, | |
| :conditions => [ | |
| 'model_name = ? AND report_name = ? AND grouping = ? AND aggregation… | |
| @@ -146,28 +146,28 @@ describe Kvlr::ReportsAsSparkline::ReportCache do | |
| @report.name.to_s, | |
| grouping.identifier.to_s, | |
| @report.aggregation.to_s, | |
| - Kvlr::ReportsAsSparkline::ReportingPeriod.first(grouping, 10).date_t… | |
| + Simplabs::ReportsAsSparkline::ReportingPeriod.first(grouping, 10).da… | |
| ], | |
| :limit => 10, | |
| :order => 'reporting_period ASC' | |
| ) | |
| - Kvlr::ReportsAsSparkline::ReportCache.process(@report, { :limit => 10, :… | |
| + Simplabs::ReportsAsSparkline::ReportCache.process(@report, { :limit => 1… | |
| end | |
| it 'should prepare the results before it returns them' do | |
| new_after_cache_data = [] | |
| new_before_cache_data = [] | |
| cached_data = [] | |
| - Kvlr::ReportsAsSparkline::ReportCache.stub!(:find).and_return(cached_dat… | |
| - Kvlr::ReportsAsSparkline::ReportCache.should_receive(:prepare_result).on… | |
| + Simplabs::ReportsAsSparkline::ReportCache.stub!(:find).and_return(cached… | |
| + Simplabs::ReportsAsSparkline::ReportCache.should_receive(:prepare_result… | |
| - Kvlr::ReportsAsSparkline::ReportCache.process(@report, @report.options) … | |
| + Simplabs::ReportsAsSparkline::ReportCache.process(@report, @report.optio… | |
| end | |
| it 'should yield the first reporting period if the cache is empty' do | |
| - Kvlr::ReportsAsSparkline::ReportCache.process(@report, @report.options) … | |
| - begin_at.should == Kvlr::ReportsAsSparkline::ReportingPeriod.first(@re… | |
| + Simplabs::ReportsAsSparkline::ReportCache.process(@report, @report.optio… | |
| + begin_at.should == Simplabs::ReportsAsSparkline::ReportingPeriod.first… | |
| end_at.should == nil | |
| [] | |
| end | |
| @@ -176,14 +176,14 @@ describe Kvlr::ReportsAsSparkline::ReportCache do | |
| describe 'with cache = false' do | |
| it 'should not read any data from cache' do | |
| - Kvlr::ReportsAsSparkline::ReportCache.should_not_receive(:find) | |
| + Simplabs::ReportsAsSparkline::ReportCache.should_not_receive(:find) | |
| - Kvlr::ReportsAsSparkline::ReportCache.process(@report, @report.options… | |
| + Simplabs::ReportsAsSparkline::ReportCache.process(@report, @report.opt… | |
| end | |
| it 'should yield the first reporting period' do | |
| - Kvlr::ReportsAsSparkline::ReportCache.process(@report, @report.options… | |
| - begin_at.should == Kvlr::ReportsAsSparkline::ReportingPeriod.first(@… | |
| + Simplabs::ReportsAsSparkline::ReportCache.process(@report, @report.opt… | |
| + begin_at.should == Simplabs::ReportsAsSparkline::ReportingPeriod.fir… | |
| end_at.should == nil | |
| [] | |
| end | |
| @@ -196,56 +196,56 @@ describe Kvlr::ReportsAsSparkline::ReportCache do | |
| describe '.prepare_result' do | |
| before do | |
| - @current_reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.ne… | |
| + @current_reporting_period = Simplabs::ReportsAsSparkline::ReportingPerio… | |
| @new_after_cache_data = [[@current_reporting_period.previous.date_time, … | |
| - Kvlr::ReportsAsSparkline::ReportingPeriod.stub!(:from_db_string).and_ret… | |
| - @cached = Kvlr::ReportsAsSparkline::ReportCache.new | |
| + Simplabs::ReportsAsSparkline::ReportingPeriod.stub!(:from_db_string).and… | |
| + @cached = Simplabs::ReportsAsSparkline::ReportCache.new | |
| @cached.stub!(:save!) | |
| - Kvlr::ReportsAsSparkline::ReportCache.stub!(:build_cached_data).and_retu… | |
| + Simplabs::ReportsAsSparkline::ReportCache.stub!(:build_cached_data).and_… | |
| end | |
| it 'should convert the date strings from the newly read data to reporting … | |
| - Kvlr::ReportsAsSparkline::ReportingPeriod.should_receive(:from_db_string… | |
| + Simplabs::ReportsAsSparkline::ReportingPeriod.should_receive(:from_db_st… | |
| - Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, [], @new_aft… | |
| + Simplabs::ReportsAsSparkline::ReportCache.send(:prepare_result, [], @new… | |
| end | |
| - it 'should create :limit instances of Kvlr::ReportsAsSparkline::ReportCach… | |
| - Kvlr::ReportsAsSparkline::ReportCache.should_receive(:build_cached_data)… | |
| + it 'should create :limit instances of Simplabs::ReportsAsSparkline::Report… | |
| + Simplabs::ReportsAsSparkline::ReportCache.should_receive(:build_cached_d… | |
| @report, | |
| @report.options[:grouping], | |
| anything(), | |
| 0.0 | |
| ).and_return(@cached) | |
| - Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, [], [], [], … | |
| + Simplabs::ReportsAsSparkline::ReportCache.send(:prepare_result, [], [], … | |
| end | |
| - it 'should create a new Kvlr::ReportsAsSparkline::ReportCache with the cor… | |
| - Kvlr::ReportsAsSparkline::ReportCache.should_receive(:build_cached_data)… | |
| + it 'should create a new Simplabs::ReportsAsSparkline::ReportCache with the… | |
| + Simplabs::ReportsAsSparkline::ReportCache.should_receive(:build_cached_d… | |
| @report, | |
| @report.options[:grouping], | |
| anything(), | |
| 0.0 | |
| ).and_return(@cached) | |
| - Kvlr::ReportsAsSparkline::ReportCache.should_receive(:build_cached_data)… | |
| + Simplabs::ReportsAsSparkline::ReportCache.should_receive(:build_cached_d… | |
| @report, | |
| @report.options[:grouping], | |
| @current_reporting_period.previous, | |
| 1.0 | |
| ).and_return(@cached) | |
| - Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, [], @new_aft… | |
| + Simplabs::ReportsAsSparkline::ReportCache.send(:prepare_result, [], @new… | |
| end | |
| - it 'should save the created Kvlr::ReportsAsSparkline::ReportCache' do | |
| + it 'should save the created Simplabs::ReportsAsSparkline::ReportCache' do | |
| @cached.should_receive(:save!).once | |
| - Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, [], @new_aft… | |
| + Simplabs::ReportsAsSparkline::ReportCache.send(:prepare_result, [], @new… | |
| end | |
| it 'should return an array of arrays of Dates and Floats' do | |
| - result = Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, [],… | |
| + result = Simplabs::ReportsAsSparkline::ReportCache.send(:prepare_result,… | |
| result.should be_kind_of(Array) | |
| result[0].should be_kind_of(Array) | |
| @@ -256,7 +256,7 @@ describe Kvlr::ReportsAsSparkline::ReportCache do | |
| describe 'with :live_data = false' do | |
| before do | |
| - @result = Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, … | |
| + @result = Simplabs::ReportsAsSparkline::ReportCache.send(:prepare_resu… | |
| end | |
| it 'should return an array of length :limit' do | |
| @@ -273,7 +273,7 @@ describe Kvlr::ReportsAsSparkline::ReportCache do | |
| before do | |
| options = @report.options.merge(:live_data => true) | |
| - @result = Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, … | |
| + @result = Simplabs::ReportsAsSparkline::ReportCache.send(:prepare_resu… | |
| end | |
| it 'should return an array of length (:limit + 1)' do | |
| @@ -288,10 +288,10 @@ describe Kvlr::ReportsAsSparkline::ReportCache do | |
| describe 'with cache = false' do | |
| - it 'should not save the created Kvlr::ReportsAsSparkline::ReportCache' do | |
| + it 'should not save the created Simplabs::ReportsAsSparkline::ReportCach… | |
| @cached.should_not_receive(:save!) | |
| - Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, [], @new_a… | |
| + Simplabs::ReportsAsSparkline::ReportCache.send(:prepare_result, [], @n… | |
| end | |
| end | |
| @@ -301,15 +301,15 @@ describe Kvlr::ReportsAsSparkline::ReportCache do | |
| describe '.find_value' do | |
| before do | |
| - @data = [[Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::ReportsAsS… | |
| + @data = [[Simplabs::ReportsAsSparkline::ReportingPeriod.new(Simplabs::Re… | |
| end | |
| it 'should return the correct value when new data has been read for the re… | |
| - Kvlr::ReportsAsSparkline::ReportCache.send(:find_value, @data, @data[0][… | |
| + Simplabs::ReportsAsSparkline::ReportCache.send(:find_value, @data, @data… | |
| end | |
| it 'should return 0.0 when no data has been read for the reporting period'… | |
| - Kvlr::ReportsAsSparkline::ReportCache.send(:find_value, @data, @data[0][… | |
| + Simplabs::ReportsAsSparkline::ReportCache.send(:find_value, @data, @data… | |
| end | |
| end | |
| diff --git a/spec/classes/report_spec.rb b/spec/classes/report_spec.rb | |
| @@ -1,11 +1,11 @@ | |
| require File.join(File.dirname(__FILE__), '..', 'spec_helper') | |
| -describe Kvlr::ReportsAsSparkline::Report do | |
| +describe Simplabs::ReportsAsSparkline::Report do | |
| before do | |
| @now = DateTime.now | |
| DateTime.stub!(:now).and_return(@now) | |
| - @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations) | |
| + @report = Simplabs::ReportsAsSparkline::Report.new(User, :registrations) | |
| end | |
| describe '#options' do | |
| @@ -19,9 +19,9 @@ describe Kvlr::ReportsAsSparkline::Report do | |
| describe '#run' do | |
| it 'should process the data with the report cache' do | |
| - Kvlr::ReportsAsSparkline::ReportCache.should_receive(:process).once.with( | |
| + Simplabs::ReportsAsSparkline::ReportCache.should_receive(:process).once.… | |
| @report, | |
| - { :limit => 100, :grouping => @report.options[:grouping], :conditions … | |
| + { :limit => 100, :grouping => @report.options[:grouping], :conditions … | |
| true | |
| ) | |
| @@ -29,9 +29,9 @@ describe Kvlr::ReportsAsSparkline::Report do | |
| end | |
| it 'should process the data with the report cache and specify cache = fals… | |
| - Kvlr::ReportsAsSparkline::ReportCache.should_receive(:process).once.with( | |
| + Simplabs::ReportsAsSparkline::ReportCache.should_receive(:process).once.… | |
| @report, | |
| - { :limit => 100, :grouping => @report.options[:grouping], :conditions … | |
| + { :limit => 100, :grouping => @report.options[:grouping], :conditions … | |
| false | |
| ) | |
| @@ -45,11 +45,11 @@ describe Kvlr::ReportsAsSparkline::Report do | |
| end | |
| it 'should use a custom grouping if one is specified' do | |
| - grouping = Kvlr::ReportsAsSparkline::Grouping.new(:month) | |
| - Kvlr::ReportsAsSparkline::Grouping.should_receive(:new).once.with(:month… | |
| - Kvlr::ReportsAsSparkline::ReportCache.should_receive(:process).once.with( | |
| + grouping = Simplabs::ReportsAsSparkline::Grouping.new(:month) | |
| + Simplabs::ReportsAsSparkline::Grouping.should_receive(:new).once.with(:m… | |
| + Simplabs::ReportsAsSparkline::ReportCache.should_receive(:process).once.… | |
| @report, | |
| - { :limit => 100, :grouping => grouping, :conditions => [], :live_data … | |
| + { :limit => 100, :grouping => grouping, :conditions => [], :live_data … | |
| true | |
| ) | |
| @@ -57,13 +57,13 @@ describe Kvlr::ReportsAsSparkline::Report do | |
| end | |
| it 'should return an array of the same length as the specified limit when … | |
| - @report = Kvlr::ReportsAsSparkline::Report.new(User, :cumulated_registra… | |
| + @report = Simplabs::ReportsAsSparkline::Report.new(User, :cumulated_regi… | |
| @report.run.length.should == 10 | |
| end | |
| it 'should return an array of the same length as the specified limit + 1 w… | |
| - @report = Kvlr::ReportsAsSparkline::Report.new(User, :cumulated_registra… | |
| + @report = Simplabs::ReportsAsSparkline::Report.new(User, :cumulated_regi… | |
| @report.run.length.should == 11 | |
| end | |
| @@ -75,7 +75,7 @@ describe Kvlr::ReportsAsSparkline::Report do | |
| User.create!(:login => 'test 3', :created_at => Time.now - 3.month, :p… | |
| User.create!(:login => 'test 4', :created_at => Time.now - 3.month, :p… | |
| - @report2 = Kvlr::ReportsAsSparkline::Report.new(User, :registrations, | |
| + @report2 = Simplabs::ReportsAsSparkline::Report.new(User, :registratio… | |
| :grouping => :month, | |
| :limit => 2 | |
| ) | |
| @@ -126,11 +126,11 @@ describe Kvlr::ReportsAsSparkline::Report do | |
| User.create!(:login => 'test 4', :created_at => Time.now - 3.sen… | |
| end | |
| - describe do | |
| + describe 'the returned result' do | |
| before do | |
| - @grouping = Kvlr::ReportsAsSparkline::Grouping.new(grouping) | |
| - @report = Kvlr::ReportsAsSparkline::Report.new(User, :registra… | |
| + @grouping = Simplabs::ReportsAsSparkline::Grouping.new(groupin… | |
| + @report = Simplabs::ReportsAsSparkline::Report.new(User, :regi… | |
| :grouping => grouping, | |
| :limit => 10, | |
| :live_data => live_data | |
| @@ -138,24 +138,24 @@ describe Kvlr::ReportsAsSparkline::Report do | |
| @result = @report.run | |
| end | |
| - it "should return an array starting reporting period (Time.now -… | |
| - @result.first[0].should == Kvlr::ReportsAsSparkline::Reporting… | |
| + it "should be an array starting reporting period (Time.now - lim… | |
| + @result.first[0].should == Simplabs::ReportsAsSparkline::Repor… | |
| end | |
| if live_data | |
| - it "should return data ending with the current reporting perio… | |
| - @result.last[0].should == Kvlr::ReportsAsSparkline::Reportin… | |
| + it "should be data ending with the current reporting period" do | |
| + @result.last[0].should == Simplabs::ReportsAsSparkline::Repo… | |
| end | |
| else | |
| - it "should return data ending with the reporting period before… | |
| - @result.last[0].should == Kvlr::ReportsAsSparkline::Reportin… | |
| + it "should be data ending with the reporting period before the… | |
| + @result.last[0].should == Simplabs::ReportsAsSparkline::Repo… | |
| end | |
| end | |
| end | |
| it 'should return correct data for aggregation :count' do | |
| - @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrati… | |
| + @report = Simplabs::ReportsAsSparkline::Report.new(User, :regist… | |
| :aggregation => :count, | |
| :grouping => grouping, | |
| :limit => 10, | |
| @@ -171,7 +171,7 @@ describe Kvlr::ReportsAsSparkline::Report do | |
| end | |
| it 'should return correct data for aggregation :sum' do | |
| - @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrati… | |
| + @report = Simplabs::ReportsAsSparkline::Report.new(User, :regist… | |
| :aggregation => :sum, | |
| :grouping => grouping, | |
| :value_column => :profile_visits, | |
| @@ -188,7 +188,7 @@ describe Kvlr::ReportsAsSparkline::Report do | |
| end | |
| it 'should return correct data for aggregation :maximum' do | |
| - @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrati… | |
| + @report = Simplabs::ReportsAsSparkline::Report.new(User, :regist… | |
| :aggregation => :maximum, | |
| :grouping => grouping, | |
| :value_column => :profile_visits, | |
| @@ -205,7 +205,7 @@ describe Kvlr::ReportsAsSparkline::Report do | |
| end | |
| it 'should return correct data for aggregation :minimum' do | |
| - @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrati… | |
| + @report = Simplabs::ReportsAsSparkline::Report.new(User, :regist… | |
| :aggregation => :minimum, | |
| :grouping => grouping, | |
| :value_column => :profile_visits, | |
| @@ -222,7 +222,7 @@ describe Kvlr::ReportsAsSparkline::Report do | |
| end | |
| it 'should return correct data for aggregation :average' do | |
| - @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrati… | |
| + @report = Simplabs::ReportsAsSparkline::Report.new(User, :regist… | |
| :aggregation => :average, | |
| :grouping => grouping, | |
| :value_column => :profile_visits, | |
| @@ -239,7 +239,7 @@ describe Kvlr::ReportsAsSparkline::Report do | |
| end | |
| it 'should return correct data for aggregation :count when custom … | |
| - @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrati… | |
| + @report = Simplabs::ReportsAsSparkline::Report.new(User, :regist… | |
| :aggregation => :count, | |
| :grouping => grouping, | |
| :limit => 10, | |
| @@ -255,7 +255,7 @@ describe Kvlr::ReportsAsSparkline::Report do | |
| end | |
| it 'should return correct data for aggregation :sum when custom co… | |
| - @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrati… | |
| + @report = Simplabs::ReportsAsSparkline::Report.new(User, :regist… | |
| :aggregation => :sum, | |
| :grouping => grouping, | |
| :value_column => :profile_visits, | |
| @@ -298,7 +298,7 @@ describe Kvlr::ReportsAsSparkline::Report do | |
| end | |
| it 'should return correct data for aggregation :count' do | |
| - @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations, | |
| + @report = Simplabs::ReportsAsSparkline::Report.new(User, :registrati… | |
| :aggregation => :count, | |
| :grouping => :week, | |
| :limit => 10 | |
| @@ -327,7 +327,7 @@ describe Kvlr::ReportsAsSparkline::Report do | |
| end | |
| it 'should return correct data for aggregation :count' do | |
| - @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations, | |
| + @report = Simplabs::ReportsAsSparkline::Report.new(User, :registrati… | |
| :aggregation => :count, | |
| :grouping => :week, | |
| :limit => 10 | |
| @@ -346,7 +346,7 @@ describe Kvlr::ReportsAsSparkline::Report do | |
| end | |
| after do | |
| - Kvlr::ReportsAsSparkline::ReportCache.destroy_all | |
| + Simplabs::ReportsAsSparkline::ReportCache.destroy_all | |
| end | |
| after(:all) do | |
| @@ -358,7 +358,7 @@ describe Kvlr::ReportsAsSparkline::Report do | |
| describe '#read_data' do | |
| it 'should invoke the aggregation method on the model' do | |
| - @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations, :ag… | |
| + @report = Simplabs::ReportsAsSparkline::Report.new(User, :registrations,… | |
| User.should_receive(:count).once.and_return([]) | |
| @report.send(:read_data, Time.now, 5.days.from_now, { :grouping => @repo… | |
| diff --git a/spec/classes/reporting_period_spec.rb b/spec/classes/reporting_per… | |
| @@ -1,19 +1,19 @@ | |
| require File.join(File.dirname(__FILE__), '..', 'spec_helper') | |
| -describe Kvlr::ReportsAsSparkline::ReportingPeriod do | |
| +describe Simplabs::ReportsAsSparkline::ReportingPeriod do | |
| describe '#date_time' do | |
| it 'should return the date and time with minutes = seconds = 0 for groupin… | |
| date_time = DateTime.now | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R… | |
| + reporting_period = Simplabs::ReportsAsSparkline::ReportingPeriod.new(Sim… | |
| reporting_period.date_time.should == DateTime.new(date_time.year, date_t… | |
| end | |
| it 'should return the date part only for grouping :day' do | |
| date_time = DateTime.now | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R… | |
| + reporting_period = Simplabs::ReportsAsSparkline::ReportingPeriod.new(Sim… | |
| reporting_period.date_time.should == date_time.to_date | |
| end | |
| @@ -22,28 +22,28 @@ describe Kvlr::ReportsAsSparkline::ReportingPeriod do | |
| it 'should return the date of the monday of the week date_time is in for… | |
| date_time = DateTime.new(2008, 11, 27) | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr:… | |
| + reporting_period = Simplabs::ReportsAsSparkline::ReportingPeriod.new(S… | |
| reporting_period.date_time.should == Date.new(date_time.year, date_tim… | |
| end | |
| it 'should return the date of the monday of the week date_time is in whe… | |
| date_time = DateTime.new(2008, 11, 24) #this is a monday already, shou… | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr:… | |
| + reporting_period = Simplabs::ReportsAsSparkline::ReportingPeriod.new(S… | |
| reporting_period.date_time.should == Date.new(date_time.year, date_tim… | |
| end | |
| it 'should return the date of the monday of the week date_time is in whe… | |
| date_time = DateTime.new(2008, 11, 1) #this is a saturday | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr:… | |
| + reporting_period = Simplabs::ReportsAsSparkline::ReportingPeriod.new(S… | |
| reporting_period.date_time.should == Date.new(2008, 10, 27) # expect t… | |
| end | |
| it 'should return the date of the monday of the week date_time is in whe… | |
| date_time = DateTime.new(2009, 1, 1) #this is a thursday | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr:… | |
| + reporting_period = Simplabs::ReportsAsSparkline::ReportingPeriod.new(S… | |
| reporting_period.date_time.should == Date.new(2008, 12, 29) # expect t… | |
| end | |
| @@ -52,7 +52,7 @@ describe Kvlr::ReportsAsSparkline::ReportingPeriod do | |
| it 'should return the date with day = 1 for grouping :month' do | |
| date_time = Time.now | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R… | |
| + reporting_period = Simplabs::ReportsAsSparkline::ReportingPeriod.new(Sim… | |
| reporting_period.date_time.should == Date.new(date_time.year, date_time.… | |
| end | |
| @@ -62,31 +62,31 @@ describe Kvlr::ReportsAsSparkline::ReportingPeriod do | |
| describe '.from_db_string' do | |
| it 'should return a reporting period with the correct date and time and wi… | |
| - grouping = Kvlr::ReportsAsSparkline::Grouping.new(:hour) | |
| + grouping = Simplabs::ReportsAsSparkline::Grouping.new(:hour) | |
| grouping.stub!(:date_parts_from_db_string).and_return([2008, 1, 1, 12]) | |
| - Kvlr::ReportsAsSparkline::ReportingPeriod.from_db_string(grouping, '').d… | |
| + Simplabs::ReportsAsSparkline::ReportingPeriod.from_db_string(grouping, '… | |
| end | |
| it 'should return a reporting period with the date part only for grouping … | |
| - grouping = Kvlr::ReportsAsSparkline::Grouping.new(:day) | |
| + grouping = Simplabs::ReportsAsSparkline::Grouping.new(:day) | |
| grouping.stub!(:date_parts_from_db_string).and_return([2008, 1, 1]) | |
| - Kvlr::ReportsAsSparkline::ReportingPeriod.from_db_string(grouping, '').d… | |
| + Simplabs::ReportsAsSparkline::ReportingPeriod.from_db_string(grouping, '… | |
| end | |
| it 'should return a reporting period with the date part of the monday of t… | |
| - grouping = Kvlr::ReportsAsSparkline::Grouping.new(:week) | |
| + grouping = Simplabs::ReportsAsSparkline::Grouping.new(:week) | |
| grouping.stub!(:date_parts_from_db_string).and_return([2008, 1]) | |
| - Kvlr::ReportsAsSparkline::ReportingPeriod.from_db_string(grouping, '').d… | |
| + Simplabs::ReportsAsSparkline::ReportingPeriod.from_db_string(grouping, '… | |
| end | |
| it 'should return a reporting period with the correct date and with day = … | |
| - grouping = Kvlr::ReportsAsSparkline::Grouping.new(:month) | |
| + grouping = Simplabs::ReportsAsSparkline::Grouping.new(:month) | |
| grouping.stub!(:date_parts_from_db_string).and_return([2008, 1]) | |
| - Kvlr::ReportsAsSparkline::ReportingPeriod.from_db_string(grouping, '').d… | |
| + Simplabs::ReportsAsSparkline::ReportingPeriod.from_db_string(grouping, '… | |
| end | |
| end | |
| @@ -95,7 +95,7 @@ describe Kvlr::ReportsAsSparkline::ReportingPeriod do | |
| it 'should return a reporting period with date and time one hour after the… | |
| now = Time.now | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R… | |
| + reporting_period = Simplabs::ReportsAsSparkline::ReportingPeriod.new(Sim… | |
| expected = now + 1.hour | |
| reporting_period.next.date_time.should == DateTime.new(expected.year, ex… | |
| @@ -103,7 +103,7 @@ describe Kvlr::ReportsAsSparkline::ReportingPeriod do | |
| it 'should return a reporting period with date one day after the current p… | |
| now = Time.now | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R… | |
| + reporting_period = Simplabs::ReportsAsSparkline::ReportingPeriod.new(Sim… | |
| expected = now + 1.day | |
| reporting_period.next.date_time.should == Date.new(expected.year, expect… | |
| @@ -111,7 +111,7 @@ describe Kvlr::ReportsAsSparkline::ReportingPeriod do | |
| it 'should return a reporting period with date one week after the current … | |
| now = DateTime.now | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R… | |
| + reporting_period = Simplabs::ReportsAsSparkline::ReportingPeriod.new(Sim… | |
| expected = reporting_period.date_time + 1.week | |
| reporting_period.next.date_time.should == Date.new(expected.year, expect… | |
| @@ -119,7 +119,7 @@ describe Kvlr::ReportsAsSparkline::ReportingPeriod do | |
| it 'should return a reporting period with date of the first day in the mon… | |
| now = Time.now | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R… | |
| + reporting_period = Simplabs::ReportsAsSparkline::ReportingPeriod.new(Sim… | |
| expected = reporting_period.date_time + 1.month | |
| reporting_period.next.date_time.should == Date.new(expected.year, expect… | |
| @@ -131,7 +131,7 @@ describe Kvlr::ReportsAsSparkline::ReportingPeriod do | |
| it 'should return a reporting period with date and time one hour before th… | |
| now = Time.now | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R… | |
| + reporting_period = Simplabs::ReportsAsSparkline::ReportingPeriod.new(Sim… | |
| expected = now - 1.hour | |
| reporting_period.previous.date_time.should == DateTime.new(expected.year… | |
| @@ -139,7 +139,7 @@ describe Kvlr::ReportsAsSparkline::ReportingPeriod do | |
| it 'should return a reporting period with date one day before the current … | |
| now = Time.now | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R… | |
| + reporting_period = Simplabs::ReportsAsSparkline::ReportingPeriod.new(Sim… | |
| expected = now - 1.day | |
| reporting_period.previous.date_time.should == Date.new(expected.year, ex… | |
| @@ -147,7 +147,7 @@ describe Kvlr::ReportsAsSparkline::ReportingPeriod do | |
| it 'should return a reporting period with date one week before the current… | |
| now = DateTime.now | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R… | |
| + reporting_period = Simplabs::ReportsAsSparkline::ReportingPeriod.new(Sim… | |
| expected = reporting_period.date_time - 1.week | |
| reporting_period.previous.date_time.should == Date.new(expected.year, ex… | |
| @@ -155,7 +155,7 @@ describe Kvlr::ReportsAsSparkline::ReportingPeriod do | |
| it 'should return a reporting period with date of the first day in the mon… | |
| now = Time.now | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R… | |
| + reporting_period = Simplabs::ReportsAsSparkline::ReportingPeriod.new(Sim… | |
| expected = reporting_period.date_time - 1.month | |
| reporting_period.previous.date_time.should == Date.new(expected.year, ex… | |
| @@ -167,30 +167,30 @@ describe Kvlr::ReportsAsSparkline::ReportingPeriod do | |
| it 'should return true for 2 reporting periods with the same date_time and… | |
| now = DateTime.now | |
| - reporting_period1 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::… | |
| - reporting_period2 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::… | |
| + reporting_period1 = Simplabs::ReportsAsSparkline::ReportingPeriod.new(Si… | |
| + reporting_period2 = Simplabs::ReportsAsSparkline::ReportingPeriod.new(Si… | |
| (reporting_period1 == reporting_period2).should == true | |
| end | |
| it 'should return false for 2 reporting periods with the same date_time bu… | |
| now = Time.now | |
| - reporting_period1 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::… | |
| - reporting_period2 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::… | |
| + reporting_period1 = Simplabs::ReportsAsSparkline::ReportingPeriod.new(Si… | |
| + reporting_period2 = Simplabs::ReportsAsSparkline::ReportingPeriod.new(Si… | |
| (reporting_period1 == reporting_period2).should == false | |
| end | |
| it 'should return true for 2 reporting periods with the same grouping but … | |
| - reporting_period1 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::… | |
| - reporting_period2 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::… | |
| + reporting_period1 = Simplabs::ReportsAsSparkline::ReportingPeriod.new(Si… | |
| + reporting_period2 = Simplabs::ReportsAsSparkline::ReportingPeriod.new(Si… | |
| (reporting_period1 == reporting_period2).should == true | |
| end | |
| it 'should return false for 2 reporting periods with the same grouping but… | |
| - reporting_period1 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::… | |
| - reporting_period2 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::… | |
| + reporting_period1 = Simplabs::ReportsAsSparkline::ReportingPeriod.new(Si… | |
| + reporting_period2 = Simplabs::ReportsAsSparkline::ReportingPeriod.new(Si… | |
| (reporting_period1 == reporting_period2).should == false | |
| end | |
| @@ -205,14 +205,14 @@ describe Kvlr::ReportsAsSparkline::ReportingPeriod do | |
| end | |
| it 'should return a reporting period with the date part of (DateTime.now -… | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.first(Kvlr:… | |
| + reporting_period = Simplabs::ReportsAsSparkline::ReportingPeriod.first(S… | |
| expected = @now - 3.hours | |
| reporting_period.date_time.should == DateTime.new(expected.year, expecte… | |
| end | |
| it 'should return a reporting period with the date part of (DateTime.now -… | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.first(Kvlr:… | |
| + reporting_period = Simplabs::ReportsAsSparkline::ReportingPeriod.first(S… | |
| expected = @now - 3.days | |
| reporting_period.date_time.should == Date.new(expected.year, expected.mo… | |
| @@ -220,24 +220,18 @@ describe Kvlr::ReportsAsSparkline::ReportingPeriod do | |
| it 'should return a reporting period with the date of the first day of the… | |
| DateTime.stub!(:now).and_return(DateTime.new(2008, 12, 31, 0, 0, 0)) | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.first(Kvlr:… | |
| + reporting_period = Simplabs::ReportsAsSparkline::ReportingPeriod.first(S… | |
| reporting_period.date_time.should == DateTime.new(2008, 9, 1) | |
| end | |
| it 'should return a reporting period with the date of the monday of the we… | |
| DateTime.stub!(:now).and_return(DateTime.new(2008, 12, 31, 0, 0, 0)) #we… | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.first(Kvlr:… | |
| + reporting_period = Simplabs::ReportsAsSparkline::ReportingPeriod.first(S… | |
| reporting_period.date_time.should == DateTime.new(2008, 12, 8) #the mond… | |
| end | |
| - it 'should return a reporting period that is offset from the end date by t… | |
| - date = DateTime.new(2009, 3, 31) | |
| - reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.first(Kvlr:… | |
| - reporting_period.date_time.should == DateTime.new(2009, 3, 28) | |
| - end | |
| - | |
| end | |
| end | |
| diff --git a/spec/other/report_method_spec.rb b/spec/other/report_method_spec.rb | |
| @@ -1,6 +1,6 @@ | |
| require File.join(File.dirname(__FILE__), '..', 'spec_helper') | |
| -describe Kvlr::ReportsAsSparkline do | |
| +describe Simplabs::ReportsAsSparkline do | |
| describe 'for inherited models' do | |
| @@ -32,7 +32,7 @@ describe Kvlr::ReportsAsSparkline do | |
| end | |
| after do | |
| - Kvlr::ReportsAsSparkline::ReportCache.destroy_all | |
| + Simplabs::ReportsAsSparkline::ReportCache.destroy_all | |
| end | |
| end | |
| diff --git a/spec/other/sparkline_tag_helper_spec.rb b/spec/other/sparkline_tag… | |
| @@ -1,6 +1,6 @@ | |
| require File.join(File.dirname(__FILE__), '..', 'spec_helper') | |
| -describe Kvlr::ReportsAsSparkline::SparklineTagHelper do | |
| +describe Simplabs::ReportsAsSparkline::SparklineTagHelper do | |
| before do | |
| @helper = TestHelper.new | |
| @@ -38,6 +38,6 @@ end | |
| class TestHelper | |
| - include Kvlr::ReportsAsSparkline::SparklineTagHelper | |
| + include Simplabs::ReportsAsSparkline::SparklineTagHelper | |
| end |