VenturePlanSoDMissions icon indicating copy to clipboard operation
VenturePlanSoDMissions copied to clipboard

Add mission logging for troubleshooting

Open zealvurte opened this issue 3 years ago • 4 comments

To help with troubleshooting, this addon probably needs an easy way to output mission logs, so here's something basic you can use and build upon:

Modify: VenturePlanSoDMissions.toc

## SavedVariables: VenturePlanSoDMissions_Logs
extra-vs-spells.lua
logs.lua

Add: logs.lua

local SaveMissionLog do
	function SaveMissionLog(missionID, autoCombatResult)
		if not (missionID and autoCombatResult and autoCombatResult.combatLog and C_Garrison.GetFollowerTypeByMissionID(missionID) == 123) then return end
		local cm, mi = C_Garrison.GetCompleteMissions(123)
		for i, m in ipairs(cm) do
			if m.missionID == missionID then
				mi = m
				break
			end
		end
		local l = {
			build = select(2,GetBuildInfo()),
			addonVersion = GetAddOnMetadata("VenturePlan","Version"),
			missionID = missionID,
			missionName = mi.name,
			missionScalar = mi.missionScalar,
			winner = autoCombatResult.winner,
			log = autoCombatResult.combatLog,
			environment = C_Garrison.GetAutoMissionEnvironmentEffect(missionID),
			encounters = C_Garrison.GetMissionCompleteEncounters(missionID),
			followers = {},
		}
		for i, fid in ipairs(mi.followers) do
			local fi = C_Garrison.GetFollowerMissionCompleteInfo(fid)
			local fs = C_Garrison.GetFollowerAutoCombatStats(fid)
			local fsp = C_Garrison.GetFollowerAutoCombatSpells(fid,fi.level)
			l.followers[fid] = fi
			local f = l.followers[fid]
			f.followerID = fid
			f.garrFollowerID = C_Garrison.GetFollowerInfo(fid).garrFollowerID or fid
			f.health = fs.currentHealth
			f.maxHealth = fs.maxHealth
			f.attack = fs.attack
			f.spells = fsp
		end
		tinsert(VenturePlanSoDMissions_Logs,l)
	end
	local function OnEvent(self, event, ...)
		if (event == "ADDON_LOADED" and select(1,...) == "VenturePlanSoDMissions") then
			_G["VenturePlanSoDMissions_Logs"] = {}
		elseif (event == "GARRISON_MISSION_COMPLETE_RESPONSE") then
			SaveMissionLog(select(1,...),select(6,...))
		end
	end
	local f = CreateFrame("Frame")
	f:RegisterEvent("ADDON_LOADED")
	f:RegisterEvent("GARRISON_MISSION_COMPLETE_RESPONSE")
	f:SetScript("OnEvent", OnEvent)
end

People can exit/reload after completing some missions, then view and/or copy & paste the logs from WTF/Account/<account name>/SavedVariables/VenturePlanSoDMissions.lua. As this need is quite basic, it's not optimized for size or encoded, and it wipes previous logs so that it only saves logs from the current session.

zealvurte avatar Sep 01 '21 22:09 zealvurte

I tried your changes and I did get some logs at WTF/Account/{my_account_number}/SavedVariables/VenturePlanSoDMissions.lua. Here is the file VenturePlanSoDMissions.txt.

Great work!

xinye83 avatar Sep 02 '21 01:09 xinye83

Made a minor correction to the code, because it wasn't setting the missionName.

zealvurte avatar Sep 05 '21 05:09 zealvurte

Is there an easy way to analyze these logs? To check out these logs output by your changes above in https://orangeworks.se/ventureviz/ I've written a parser below to change the logs to json to analyze them (a single lua file ,not in addon)

local report = require("Log")
local s = ""
for _,v in pairs(VenturePlanSoDMissions_Logs) do
	if s ~= "" then
		s = s .. "\n"
	end
	v.missionName = "..."
	v.meta = {dv = 1,lc = "zhCN",ts = 18846,cb = 39653}
	v.predictionCorrect = true
	v.differentOutcome = true
	s = s .. lib:JSONEncode(v)
end

local file = io.open("output.txt","w+")
file:write(s)
file:close()

LostTemple1990 avatar Sep 09 '21 07:09 LostTemple1990

Yeah, I've also been parsing them to JSON and adding the 2 missing fields that the visualiser expects.

Unfortunately I can't provide the code I use for comparing a sim to the the log as it uses a lot of modifications to VP. I'll add some info to https://github.com/LostTemple1990/Issues-of-self-debugged-VenturePlan/issues/8 that will hopefully help you out in writing something similar.

zealvurte avatar Sep 09 '21 08:09 zealvurte