From b5e2d2d223c5291adc412c2c88209ffd21c2688e Mon Sep 17 00:00:00 2001 From: Durel Date: Sat, 3 Feb 2018 15:34:17 -0500 Subject: [PATCH] 1) Updated background stat checking thread to pause when the user is idle. This should help improve estimates for each level's average spellup since we won't sample stats when the user isn't active. --- aard_inventory.xml | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/aard_inventory.xml b/aard_inventory.xml index 0a79c28..3b2133e 100644 --- a/aard_inventory.xml +++ b/aard_inventory.xml @@ -926,6 +926,9 @@ function setPending(msg) end -- setPending +drlLastCmdTime = os.time() +drlIdleTime = 60 * 15 -- 15 minutes of no commands --> we are idle +drlIsIdle = false function OnPluginSend(msg) local baseCommand @@ -952,6 +955,18 @@ function OnPluginSend(msg) return false end -- if + -- We have a valid command entered by the user and not something that the plugin is running + -- in the background. If we were in the idle state, drop out of idle and restart the statBonus + -- background thread. + drlLastCmdTime = dbot.getTime() + if drlIsIdle then + check (AddTimer(inv.statBonus.timer.name, 0, inv.statBonus.timer.min, inv.statBonus.timer.sec, "", + timer_flag.Enabled + timer_flag.Replace + timer_flag.OneShot, + "inv.statBonus.set")) + dbot.debug("Restarting stat bonus thread. We are out of idle!") + drlIsIdle = false + end -- if + -- If we are at this point, then we know that we don't have a "bypass" command. This means -- that we should either queue up the command if we are in a state where we are delaying -- command execution, or we should allow the command to go through as normal. @@ -15875,7 +15890,7 @@ end -- inv.statBonus.setSetupFn inv.statBonus.timer = {} inv.statBonus.timer.name = "drlInvStatBonusTimer" inv.statBonus.timer.min = 5 -inv.statBonus.timer.sec = 30 +inv.statBonus.timer.sec = 0 function inv.statBonus.timer.update(min, sec) min = tonumber(min or "") @@ -15887,9 +15902,18 @@ function inv.statBonus.timer.update(min, sec) dbot.debug("Scheduling stat bonus timer in " .. min .. " minutes, " .. sec .. " seconds") - check (AddTimer(inv.statBonus.timer.name, 0, min, sec, "", - timer_flag.Enabled + timer_flag.Replace + timer_flag.OneShot, - "inv.statBonus.set")) + -- If we are idle, don't keep scanning the spellup stats. They most likely aren't accurate at this + -- point and running the stats could keep someone logged in when they'd prefer to idle out. + local currentTime = dbot.getTime() + if (currentTime - drlLastCmdTime > drlIdleTime) then + dbot.debug("Halting statBonus thread. We are idle!") + drlIsIdle = true + else + check (AddTimer(inv.statBonus.timer.name, 0, min, sec, "", + timer_flag.Enabled + timer_flag.Replace + timer_flag.OneShot, + "inv.statBonus.set")) + end -- if + end -- inv.statBonus.timer.update