Sha256: 9d3fa41947661379418a9c4bb480a0eeff136946fb9d441d74c6c30a397b095c

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

module RailsPerformance
  module Reports
    class ResponseTimeReport < BaseReport
      def set_defaults
        @group ||= :datetime
      end

      def data
        all     = {}
        stop    = RailsPerformance::Reports::BaseReport::time_in_app_time_zone(Time.at(60 * (Time.now.to_i / 60)))
        offset  = RailsPerformance::Reports::BaseReport::time_in_app_time_zone(Time.now).utc_offset
        current = stop - RailsPerformance.duration
        @data   = []

        # puts "current: #{current}"
        # puts "stop: #{stop}"

        # read current values
        db.group_by(group).each do |(k, v)|
          durations = v.collect{|e| e["duration"]}.compact
          next if durations.empty?
          all[k] = durations.sum.to_f / durations.count
        end

        # add blank columns
        while current <= stop
          views = all[current.strftime(RailsPerformance::FORMAT)] || 0
          # time = RailsPerformance::Reports::BaseReport::time_in_app_time_zone(current)
          @data << [(current.to_i + offset) * 1000, views.round(2)]
          current += 1.minute
        end

        # sort by time
        @data.sort!
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails_performance-1.2.0.alpha4 lib/rails_performance/reports/response_time_report.rb
rails_performance-1.2.0.alpha3 lib/rails_performance/reports/response_time_report.rb