riggnaros

Untitled

Jan 21st, 2020
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.02 KB | None | 0 0
  1. local _, ns = ...
  2.  
  3. -------------------------------------------------------------------------------
  4. -- Module Declaration
  5. --
  6.  
  7. local plugin = BigWigs:NewPlugin("Transcriptor")
  8. if not plugin then return end
  9.  
  10. -------------------------------------------------------------------------------
  11. -- Locals
  12. --
  13.  
  14. -- luacheck: globals Transcriptor TranscriptDB TranscriptIgnore
  15. local ipairs, next, print, split, trim = ipairs, next, print, string.split, string.trim
  16. local sort, concat, tremove, wipe = table.sort, table.concat, table.remove, table.wipe
  17. local tonumber, ceil, floor = tonumber, math.ceil, math.floor
  18.  
  19. local logging = nil
  20. local timer = nil
  21.  
  22. local temp = {}
  23. local function quartiles(t)
  24. wipe(temp)
  25. for i = 1, #t do
  26. local v = tonumber(t[i])
  27. if v then
  28. temp[#temp+1] = v
  29. elseif t[i]:find("/", nil, true) then
  30. local _,v = split("/", t[i])
  31. v = tonumber(v)
  32. if v then
  33. temp[#temp+1] = v
  34. end
  35. end
  36. end
  37. sort(temp)
  38. local count = #temp
  39.  
  40. -- stupid small data sets
  41. if count == 0 then
  42. return 0, 0, 0, 0, 0
  43. elseif count == 1 then
  44. local a = temp[1]
  45. return a, a, a, a, 1
  46. elseif count == 2 then
  47. local a, b = temp[1], temp[2]
  48. return a, b, a, b, 2
  49. end
  50.  
  51. local q1, q3
  52. if count % 2 == 0 then -- should i average or just use the inner indexes?
  53. q1 = (temp[ceil(count / 4)] + temp[ceil(count / 4) + 1]) / 2
  54. q3 = (temp[floor(count * .75)] + temp[floor(count * .75) + 1]) / 2
  55. else
  56. q1 = temp[ceil(count / 4)]
  57. q3 = temp[ceil(count * .75)]
  58. end
  59. return q1, q3, temp[1], temp[count], count
  60. end
  61.  
  62. local diffShort = {
  63. [1] = "5N",
  64. [2] = "5H",
  65. [3] = "10N",
  66. [4] = "25N",
  67. [5] = "10H",
  68. [6] = "25H",
  69. [7] = "25LFR",
  70. [8] = "5M+",
  71. [14] = "N",
  72. [15] = "H",
  73. [16] = "M",
  74. [17] = "LFR",
  75. [18] = "40E",
  76. [19] = "5E",
  77. [23] = "5M",
  78. [24] = "5TW",
  79. }
  80.  
  81. local function parseLogInfo(logName, log)
  82. -- logNameFormat = "[%s]@[%s] - Zone:%d Difficulty:%d,%s Type:%s " .. format("Version: %s.%s", wowVersion, buildRevision)
  83. -- "[2018-09-04]@[18:11:58] - Zone:1763 Difficulty:8,5Challenge Type:party Version: 8.0.1.27547"
  84. local year, month, day, hour, min, sec, map, diff, _, _, version = logName:match("^%[(%d+)-(%d+)-(%d+)%]@%[(%d+):(%d+):(%d+)%] %- Zone:(%d+) Difficulty:(%d+),(.+) Type:(.+) Version: (.+)$")
  85. if not version then
  86. -- try previous format
  87. -- logNameFormat = "[%s]@[%s] - %d/%d/%s/%s/%s@%s" .. format(" (%s) (%s.%s)", version, wowVersion, buildRevision)
  88. -- "[2017-06-20]@[23:26:47] - 1147/1676/Tomb of Sargeras/Tomb of Sargeras/The Twisting Nether@Heroic (v7.2.0) (7.2.5.24367)"
  89. year, month, day, hour, min, sec, map, diff, version = logName:match("^%[(%d+)-(%d+)-(%d+)%]@%[(%d+):(%d+):(%d+)%] %- %d+/(%d+)/.-/.-/.-@(.-) %(.-%) %((.-)%)$")
  90. end
  91. if not version then return end
  92.  
  93. local killed, encounter, duration = nil, nil, 0
  94. if log.COMBAT then
  95. -- should probably handle multiple encounters in one log, but meh
  96. for _, line in next, log.COMBAT do
  97. if line:find("ENCOUNTER_START", nil, true) or line:find("ENCOUNTER_END", nil, true) then
  98. -- "<1.94 23:38:46> [ENCOUNTER_START] ENCOUNTER_START#2051#Kil'jaeden#15#24"
  99. -- "<524.88 23:47:29> [ENCOUNTER_END] 2051#Kil'jaeden#15#24#1"
  100. encounter = line:match("%d+#(.-)#%d+#%d+")
  101. elseif line:find("BOSS_KILL", nil, true) then
  102. -- "<524.88 23:47:29> [BOSS_KILL] 2051#Kil'jaeden"
  103. encounter = line:match("#(.-)$")
  104. killed = true
  105. break
  106. end
  107. end
  108. end
  109. if log.total and #log.total > 0 then
  110. duration = tonumber(log.total[#log.total]:match("^<(.-)%s")) or 0
  111. end
  112.  
  113. local diffName = diffShort[tonumber(diff)] or GetDifficultyInfo(diff) or diff
  114. local zone = GetRealZoneText(map) or tostring(map)
  115. local info = ("%s - |cffffffff%s|r (%s)"):format(zone, encounter or UNKNOWN, diffName)
  116. local timestamp = time({day=day,month=month,year=year,hour=hour,min=min,sec=sec})
  117.  
  118. -- I should probably cache this stuff
  119. return info, timestamp, zone, encounter, killed, duration
  120. end
  121.  
  122. -------------------------------------------------------------------------------
  123. -- Locale
  124. --
  125.  
  126. local L = setmetatable({}, { __newindex = function(t, k, v) rawset(t, k, v == true and k or v) end })
  127. ns.L = L
  128.  
  129. L["Transcriptor"] = true
  130. L["Automatically start Transcriptor logging when you pull a boss and stop when you win or wipe."] = true
  131.  
  132. L["Your Transcriptor DB has been reset! You can still view the contents of the DB in your SavedVariables folder until you exit the game or reload your UI."] = true
  133. L["Transcriptor is currently using %.01f MB of memory. You should clear some logs or risk losing them."] = true
  134. L["Log deleted."] = true
  135.  
  136. L["Raid only"] = true
  137. L["Only enable logging while in a raid instance."] = true
  138. L["Start with pull timer"] = true
  139. L["Start Transcriptor logging from a pull timer at two seconds remaining."] = true
  140. L["Show spell cast details"] = true
  141. L["Include some spell stats and the time between casts in the log tooltip when available."] = true
  142. L["Delete short logs"] = true
  143. L["Automatically delete logs shorter than 30 seconds."] = true
  144. L["Keep one log per fight"] = true
  145. L["Only keep a log for the longest attempt or latest kill of an encounter."] = true
  146. L["Stored logs (%s / %s) - Click to delete"] = true
  147. L["No logs recorded"] = true
  148. L["%d stored events over %.01f seconds. %s"] = true
  149. L["Ignored Events"] = true
  150. L["Clear All"] = true
  151.  
  152. L.win = " |cff20ff20" .. _G.WIN .. "|r"
  153. L.failed = " |cffff2020" .. _G.FAILED .. "|r"
  154.  
  155. -------------------------------------------------------------------------------
  156. -- Options
  157. --
  158.  
  159. plugin.defaultDB = {
  160. enabled = false,
  161. onpull = false,
  162. details = false,
  163. delete = false,
  164. keepone = false,
  165. raid = false,
  166. }
  167.  
  168. local GetOptions
  169. do
  170. local function cmp(a, b) return a:match("%-(.*)") < b:match("%-(.*)") end
  171. local sorted = {}
  172. local timerEvents = {"SPELL_CAST_START", "SPELL_CAST_SUCCESS", "SPELL_AURA_APPLIED"}
  173.  
  174. local function GetDescription(info)
  175. local log = Transcriptor:Get(info.arg)
  176. if not log then return end
  177.  
  178. local numEvents = log.total and #log.total or 0
  179. if numEvents == 0 then return end
  180.  
  181. local duration = tonumber(log.total[numEvents]:match("^<(.-)%s")) or 0
  182. local desc = L["%d stored events over %.01f seconds. %s"]:format(numEvents, duration, "")
  183. if not log.TIMERS or not plugin.db.profile.details then
  184. return desc
  185. end
  186.  
  187. desc = ("%s\n"):format(desc)
  188. for _, event in ipairs(timerEvents) do
  189. if log.TIMERS[event] then
  190. desc = ("%s\n%s\n"):format(desc, event)
  191.  
  192. local spells = CopyTable(log.TIMERS[event])
  193. if spells[1] then
  194. -- un-funkify this shit (convert the new indexed table format back into a keyed table)
  195. for i = 1, #spells do
  196. local k, v = split("=", spells[i], 2)
  197. local spellName, spellId, npc = k:match("(.+)-(%d+)-(npc:%d+)") -- Armageddon-240910-npc:117269
  198. k = ("%s-%s-%s"):format(spellId, spellName, npc) -- 240910-Armageddon-npc:117269
  199. spells[k] = v
  200. spells[i] = nil
  201. end
  202. end
  203.  
  204. wipe(sorted)
  205. for spell in next, spells do sorted[#sorted + 1] = spell end
  206. sort(sorted, cmp)
  207. for _, spell in ipairs(sorted) do
  208. local spellId, spellName = split("-", spell, 2)
  209. local npc = spellName:match("-(npc:.+)")
  210. if npc then
  211. spellName = spellName:gsub("%-npc:.+$", "")
  212. npc = (" %s"):format(npc)
  213. end
  214. local values = {split(",", spells[spell])}
  215. local _, pull = split(":", tremove(values, 1))
  216. if #values == 0 then
  217. desc = ("%s|cfffed000%s (%d)%s|r | Count: |cff20ff20%d|r | From pull: |cff20ff20%.01f|r\n"):format(desc, spellName, spellId, npc or "", 1, pull)
  218. else
  219. -- use the lower and upper quartiles to find outliers
  220. local q1, q3, low, high, count = quartiles(values)
  221. if low == high then
  222. desc = ("%s|cfffed000%s (%d)%s|r | Count: |cff20ff20%d|r | From pull: |cff20ff20%.01f|r | CD: |cff20ff20%.01f|r\n"):format(desc, spellName, spellId, npc or "", count + 1, pull, low)
  223. else
  224. local iqr = q3 - q1
  225. local lower = q1 - (1.5 * iqr)
  226. local upper = q3 + (1.5 * iqr)
  227. local count, total = 0, 0
  228. for i = 1, #values do
  229. local v = tonumber(values[i])
  230. if not v then -- handle "stage" times
  231. if values[i+1] then
  232. local fromStage,fromLast = trim(values[i+1]):match("^(.+)/(.+)$")
  233. if fromLast then
  234. values[i] = ("|cffffff9a%s (+%s)|r"):format(values[i], fromStage)
  235. values[i+1] = fromLast
  236. end
  237. else
  238. values[i] = ("|cffffff9a%s|r"):format(values[i])
  239. end
  240. else
  241. if lower <= v and v <= upper then
  242. count = count + 1
  243. total = total + v
  244. else
  245. v = ("|cffff7f3f%s|r"):format(v) -- outlier
  246. end
  247. values[i] = v
  248. end
  249. if i % 24 == 0 then -- simple wrapping
  250. values[i] = ("\n %s"):format(values[i])
  251. end
  252. end
  253. desc = ("%s|cfffed000%s (%d)|r | Count: |cff20ff20%d|r | Avg: |cff20ff20%.01f|r | Min: |cff20ff20%.01f|r | Max: |cff20ff20%.01f|r | From pull: |cff20ff20%.01f|r\n %s\n"):format(desc, spellName, spellId, count + 1, total / count, low, high, pull, concat(values, ", "))
  254. end
  255. end
  256. end
  257. end
  258. end
  259.  
  260. return desc
  261. end
  262.  
  263.  
  264. local function get(info)
  265. return plugin.db.profile[info[#info]]
  266. end
  267. local function set(info, value)
  268. plugin.db.profile[info[#info]] = value
  269. end
  270. local function set_reboot(info, value)
  271. plugin.db.profile[info[#info]] = value
  272. plugin:Disable()
  273. plugin:Enable()
  274. end
  275. local function delete(info)
  276. if info.arg then
  277. Transcriptor:Clear(info.arg)
  278. else
  279. Transcriptor:ClearAll()
  280. end
  281. GameTooltip:Hide()
  282. collectgarbage()
  283. end
  284. local function disabled(info)
  285. return InCombatLockdown()
  286. end
  287.  
  288. local eventCategories = {
  289. PLAYER_REGEN_DISABLED = "COMBAT",
  290. PLAYER_REGEN_ENABLED = "COMBAT",
  291. ENCOUNTER_START = "COMBAT",
  292. ENCOUNTER_END = "COMBAT",
  293. BOSS_KILL = "COMBAT",
  294. CHAT_MSG_MONSTER_EMOTE = "MONSTER",
  295. CHAT_MSG_MONSTER_SAY = "MONSTER",
  296. CHAT_MSG_MONSTER_WHISPER = "MONSTER",
  297. CHAT_MSG_MONSTER_YELL = "MONSTER",
  298. CHAT_MSG_RAID_BOSS_EMOTE = "MONSTER",
  299. CHAT_MSG_RAID_BOSS_WHISPER = "MONSTER",
  300. RAID_BOSS_EMOTE = "MONSTER",
  301. RAID_BOSS_WHISPER = "MONSTER",
  302. UNIT_SPELLCAST_START = "UNIT_SPELLCAST",
  303. UNIT_SPELLCAST_STOP = "UNIT_SPELLCAST",
  304. UNIT_SPELLCAST_SUCCEEDED = "UNIT_SPELLCAST",
  305. UNIT_SPELLCAST_INTERRUPTED = "UNIT_SPELLCAST",
  306. UNIT_SPELLCAST_CHANNEL_START = "UNIT_SPELLCAST",
  307. UNIT_SPELLCAST_CHANNEL_STOP = "UNIT_SPELLCAST",
  308. ZONE_CHANGED = "ZONE_CHANGED",
  309. ZONE_CHANGED_INDOORS = "ZONE_CHANGED",
  310. ZONE_CHANGED_NEW_AREA = "ZONE_CHANGED",
  311. SCENARIO_UPDATE = "SCENARIO",
  312. SCENARIO_CRITERIA_UPDATE = "SCENARIO",
  313. PLAY_MOVIE = "MOVIE",
  314. CINEMATIC_START = "MOVIE",
  315. START_TIMER = "PVP",
  316. CHAT_MSG_BG_SYSTEM_HORDE = "PVP",
  317. CHAT_MSG_BG_SYSTEM_ALLIANCE = "PVP",
  318. CHAT_MSG_BG_SYSTEM_NEUTRAL = "PVP",
  319. ARENA_OPPONENT_UPDATE = "PVP",
  320. BigWigs_Message = "BigWigs",
  321. BigWigs_StartBar = "BigWigs",
  322. DBM_Announce = "DBM",
  323. DBM_TimerStart = "DBM",
  324. DBM_TimerStop = "DBM",
  325. }
  326.  
  327. function GetOptions()
  328. local logs = Transcriptor:GetAll()
  329. local count = 0
  330. for _ in next, logs do
  331. count = count + 1
  332. end
  333.  
  334. UpdateAddOnMemoryUsage()
  335. local mem = GetAddOnMemoryUsage("Transcriptor") / 1000
  336. mem = ("|cff%s%.01f MB|r"):format(mem > 60 and "ff2020" or "ffd200", mem)
  337.  
  338. local options = {
  339. name = L["Transcriptor"],
  340. type = "group",
  341. args = {
  342. heading = {
  343. type = "description",
  344. name = L["Automatically start Transcriptor logging when you pull a boss and stop when you win or wipe."].."\n",
  345. fontSize = "medium",
  346. width = "full",
  347. order = 1,
  348. },
  349. enabled = {
  350. type = "toggle",
  351. name = ENABLE,
  352. get = get,
  353. set = set_reboot,
  354. order = 2,
  355. },
  356. raid = {
  357. type = "toggle",
  358. name = L["Raid only"],
  359. desc = L["Only enable logging while in a raid instance."],
  360. get = get,
  361. set = set,
  362. order = 3,
  363. },
  364. onpull = {
  365. type = "toggle",
  366. name = L["Start with pull timer"],
  367. desc = L["Start Transcriptor logging from a pull timer at two seconds remaining."],
  368. get = get,
  369. set = set_reboot,
  370. order = 4,
  371. },
  372. delete = {
  373. type = "toggle",
  374. name = L["Delete short logs"],
  375. desc = L["Automatically delete logs shorter than 30 seconds."],
  376. get = get,
  377. set = set,
  378. order = 5,
  379. },
  380. keepone = {
  381. type = "toggle",
  382. name = L["Keep one log per fight"],
  383. desc = L["Only keep a log for the longest attempt or latest kill of an encounter."],
  384. get = get,
  385. set = set,
  386. order = 6,
  387. },
  388. details = {
  389. type = "toggle",
  390. name = L["Show spell cast details"],
  391. desc = L["Include some spell stats and the time between casts in the log tooltip when available."],
  392. get = get,
  393. set = set,
  394. order = 7,
  395. },
  396. clear = {
  397. type = "execute",
  398. name = L["Clear All"],
  399. func = delete,
  400. width = "full",
  401. disabled = disabled,
  402. hidden = function() return not next(logs) end,
  403. order = 8,
  404. },
  405. size = {
  406. type = "description",
  407. name = L["Stored logs (%s / %s) - Click to delete"]:format(count, mem),
  408. fontSize = "medium",
  409. width = "full",
  410. hidden = function() return not next(logs) end,
  411. order = 9,
  412. },
  413. -- part of the zone tree
  414. ignoredEvents = {
  415. type = "group",
  416. name = "|cffffffff"..L["Ignored Events"].."|r",
  417. get = function(info)
  418. local key = info[#info]
  419. return TranscriptIgnore[key]
  420. end,
  421. set = function(info, value)
  422. local key = info[#info]
  423. TranscriptIgnore[key] = value or nil
  424. end,
  425. order = -1,
  426. args = {
  427. reset = {
  428. type = "execute",
  429. name = RESET,
  430. func = function()
  431. wipe(TranscriptIgnore)
  432. end,
  433. width = "full",
  434. order = 0,
  435. },
  436. },
  437. },
  438. },
  439. }
  440.  
  441. local ignoredEvents = options.args.ignoredEvents.args
  442. for _, event in next, Transcriptor.events do
  443. local cat = eventCategories[event] or "GENERAL"
  444. if not ignoredEvents[cat] then
  445. ignoredEvents[cat] = {
  446. type = "group", inline = true,
  447. name = cat,
  448. args = {},
  449. }
  450. end
  451. ignoredEvents[cat].args[event] = {
  452. type = "toggle",
  453. name = event,
  454. width = "full",
  455. }
  456. end
  457.  
  458. for key, log in next, logs do
  459. local info, ts, zone, encounter, killed = parseLogInfo(key, log)
  460. local name
  461. if info then
  462. local result = killed and L.win or encounter and L.failed or ""
  463. name = ("[%s] %s%s"):format(date("%F %T", ts), info:gsub("^.- %- ", ""), result)
  464. else
  465. name = key
  466. zone = UNKNOWN
  467. end
  468.  
  469. if not options.args[zone] then
  470. options.args[zone] = {
  471. type = "group",
  472. name = zone,
  473. order = 10,
  474. args = {},
  475. }
  476. end
  477.  
  478. options.args[zone].args[key] = {
  479. type = "execute",
  480. name = name,
  481. desc = GetDescription,
  482. func = delete,
  483. arg = key,
  484. disabled = disabled,
  485. width = "full",
  486. order = ts,
  487. }
  488. end
  489.  
  490. return options
  491. end
  492. end
  493.  
  494. plugin.subPanelOptions = {
  495. key = "BigWigs: Transcriptor",
  496. name = L["Transcriptor"],
  497. options = GetOptions,
  498. }
  499.  
  500. -------------------------------------------------------------------------------
  501. -- Initialization
  502. --
  503.  
  504. local function Refresh()
  505. local ACR = LibStub("AceConfigRegistry-3.0", true)
  506. if ACR then -- make sure it's loaded (provided by BigWigs_Options)
  507. ACR:NotifyChange("BigWigs")
  508. end
  509. end
  510.  
  511. function plugin:BigWigs_ProfileUpdate()
  512. self:Disable()
  513. self:Enable()
  514. self:Refresh()
  515. end
  516.  
  517. function plugin:OnPluginEnable()
  518. -- cleanup old savedvars
  519. self.db.profile.ignoredEvents = nil
  520. self.db.global.ignoredEvents = nil
  521.  
  522. -- try to fix memory overflow error
  523. if Transcriptor and TranscriptDB == nil then
  524. print("\n|cffff2020" .. L["Your Transcriptor DB has been reset! You can still view the contents of the DB in your SavedVariables folder until you exit the game or reload your UI."])
  525. TranscriptDB = {}
  526. end
  527.  
  528. self:RegisterMessage("BigWigs_ProfileUpdate")
  529. if self.db.profile.enabled then
  530. if self.db.profile.onpull then
  531. self:RegisterMessage("BigWigs_StartPull")
  532. self:RegisterMessage("BigWigs_StopPull")
  533. end
  534. self:RegisterEvent("ENCOUNTER_START")
  535. self:RegisterEvent("ENCOUNTER_END")
  536. -- catch fights that have a module but don't use ENCOUNTER events
  537. self:RegisterMessage("BigWigs_OnBossEngage")
  538. self:RegisterMessage("BigWigs_OnBossWin")
  539. self:RegisterMessage("BigWigs_OnBossWipe")
  540. end
  541. self:RegisterEvent("PLAYER_REGEN_DISABLED", Refresh)
  542. self:RegisterEvent("PLAYER_REGEN_ENABLED", Refresh)
  543. end
  544.  
  545. function plugin:OnPluginDisable()
  546. if logging then
  547. self:Stop()
  548. end
  549. timer = nil
  550. end
  551.  
  552. SLASH_BigWigs_Transcriptor1 = "/bwts"
  553. SlashCmdList.BigWigs_Transcriptor = function()
  554. LibStub("AceConfigDialog-3.0"):Open("BigWigs", "BigWigs: Transcriptor")
  555. end
  556.  
  557. -------------------------------------------------------------------------------
  558. -- Event Handlers
  559. --
  560.  
  561. function plugin:BigWigs_StartPull(_, _, seconds)
  562. if seconds > 2 then
  563. self:CancelTimer(timer)
  564. timer = self:ScheduleTimer("Start", seconds-2)
  565. else
  566. self:Start()
  567. end
  568. end
  569.  
  570. function plugin:BigWigs_StopPull()
  571. if timer then
  572. self:CancelTimer(timer)
  573. timer = nil
  574. end
  575. end
  576.  
  577. function plugin:BigWigs_OnBossEngage(_, module, diff)
  578. if not module.engageId then
  579. self:Start()
  580. end
  581. end
  582.  
  583. function plugin:BigWigs_OnBossWin(_, module)
  584. if not module.engageId then
  585. self:ScheduleTimer("Stop", 5) -- catch the end events
  586. end
  587. end
  588.  
  589. function plugin:BigWigs_OnBossWipe(_, module)
  590. if not module.engageId then
  591. self:Stop()
  592. end
  593. end
  594.  
  595. function plugin:ENCOUNTER_START(_, id, name, diff, size)
  596. -- XXX this will start logging dungeons and shit for people without little wigs
  597. self:Start()
  598. end
  599.  
  600. function plugin:ENCOUNTER_END(_, id, name, diff, size, status)
  601. self:ScheduleTimer("Stop", 5) -- catch the end events
  602. end
  603.  
  604. function plugin:Start()
  605. local _, instanceType = GetInstanceInfo()
  606. if instanceType ~= "raid" and self.db.profile.raid then return end
  607.  
  608. if timer then
  609. self:CancelTimer(timer)
  610. timer = nil
  611. end
  612. -- stop your current log and start a new one
  613. if Transcriptor:IsLogging() and not logging then
  614. self:Stop(true)
  615. end
  616. if not Transcriptor:IsLogging() then
  617. Transcriptor:StartLog()
  618. logging = true
  619. end
  620. end
  621.  
  622. function plugin:Stop(silent)
  623. logging = nil
  624. if not Transcriptor:IsLogging() then return end
  625.  
  626. local logName = Transcriptor:StopLog()
  627.  
  628. if self.db.profile.delete and logName then
  629. local log = Transcriptor:Get(logName)
  630. if #log.total == 0 or tonumber(log.total[#log.total]:match("^<(.-)%s")) < 30 then
  631. Transcriptor:Clear(logName)
  632. print("|cffff2020" .. L["Log deleted."])
  633. logName = nil
  634. end
  635. end
  636.  
  637. if self.db.profile.keepone and logName then
  638. local log = Transcriptor:Get(logName)
  639. local encounter, _, _, _, isWin = parseLogInfo(logName, log)
  640. if isWin then
  641. -- delete previous logs
  642. for name, log in next, Transcriptor:GetAll() do
  643. local e = parseLogInfo(name, log)
  644. if name ~= logName and e == encounter then
  645. Transcriptor:Clear(logName)
  646. end
  647. end
  648. else
  649. -- keep the longest attempt or last kill
  650. local encounterLogs = {}
  651. local lastWin, lastWinTime = nil, nil
  652. local longLog, longLogTime = nil, nil
  653. for name, log in next, Transcriptor:GetAll() do
  654. local e, t, _, _, k, d = parseLogInfo(name, log)
  655. if e == encounter then
  656. encounterLogs[name] = true
  657. if k and (not lastWin or t > lastWinTime) then
  658. lastWin = name
  659. lastWinTime = t
  660. end
  661. if not longLog or d > longLogTime then
  662. longLog = name
  663. longLogTime = d
  664. end
  665. end
  666. end
  667. local winner = lastWin or longLog
  668. for name in next, encounterLogs do
  669. if name ~= winner then
  670. Transcriptor:Clear(name)
  671. end
  672. end
  673. end
  674. end
  675.  
  676. if not silent then
  677. -- check memory
  678. UpdateAddOnMemoryUsage()
  679. local mem = GetAddOnMemoryUsage("Transcriptor") / 1000
  680. if mem > 60 then
  681. print("\n|cffff2020" .. L["Transcriptor is currently using %.01f MB of memory. You should clear some logs or risk losing them."]:format(mem))
  682. end
  683. end
  684. end
Advertisement
Add Comment
Please, Sign In to add comment