forked from Ravenholdt-TC/SimcScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrinketSimulation.rb
108 lines (98 loc) · 3.54 KB
/
TrinketSimulation.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
require 'rubygems'
require 'bundler/setup'
require_relative 'lib/Interactive'
require_relative 'lib/JSONParser'
require_relative 'lib/JSONResults'
require_relative 'lib/Logging'
require_relative 'lib/SimcConfig'
require_relative 'lib/SimcHelper'
Logging.Initialize("TrinketSimulation")
classfolder = Interactive.SelectSubfolder('TrinketSimulation')
template = Interactive.SelectTemplate("TrinketSimulation/#{classfolder}/TrinketSimulation")
trinketListProfile = Interactive.SelectTemplate('TrinketSimulation/TrinketList')
fightstyle = Interactive.SelectTemplate('Fightstyles/Fightstyle')
# Log all interactively set settings
puts
Logging.LogScriptInfo "Summarizing input:"
Logging.LogScriptInfo "-- Class: #{classfolder}"
Logging.LogScriptInfo "-- Profile: #{template}"
Logging.LogScriptInfo "-- Trinket List: #{trinketListProfile}"
Logging.LogScriptInfo "-- Fightstyle: #{fightstyle}"
puts
trinketList = JSONParser.ReadFile("#{SimcConfig['ProfilesFolder']}/TrinketSimulation/TrinketList_#{trinketListProfile}.json")
simcFile = "#{SimcConfig['GeneratedFolder']}/TrinketSimulation_#{fightstyle}_#{template}.simc"
Logging.LogScriptInfo "Writing profilesets to #{simcFile}!"
File.open(simcFile, 'w') do |out|
out.puts 'name="Template"'
out.puts 'trinket1=empty'
out.puts 'trinket2=empty'
out.puts
trinketList['trinkets'].each do |trinket|
bonusIdString = trinket['bonusIds'].empty? ? '' : ',bonus_id=' + trinket['bonusIds'].join('/')
trinket['itemLevels'].each do |ilvl|
out.puts "profileset.\"#{trinket['name']}_#{ilvl}\"+=trinket1=,id=#{trinket['itemId']},ilevel=#{ilvl}#{bonusIdString}"
trinket['additionalInput'].each do |input|
out.puts "profileset.\"#{trinket['name']}_#{ilvl}\"+=#{input}"
end
end
out.puts
end
end
Logging.LogScriptInfo 'Starting simulations, this may take a while!'
logFile = "#{SimcConfig['LogsFolder']}/TrinketSimulation_#{fightstyle}_#{template}"
reportFile = "#{SimcConfig['ReportsFolder']}/TrinketSimulation_#{fightstyle}_#{template}.json"
metaFile = "#{SimcConfig['ReportsFolder']}/meta/TrinketSimulation_#{fightstyle}_#{template}.json"
params = [
"#{SimcConfig['ConfigFolder']}/SimcTrinketConfig.simc",
"output=#{logFile}.log",
"json2=#{logFile}.json",
"#{SimcConfig['ProfilesFolder']}/Fightstyles/Fightstyle_#{fightstyle}.simc",
"#{SimcConfig['ProfilesFolder']}/TrinketSimulation/#{classfolder}/TrinketSimulation_#{template}.simc",
simcFile
]
SimcHelper.RunSimulation(params)
# Read JSON Output
results = JSONResults.new("#{logFile}.json")
# Extract metadata
Logging.LogScriptInfo "Extract metadata from #{logFile}.json to #{metaFile}..."
results.extractMetadata(metaFile)
Logging.LogScriptInfo "Processing data from #{logFile}.json to #{reportFile}..."
templateDPS = 0
iLevelList = []
sims = {}
results.getAllDPSResults().each do |name, dps|
if data = /\A(.+)_(\p{Digit}+)\Z/.match(name)
sims[data[1]] = {} unless sims[data[1]]
sims[data[1]][data[2].to_i] = dps
iLevelList.push(data[2].to_i)
elsif name == 'Template'
templateDPS = dps
end
end
iLevelList.uniq!
iLevelList.sort!
# Write report
report = [ ]
# Header
header = [ "Trinket" ]
iLevelList.each do |ilvl|
header.push(ilvl.to_s)
end
report.push(header)
# Trinkets
sims.each do |name, values|
actor = [ ]
actor.push(name)
iLevelList.each do |ilvl|
if values[ilvl]
actor.push(values[ilvl] - templateDPS)
else
actor.push(0)
end
end
report.push(actor)
end
# Write into the report file
JSONParser.WriteFile(reportFile, report)
Logging.LogScriptInfo 'Done! Press enter to quit...'
Interactive.GetInputOrArg()