Class: AuditRails::Audit
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AuditRails::Audit
- Extended by:
- DBExtension
- Defined in:
- app/models/audit_rails/audit.rb
Class Method Summary collapse
- .analysis_by_hourly_views ⇒ Object
- .analysis_by_page_views ⇒ Object
- .analysis_by_user_name ⇒ Object
- .analysis_per_user_by_page_views ⇒ Object
- .count_by_day(start_date = 1.year.ago, end_date = Time.now) ⇒ Object
- .needs_attr_accessible? ⇒ Boolean
- .no_audit_entry_for_today?(action_name, user_name) ⇒ Boolean
- .unique_visitor_count ⇒ Object
- .visitor_count ⇒ Object
Methods included from DBExtension
Class Method Details
.analysis_by_hourly_views ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'app/models/audit_rails/audit.rb', line 59 def self.analysis_by_hourly_views hourly_counts = Hash[group_by_hours.count.map{|k,v| [k.to_i, v]}] hourly_series = Array.new(24, 0) hourly_series.each.with_index do |a, i| hourly_series[i] = hourly_counts[i] if hourly_counts[i] end hourly_series.map.with_index{|v,i| {'hour' => i.to_s.rjust(2,'0')+":00", 'count' => v}}.to_json end |
.analysis_by_page_views ⇒ Object
38 39 40 |
# File 'app/models/audit_rails/audit.rb', line 38 def self.analysis_by_page_views group_by_controller_action.count.map{|k,v| {'page' => k.join('/'), 'count' => v}}.to_json end |
.analysis_by_user_name ⇒ Object
34 35 36 |
# File 'app/models/audit_rails/audit.rb', line 34 def self.analysis_by_user_name group_by_user_name.count.map{|k,v| {'user' => k, 'count' => v}}.to_json end |
.analysis_per_user_by_page_views ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'app/models/audit_rails/audit.rb', line 42 def self.analysis_per_user_by_page_views users = {} group_by_user_name.group_by_controller_action.count.map do |k, v| value = [{"page" => "#{k[1]}/#{k[2]}", "count" => v}] users[k[0]] = users[k[0]] ? users[k[0]] + value : value end users.to_json end |
.count_by_day(start_date = 1.year.ago, end_date = Time.now) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/audit_rails/audit.rb', line 70 def self.count_by_day(start_date=1.year.ago, end_date=Time.now) start_date ||= 3.months.ago end_date ||= Time.now dates = start_date.to_date..end_date.to_date records = AuditRails::Audit.where(created_at: start_date.to_date.beginning_of_day..end_date.to_date.end_of_day).order('created_at') records = records.group_by{|audit| audit.created_at.to_date.strftime('%Y%m%d')} overall_counts = Hash.new(0) overall_counts['Date']='Page views' records.each do |date, audits| overall_counts[date] = audits.count end dates = dates.map{|d| d.strftime('%Y%m%d')} dates.each do |date| overall_counts[date] = "#{overall_counts[date]}".to_i end overall_counts.to_json end |
.needs_attr_accessible? ⇒ Boolean
5 6 7 |
# File 'app/models/audit_rails/audit.rb', line 5 def self.needs_attr_accessible? Rails::VERSION::MAJOR == 3 end |
.no_audit_entry_for_today?(action_name, user_name) ⇒ Boolean
27 28 29 30 31 32 |
# File 'app/models/audit_rails/audit.rb', line 27 def self.no_audit_entry_for_today?(action_name, user_name) audits = where(action: action_name, user_name: user_name, created_at: Time.now.to_date.beginning_of_day..Time.now.to_date.end_of_day) audits.blank? end |
.unique_visitor_count ⇒ Object
51 52 53 |
# File 'app/models/audit_rails/audit.rb', line 51 def self.unique_visitor_count group_by_ip_address.count.values.size end |
.visitor_count ⇒ Object
55 56 57 |
# File 'app/models/audit_rails/audit.rb', line 55 def self.visitor_count group_by_ip_address.count.values.sum end |