Created
November 17, 2016 15:23
-
-
Save mooreniemi/5ab5fcf42d1562e1b3f2b9c51da71235 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -w | |
require 'json' | |
require 'net/http' | |
require 'uri' | |
# includes all subtasks | |
# uri = URI.parse('https://raizlabs.atlassian.net/rest/greenhopper/1.0/rapid/charts/controlchart.json?rapidViewId=146&swimlaneId=167&_=1479395489279') | |
# just tickets | |
uri = URI.parse('https://raizlabs.atlassian.net/rest/greenhopper/1.0/rapid/charts/controlchart.json?rapidViewId=146&swimlaneId=167&quickFilterId=531&_=1479322925859') | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
request = Net::HTTP::Get.new( | |
uri.request_uri, | |
'Content-Type' => 'application/json' | |
) | |
request.basic_auth(ENV['JIRA_UN'], ENV['JIRA_PW']) | |
response = http.request(request) | |
code_msg = "unable to get data (code: #{response.code})" | |
raise code_msg unless response.code.to_i == 200 | |
# for testing, a static response file | |
# response.body = File.read('controlchart.json') | |
data = JSON.parse(response.body) | |
issues = data['issues'] | |
# check out an example issue | |
# p issues.first | |
# for checking against the web gui control chart | |
puts "#{issues.count} issues counted in Drinkless project" | |
into_hours = proc { |m| ((m / 60_000.0) / 60.0) } | |
working_hours = issues.map do |i| | |
# defined by data.columns | |
# 1 = "In Progress", 2 = "PO Review" | |
into_hours.call(i['workingTime'][1]) + | |
into_hours.call(i['workingTime'][2]) | |
end | |
avg_working_hours = (working_hours.reduce(:+) / working_hours.size.to_f) | |
# puts "total working hours: #{avg_working_hours}" | |
# switch 8 to 24 if you want literal days | |
puts "working state defined by 'In Progress' and 'PO Review' statuses" | |
puts "8 hour days were assumed\n\n\n" | |
days, hours = avg_working_hours.divmod(8) | |
puts s = 'Average cycle time (working hours spent in working state): ' | |
puts '-' * s.length | |
puts "#{days} working day#{days > 1 ? 's' : ''}, \ | |
#{hours.ceil} working hour#{hours > 1 ? 's' : ''}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sample output: