| added support for postgres - reportable - Fork of reportable required by WarVox… | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit cabd6ea34c0922bdb62628218399f34f7857e2dd | |
| parent 6fa91753578a26722f5dcb1910bb8d771117c316 | |
| Author: marcoow <[email protected]> | |
| Date: Thu, 4 Dec 2008 22:02:49 +0800 | |
| added support for postgres | |
| Signed-off-by: Marco Otte-Witte <[email protected]> | |
| Diffstat: | |
| M README.rdoc | 10 ++++++---- | |
| M lib/kvlr/reports_as_sparkline/grou… | 15 +++++++++++++++ | |
| M lib/kvlr/reports_as_sparkline/repo… | 2 +- | |
| M lib/kvlr/reports_as_sparkline/repo… | 5 +++-- | |
| M spec/db/database.yml | 10 ++++++++-- | |
| M spec/db/schema.rb | 2 +- | |
| M spec/other/cumulated_report_spec.rb | 1 + | |
| M spec/other/report_spec.rb | 1 + | |
| 8 files changed, 36 insertions(+), 10 deletions(-) | |
| --- | |
| diff --git a/README.rdoc b/README.rdoc | |
| @@ -1,6 +1,6 @@ | |
| -## ReportsAsSparkline | |
| += ReportsAsSparkline | |
| -This plugin shall allow you to generate sparklines and do reporting from your … | |
| +ReportsAsSparkline enables you to generate reports and sparklines from your da… | |
| ### Example | |
| @@ -24,12 +24,14 @@ Using *report_as_sparkline* like this will add the followin… | |
| ### Implemented features | |
| * cumulate option that depends on other report | |
| -### Pending points | |
| +== TODOs/ future plans | |
| -* Create a model to cache results and reuse | |
| +* support for Oracle and DB2 (and others?) missing | |
| * Implement data ranges in arguments | |
| * Limit number of data points to maximum that the google chart api allows | |
| * Make graph styling configurable | |
| +If you want ot suggest any new features or report bugs, do so at http://simpla… | |
| + | |
| © 2008 Martin Kavalar, Marco Otte-Witte (http://simplabs.com/#projects), … | |
| diff --git a/lib/kvlr/reports_as_sparkline/grouping.rb b/lib/kvlr/reports_as_sp… | |
| @@ -65,6 +65,8 @@ module Kvlr #:nodoc: | |
| mysql_format(date_column_name) | |
| when 'ActiveRecord::ConnectionAdapters::SQLite3Adapter' | |
| sqlite_format(date_column_name) | |
| + when 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter' | |
| + postgresql_format(date_column_name) | |
| end | |
| end | |
| @@ -96,6 +98,19 @@ module Kvlr #:nodoc: | |
| end | |
| end | |
| + def postgresql_format(date_column_name) | |
| + return case @identifier | |
| + when :day | |
| + "date_trunc('day', #{date_column_name})" | |
| + when :week | |
| + "date_trunc('week', #{date_column_name})" | |
| + when :month | |
| + "date_trunc('month', #{date_column_name})" | |
| + when :hour | |
| + "date_trunc('hour', #{date_column_name})" | |
| + end | |
| + end | |
| + | |
| end | |
| end | |
| diff --git a/lib/kvlr/reports_as_sparkline/report.rb b/lib/kvlr/reports_as_spar… | |
| @@ -34,7 +34,7 @@ module Kvlr #:nodoc: | |
| options[:value_column_name].to_s, | |
| :conditions => conditions, | |
| :group => grouping.to_sql(options[:date_column_name]), | |
| - :order => "#{options[:date_column_name].to_s} DESC" | |
| + :order => "#{grouping.to_sql(options[:date_column_name])} DESC" | |
| ) | |
| end | |
| end | |
| diff --git a/lib/kvlr/reports_as_sparkline/report_cache.rb b/lib/kvlr/reports_a… | |
| @@ -23,13 +23,14 @@ module Kvlr #:nodoc: | |
| def self.get_last_reporting_period(cached_data, grouping, acc) | |
| return acc if cached_data.empty? | |
| - period = grouping.to_reporting_period(DateTime.parse(cached_data[0].… | |
| + puts cached_data[0].reporting_period.class.inspect | |
| + period = grouping.to_reporting_period(cached_data[0].reporting_perio… | |
| cached_data[1..-2].each_with_index do |cached, i| | |
| if grouping.next_reporting_period(grouping.to_reporting_period(Dat… | |
| return cached | |
| end | |
| end | |
| - return grouping.to_reporting_period(DateTime.parse(cached_data[-1].r… | |
| + return grouping.to_reporting_period(cached_data[-1].reporting_period) | |
| end | |
| def self.update_cache(new_data, cached_data, report, grouping) | |
| diff --git a/spec/db/database.yml b/spec/db/database.yml | |
| @@ -8,4 +8,10 @@ mysql: | |
| username: reports_as_spark | |
| password: reports_as_spark | |
| host: localhost | |
| - | |
| -\ No newline at end of file | |
| + | |
| +postgresql: | |
| + adapter: postgresql | |
| + database: reports_as_sparkline_test | |
| + username: reports_as_sparkline | |
| + password: reports_as_sparkline | |
| + host: localhost | |
| +\ No newline at end of file | |
| diff --git a/spec/db/schema.rb b/spec/db/schema.rb | |
| @@ -12,7 +12,7 @@ ActiveRecord::Schema.define(:version => 1) do | |
| t.string :report_name, :null => false | |
| t.string :report_grouping, :null => false | |
| t.float :value, :null => false, :default => 0 | |
| - t.string :reporting_period, :null => false | |
| + t.datetime :reporting_period, :null => false | |
| t.timestamps | |
| end | |
| diff --git a/spec/other/cumulated_report_spec.rb b/spec/other/cumulated_report_… | |
| @@ -39,6 +39,7 @@ describe Kvlr::ReportsAsSparkline::CumulatedReport do | |
| after do | |
| User.destroy_all | |
| + Kvlr::ReportsAsSparkline::ReportCache.destroy_all | |
| end | |
| end | |
| diff --git a/spec/other/report_spec.rb b/spec/other/report_spec.rb | |
| @@ -58,6 +58,7 @@ describe Kvlr::ReportsAsSparkline::Report do | |
| after do | |
| User.destroy_all | |
| + Kvlr::ReportsAsSparkline::ReportCache.destroy_all | |
| end | |
| end |