Class: RailsPulse::Requests::Charts::AverageResponseTimes
- Inherits:
-
Object
- Object
- RailsPulse::Requests::Charts::AverageResponseTimes
- Defined in:
- app/models/rails_pulse/requests/charts/average_response_times.rb
Instance Method Summary collapse
-
#initialize(ransack_query:, period_type: nil, route: nil, start_time: nil, end_time: nil, start_duration: nil, disabled_tags: [], show_non_tagged: true) ⇒ AverageResponseTimes
constructor
A new instance of AverageResponseTimes.
- #to_chart_data ⇒ Object
Constructor Details
#initialize(ransack_query:, period_type: nil, route: nil, start_time: nil, end_time: nil, start_duration: nil, disabled_tags: [], show_non_tagged: true) ⇒ AverageResponseTimes
Returns a new instance of AverageResponseTimes.
5 6 7 8 9 10 11 12 13 14 |
# File 'app/models/rails_pulse/requests/charts/average_response_times.rb', line 5 def initialize(ransack_query:, period_type: nil, route: nil, start_time: nil, end_time: nil, start_duration: nil, disabled_tags: [], show_non_tagged: true) @ransack_query = ransack_query @period_type = period_type @route = route @start_time = start_time @end_time = end_time @start_duration = start_duration @disabled_tags = @show_non_tagged = show_non_tagged end |
Instance Method Details
#to_chart_data ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/rails_pulse/requests/charts/average_response_times.rb', line 16 def to_chart_data # Note: Overall request summaries (summarizable_id: 0) are not filtered by tags # as they aggregate all requests regardless of route tags summaries = @ransack_query.result(distinct: false) .with_tag_filters(@disabled_tags, @show_non_tagged) .where( summarizable_type: "RailsPulse::Request", summarizable_id: 0, # Overall request summaries period_type: @period_type ) summaries = summaries .group(:period_start) .having("AVG(avg_duration) > ?", @start_duration || 0) .average(:avg_duration) .transform_keys(&:to_i) # Pad missing data points with zeros step = @period_type == :hour ? 1.hour : 1.day data = {} (@start_time.to_i..@end_time.to_i).step(step) do || data[.to_i] = summaries[.to_i].to_f.round(2) end data end |