publish eve_rock_watcher.py
This commit is contained in:
parent
48fd3bcb17
commit
8ac0b3fbd3
1 changed files with 25 additions and 7 deletions
|
|
@ -179,9 +179,11 @@ def main():
|
||||||
_snip_to_rock(cp)
|
_snip_to_rock(cp)
|
||||||
return
|
return
|
||||||
|
|
||||||
poll = cp.getint("rock", "poll_secs", fallback=5) if cp.has_section("rock") else 5
|
sec = cp.has_section("rock")
|
||||||
switch_secs = cp.getint("rock", "switch_secs", fallback=45) if cp.has_section("rock") else 45
|
poll = cp.getint("rock", "poll_secs", fallback=5) if sec else 5
|
||||||
cooldown = cp.getint("rock", "cooldown_secs", fallback=60) if cp.has_section("rock") else 60
|
switch_secs = cp.getint("rock", "switch_secs", fallback=45) if sec else 45
|
||||||
|
cooldown = cp.getint("rock", "cooldown_secs", fallback=60) if sec else 60
|
||||||
|
status_secs = cp.getint("rock", "status_secs", fallback=90) if sec else 90
|
||||||
|
|
||||||
if "--test" in sys.argv:
|
if "--test" in sys.argv:
|
||||||
import pytesseract
|
import pytesseract
|
||||||
|
|
@ -205,6 +207,7 @@ def main():
|
||||||
print(f"[rock] started; switch<{switch_secs}s, poll {poll}s (waits for !mining on)")
|
print(f"[rock] started; switch<{switch_secs}s, poll {poll}s (waits for !mining on)")
|
||||||
tracker = Tracker()
|
tracker = Tracker()
|
||||||
last_alert = {}
|
last_alert = {}
|
||||||
|
last_status = 0.0
|
||||||
region = None
|
region = None
|
||||||
while True:
|
while True:
|
||||||
if not w.bot_mining(cp): # only during a mining session
|
if not w.bot_mining(cp): # only during a mining session
|
||||||
|
|
@ -228,23 +231,38 @@ def main():
|
||||||
now = time.time()
|
now = time.time()
|
||||||
keyed = tracker.update(rows, now)
|
keyed = tracker.update(rows, now)
|
||||||
hr = hold_rate()
|
hr = hold_rate()
|
||||||
|
actives = [] # (key, ore, units, tleft)
|
||||||
for key, ore, units in keyed:
|
for key, ore, units in keyed:
|
||||||
r = tracker.rate(key) # measured units/sec
|
r = tracker.rate(key) # measured units/sec
|
||||||
if r <= 0 and len(keyed) == 1 and hr > 0 and ORE_VOL.get(ore):
|
if r <= 0 and len(keyed) == 1 and hr > 0 and ORE_VOL.get(ore):
|
||||||
r = hr / 60.0 / ORE_VOL[ore] # single-rock hold-fill fallback
|
r = hr / 60.0 / ORE_VOL[ore] # single-rock hold-fill fallback
|
||||||
if r <= 0:
|
if r <= 0:
|
||||||
continue
|
continue
|
||||||
tleft = units / r
|
actives.append((key, ore, units, units / r))
|
||||||
|
# the rock you're emptying = the one with the least time left
|
||||||
|
actives.sort(key=lambda x: x[3])
|
||||||
|
for key, ore, units, tleft in actives:
|
||||||
if tleft <= switch_secs and now - last_alert.get(key, 0) > cooldown:
|
if tleft <= switch_secs and now - last_alert.get(key, 0) > cooldown:
|
||||||
last_alert[key] = now
|
last_alert[key] = now
|
||||||
others = [(o, u) for (k, o, u) in keyed if k != key]
|
others = [(o, u) for (k, o, u) in keyed if k != key]
|
||||||
nxt = max(others, key=lambda x: x[1]) if others else None
|
nxt = max(others, key=lambda x: x[1]) if others else None
|
||||||
msg = (f"{ore.title()} rock ~{int(tleft)}s from empty "
|
empty_at = int(now + tleft)
|
||||||
f"({units:,} u left).")
|
msg = f"{ore.title()} rock empties <t:{empty_at}:R> ({units:,} u left)."
|
||||||
if nxt:
|
if nxt:
|
||||||
msg += f" Next: {nxt[0].title()} ({nxt[1]:,} u)."
|
msg += f" Switch to {nxt[0].title()} ({nxt[1]:,} u)."
|
||||||
w.notify(cp, "Switch rocks", msg, priority="high", tags="pick,gem")
|
w.notify(cp, "Switch rocks", msg, priority="high", tags="pick,gem")
|
||||||
print(f"[rock] ALERT {msg}")
|
print(f"[rock] ALERT {msg}")
|
||||||
|
# periodic live readout of the rock you're on (so you see the countdown)
|
||||||
|
if actives and not w.bot_muted(cp) and now - last_status >= status_secs:
|
||||||
|
key, ore, units, tleft = actives[0]
|
||||||
|
empty_at = int(now + tleft)
|
||||||
|
others = [(o, u) for (k, o, u) in keyed if k != key]
|
||||||
|
nxt = max(others, key=lambda x: x[1]) if others else None
|
||||||
|
line = f"🪨 {ore.title()} {units:,} u · empties <t:{empty_at}:R>"
|
||||||
|
if nxt:
|
||||||
|
line += f" · next: {nxt[0].title()} ({nxt[1]:,} u)"
|
||||||
|
w._discord(cp, "Mining — current rock", line)
|
||||||
|
last_status = now
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[rock] error: {e}")
|
print(f"[rock] error: {e}")
|
||||||
time.sleep(poll)
|
time.sleep(poll)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue