Class: RailsPerformance::Reports::BaseReport
- Inherits:
-
Object
- Object
- RailsPerformance::Reports::BaseReport
- Defined in:
- lib/rails_performance/reports/base_report.rb
Direct Known Subclasses
BreakdownReport, CrashReport, RecentRequestsReport, RequestsReport, ResponseTimeReport, SlowRequestsReport, ThroughputReport
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#sort ⇒ Object
readonly
Returns the value of attribute sort.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #calculate_data ⇒ Object
- #collect ⇒ Object
-
#initialize(db, group: nil, sort: nil, title: nil) ⇒ BaseReport
constructor
A new instance of BaseReport.
- #set_defaults ⇒ Object
Constructor Details
#initialize(db, group: nil, sort: nil, title: nil) ⇒ BaseReport
Returns a new instance of BaseReport.
6 7 8 9 10 11 12 13 |
# File 'lib/rails_performance/reports/base_report.rb', line 6 def initialize(db, group: nil, sort: nil, title: nil) @db = db @group = group @sort = sort @title = title set_defaults end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
4 5 6 |
# File 'lib/rails_performance/reports/base_report.rb', line 4 def db @db end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
4 5 6 |
# File 'lib/rails_performance/reports/base_report.rb', line 4 def group @group end |
#sort ⇒ Object (readonly)
Returns the value of attribute sort.
4 5 6 |
# File 'lib/rails_performance/reports/base_report.rb', line 4 def sort @sort end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
4 5 6 |
# File 'lib/rails_performance/reports/base_report.rb', line 4 def title @title end |
Class Method Details
.time_in_app_time_zone(time) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/rails_performance/reports/base_report.rb', line 24 def self.time_in_app_time_zone(time) app_time_zone = ::Rails.application.config.time_zone if app_time_zone.present? time.in_time_zone(app_time_zone) else time end end |
Instance Method Details
#calculate_data ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rails_performance/reports/base_report.rb', line 33 def calculate_data now = Time.current stop = Time.at(60 * ((now.to_i)/ 60)) offset = RailsPerformance::Reports::BaseReport::time_in_app_time_zone(now).utc_offset current = stop - RailsPerformance.duration @data = [] all = {} # read current values db.group_by(group).each do |(k, v)| yield(all, k, v) end # add blank columns while current <= stop key = (current).strftime(RailsPerformance::FORMAT) views = all[key].presence || 0 @data << [(current.to_i + offset) * 1000, views.round(2)] current += 1.minute end # sort by time @data.sort! end |
#collect ⇒ Object
15 16 17 18 19 20 |
# File 'lib/rails_performance/reports/base_report.rb', line 15 def collect db.group_by(group).inject([]) do |res, (k,v)| res << yield(k, v) res end end |
#set_defaults ⇒ Object
22 |
# File 'lib/rails_performance/reports/base_report.rb', line 22 def set_defaults; end |