Skip to content

Instantly share code, notes, and snippets.

@mooreniemi
Last active November 22, 2016 16:01
Show Gist options
  • Save mooreniemi/7488df79d2ef71d5e874e47f44424a46 to your computer and use it in GitHub Desktop.
Save mooreniemi/7488df79d2ef71d5e874e47f44424a46 to your computer and use it in GitHub Desktop.
#!/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' : ''}"
@mooreniemi
Copy link
Author

mooreniemi commented Nov 21, 2016

314 issues counted in Drinkless project
working state defined by 'In Progress' and 'PO Review' statuses
8 hour days were assumed


Average cycle time (working hours spent in working state):
-----------------------------------------------------------
5 working days, 7 working hours

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment