Last active
March 9, 2020 20:28
-
-
Save Mystler/b6c3d6ba96c4145508137dd1dc2489bf to your computer and use it in GitHub Desktop.
They See Me Rolling
This file contains 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
require "net/http" | |
require "net/https" | |
require "json" | |
class APIClient | |
def self.get(url, use_https = true) | |
uri = URI.parse(url) | |
request = Net::HTTP.new(uri.host, uri.port) | |
if use_https | |
request.use_ssl = true | |
request.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
end | |
response = request.get(uri.request_uri) | |
return nil if response.code != "200" | |
return JSON.parse(response.body) | |
end | |
end |
This file contains 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
require "rubygems" | |
require "bundler/setup" | |
#require "yaml" | |
require_relative "lib/WCLClient" | |
#reports = YAML.load(File.read("reports.yml", mode: "r:UTF-8")) | |
#reports = WCLClient.getCustomView("rankings/encounter/2329?difficulty=5&class=8&spec=4")["rankings"].collect { |x| x["reportID"] } | |
reports = WCLClient.getCustomView("rankings/encounter/2327?difficulty=5&class=8&spec=4&bracket=11")["rankings"].collect { |x| x["reportID"] } | |
=begin | |
reports += WCLClient.getCustomView("rankings/encounter/2334?difficulty=5&class=8&spec=4")["rankings"].collect { |x| x["reportID"] } | |
reports += WCLClient.getCustomView("rankings/encounter/2328?difficulty=5&class=8&spec=4")["rankings"].collect { |x| x["reportID"] } | |
reports += WCLClient.getCustomView("rankings/encounter/2333?difficulty=5&class=8&spec=4")["rankings"].collect { |x| x["reportID"] } | |
reports += WCLClient.getCustomView("rankings/encounter/2335?difficulty=5&class=8&spec=4")["rankings"].collect { |x| x["reportID"] } | |
reports += WCLClient.getCustomView("rankings/encounter/2343?difficulty=5&class=8&spec=4")["rankings"].collect { |x| x["reportID"] } | |
reports += WCLClient.getCustomView("rankings/encounter/2336?difficulty=5&class=8&spec=4")["rankings"].collect { |x| x["reportID"] } | |
reports += WCLClient.getCustomView("rankings/encounter/2331?difficulty=5&class=8&spec=4")["rankings"].collect { |x| x["reportID"] } | |
reports += WCLClient.getCustomView("rankings/encounter/2345?difficulty=5&class=8&spec=4")["rankings"].collect { |x| x["reportID"] } | |
reports += WCLClient.getCustomView("rankings/encounter/2337?difficulty=5&class=8&spec=4")["rankings"].collect { |x| x["reportID"] } | |
reports += WCLClient.getCustomView("rankings/encounter/2344?difficulty=5&class=8&spec=4")["rankings"].collect { |x| x["reportID"] } | |
=end | |
reports.uniq! | |
Combinations_count = {} | |
RTB_count = {} | |
LD_count = {} | |
total_fights = 0 | |
def update_live_output(total_fights, total_reports, report_prog = nil, fight_prog = nil) | |
if Gem.win_platform? | |
system "cls" | |
else | |
system "clear" | |
end | |
if report_prog && fight_prog | |
puts "Last processed:" | |
puts "- Report #{report_prog}" | |
puts "-- Fight #{fight_prog}" | |
puts | |
end | |
puts "Processed a total of #{total_fights} fights in #{total_reports} reports." | |
puts | |
puts "Results:" | |
sum_rtb = RTB_count.values.reduce(:+) | |
puts "Regular RtB rolls: #{sum_rtb}" | |
rdisp = RTB_count.sort_by { |k, v| k } | |
rdisp.each do |buffs, count| | |
puts "#{buffs}:\t#{count}\t#{(count.to_f / sum_rtb.to_f).round(5)}" | |
end | |
puts | |
sum_ld = LD_count.values.reduce(:+) | |
puts "Loaded Dice RtB rolls: #{sum_ld}" | |
ldisp = LD_count.sort_by { |k, v| k } | |
ldisp.each do |buffs, count| | |
puts "#{buffs}:\t#{count}\t#{(count.to_f / sum_ld.to_f).round(5)}" | |
end | |
puts | |
sum_comb = Combinations_count.values.reduce(:+) | |
puts "Combination counts:" | |
cdisp = Combinations_count.sort_by { |k, v| -v } | |
cdisp.each do |comb, count| | |
buffs = comb.split(", ").size | |
puts "#{count}x\t#{buffs} buff\t#{(count.to_f / sum_comb.to_f).round(5)}\t\t#{comb}" | |
end | |
end | |
def buff_name(id) | |
case id | |
when 193356 | |
"Broadside" | |
when 199600 | |
"Buried Treasure" | |
when 193358 | |
"Grand Melee" | |
when 193357 | |
"Ruthless Precision" | |
when 199603 | |
"Skull and Crossbones" | |
when 193359 | |
"True Bearing" | |
end | |
end | |
def save_count(data) | |
if data[:buffs].size > 0 | |
target = data[:has_ld] ? LD_count : RTB_count | |
target[data[:buffs].size] = target[data[:buffs].size].to_i.next | |
comb = data[:buffs].collect { |x| buff_name(x) }.sort.join(", ") | |
Combinations_count[comb] = Combinations_count[comb].to_i.next | |
end | |
end | |
# WCL Processing | |
reports.each_with_index do |report, idx| | |
fights = WCLClient.getFightList(report) | |
fights.select! { |x| x["boss"] > 0 } | |
fights.each_with_index do |fight, fidx| | |
total_fights += 1 | |
temp_store = {} | |
data = WCLClient.getCustomView("report/events/buffs/#{report}?start=#{fight["start_time"]}&end=#{fight["end_time"]}&sourceclass=rogue") | |
data["events"].each do |entry| | |
temp_store[entry["sourceID"]] = {rtb_timestamp: nil, has_ld: false, buffs: []} unless temp_store[entry["sourceID"]] | |
if temp_store[entry["sourceID"]][:rtb_timestamp] && entry["timestamp"] > temp_store[entry["sourceID"]][:rtb_timestamp] + 750 | |
# New cycle: Save and clear previous RtB | |
save_count(temp_store[entry["sourceID"]]) | |
temp_store[entry["sourceID"]][:rtb_timestamp] = nil | |
temp_store[entry["sourceID"]][:has_ld] = false | |
end | |
if entry["type"] == "removebuff" && entry["ability"]["guid"] == 256171 | |
# Current cycle had LD | |
temp_store[entry["sourceID"]][:has_ld] = true | |
elsif ["applybuff", "refreshbuff"].include?(entry["type"]) && entry["ability"]["guid"] == 193316 | |
# RtB update: Mark cycle for processing | |
temp_store[entry["sourceID"]][:rtb_timestamp] = entry["timestamp"] | |
elsif ["applybuff", "refreshbuff"].include?(entry["type"]) && [193356, 199600, 193358, 193357, 199603, 193359].include?(entry["ability"]["guid"]) | |
# Track buff application and refresh | |
temp_store[entry["sourceID"]][:buffs].push(entry["ability"]["guid"]).uniq! | |
elsif ["removebuff"].include?(entry["type"]) && [193356, 199600, 193358, 193357, 199603, 193359].include?(entry["ability"]["guid"]) | |
# Track buff expiries | |
temp_store[entry["sourceID"]][:buffs].delete(entry["ability"]["guid"]) | |
end | |
end | |
temp_store.each do |source, data| | |
save_count(data) if data[:rtb_timestamp] | |
end | |
update_live_output(total_fights, idx + 1, "#{idx + 1} of #{reports.size}", "#{fidx + 1} of #{fights.size}") | |
end | |
end | |
update_live_output(total_fights, reports.size) | |
puts "DONE!" | |
gets |
This file contains 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
require_relative "APIClient" | |
require "yaml" | |
class WCLClient < APIClient | |
BASE_URL = "https://www.warcraftlogs.com:443/v1/" | |
PUBLIC_KEY = YAML.load(File.read("keys.yml"))["warcraftlogs-public"] | |
def self.getReportsByGuild(name, realm, region) | |
return get("#{BASE_URL}reports/guild/#{name}/#{realm}/#{region}?api_key=#{PUBLIC_KEY}") | |
end | |
def self.getCustomView(path) | |
return get("#{BASE_URL}#{path}&api_key=#{PUBLIC_KEY}") | |
end | |
def self.getFightList(reportId) | |
data = get("#{BASE_URL}report/fights/#{reportId}?api_key=#{PUBLIC_KEY}") | |
if data && data["fights"] | |
return data["fights"] | |
else | |
puts "Possible error when fetching fight list for #{reportId}." | |
return [] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment