Module: CreationReport::ClassMethods
- Defined in:
- lib/creation_report.rb
Constant Summary collapse
- @@number_of_days =
1000
Instance Method Summary collapse
- #average_created_at_this_hour ⇒ Object
- #average_created_by_day ⇒ Object
- #created_by_day ⇒ Object
- #created_by_hour(count = 24) ⇒ Object
- #created_by_hour_of_day ⇒ Object
- #creations_by_day_chart ⇒ Object
- #creations_by_hour_of_day_chart ⇒ Object
Instance Method Details
#average_created_at_this_hour ⇒ Object
56 57 58 |
# File 'lib/creation_report.rb', line 56 def average_created_at_this_hour created_by_day.values.at( Time.now.hour ) end |
#average_created_by_day ⇒ Object
52 53 54 |
# File 'lib/creation_report.rb', line 52 def average_created_by_day created_by_day.values.sum.to_f / created_by_day.values.length.to_f end |
#created_by_day ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/creation_report.rb', line 32 def created_by_day DataSet::DailyDataSet.new( count( :group => "DATE(#{table_name}.created_at)", :order => "#{table_name}.id ASC", :conditions => ["#{table_name}.created_at > ?", report_start_time] ), @@number_of_days ) end |
#created_by_hour(count = 24) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/creation_report.rb', line 22 def created_by_hour( count = 24) DataSet::HourlyDataSet.new( count( :group => "DATE_FORMAT( CONVERT_TZ(#{table_name}.created_at, '+0:00', '#{((Time.zone.utc_offset/3600 + (Time.now.dst? ? 1 : 0)) rescue '-0')}:00'),'%Y-%m-%d %H')", :order => "#{table_name}.id ASC", :conditions => ["#{table_name}.created_at > ?", count.hours.ago] ), count ) end |
#created_by_hour_of_day ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/creation_report.rb', line 42 def created_by_hour_of_day DataSet::HourOfDayDataSet.new( count( :group => "DATE_FORMAT(created_at, '%k')", :order => "#{table_name}.id ASC", :conditions => ["created_at > ?", report_start_time] ) ) end |
#creations_by_day_chart ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/creation_report.rb', line 60 def creations_by_day_chart dataset = created_by_day GoogleChart::LineChart.new('600x150', "#{self.table_name.upcase} CREATED IN THE LAST #{@@number_of_days} DAYS", false) do |lc| lc.data_encoding = :extended lc.data "Created", dataset.values, '00ff00' lc.show_legend = false lc.title_color = 'A5B1A0' lc.title_font_size = '10' lc.max_value dataset.max_value lc.axis :y, :range => [dataset.min_value, dataset.max_value] lc.axis :x, :labels => dataset.date_labels lc.grid :y_step => 50, :x_step => 25, :length_segment => 2, :length_blank => 10 end end |
#creations_by_hour_of_day_chart ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/creation_report.rb', line 75 def creations_by_hour_of_day_chart dataset = created_by_hour_of_day GoogleChart::LineChart.new('600x150', "#{self.table_name.upcase} CREATED FOR EACH HOUR", false) do |lc| lc.data "Created", dataset.values, '00ff00' lc.show_legend = false lc.title_color = 'A5B1A0' lc.title_font_size = '10' lc.max_value dataset.max_value lc.axis :y, :range => [dataset.min_value, dataset.max_value] lc.axis :x, :labels => dataset.hours.to_a lc.grid :y_step => 50, :x_step => 100/11.5, :length_segment => 2, :length_blank => 10 end end |