Skip to content

Instantly share code, notes, and snippets.

@tdooner
Created August 17, 2015 22:31
Show Gist options
  • Save tdooner/25afd16d5b6db4ff5494 to your computer and use it in GitHub Desktop.
Save tdooner/25afd16d5b6db4ff5494 to your computer and use it in GitHub Desktop.
# To use this script, download a CSV of incidents from Pagerduty, e.g
# https://causes.pagerduty.com/csv/incidents?since=2015-08-10T00:00:00-07:00&until=2015-08-17T23:59:59-07:00
require 'csv'
require 'date'
ENV['TZ'] = 'America/Los_Angeles'
def average(array, round = 1)
(array.inject(0, :+) / array.length.to_f).round(round)
end
def median(array, round = 1)
(array.length % 2 == 1 ?
array.sort[array.length / 2] :
array.sort[array.length / 2 - 1, 2].inject(0, :+) / 2.0).round(round)
end
total = 0
escalations = 0
durations = []
CSV.parse(ARGF, headers: :first_row) do |row|
total += 1
start_time = DateTime.parse(row['Opened On']).to_time.localtime
end_time = DateTime.parse(row['Resolved On']).to_time.localtime
durations << (end_time - start_time) / 60
escalations += 1 if row['# Escalations'].to_i > 0
end
puts "#{total} pages"
puts "#{escalations} escalations"
puts "#{median(durations)} min median duration"
puts "#{average(durations)} min average duration"
puts "#{durations.sort.last} min max duration"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment