Skip to content

Commit bfb3b4a

Browse files
authored
Merge pull request #795 from hanzi/benchmark-mode
Make it easier to benchmark encounters/hr on a route
2 parents 7fde935 + 160c9c8 commit bfb3b4a

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

modules/gui/debug_tabs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,7 @@ def _get_data(self):
11711171
"Session Time at 1×": f"{session_time_at_1x}",
11721172
"RNG Seed": hex(unpack_uint32(read_symbol("gRngValue"))),
11731173
"Encounters/h (at 1×)": context.stats.encounter_rate_at_1x,
1174+
"Encounters in Timing Log": len(context.stats._encounter_timestamps),
11741175
"Controller Stack": [controller.__qualname__ for controller in context.controller_stack],
11751176
"RTC": rtc.isoformat() if rtc is not None else None,
11761177
"Currently Running Actions": debug.action_stack,

modules/stats.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import sqlite3
23
import sys
34
import threading
@@ -611,8 +612,19 @@ def __init__(self, profile: "Profile"):
611612
self._pickup_items: dict[int, PickupItem] = self._get_pickup_items()
612613
self._base_data: dict[str, str | None] = self._get_base_data()
613614

614-
self._encounter_timestamps: deque[float] = deque(maxlen=100)
615-
self._encounter_frames: deque[int] = deque(maxlen=100)
615+
# Normally, the encounter rate is calculated based on the previous 100 encounters. Which
616+
# is accurate enough to get a rough idea of how fast things are going, and it means that
617+
# a long break in between encounters (due to changing modes, playing manually etc.) will
618+
# be flushed out reasonably soon.
619+
# But when trying to measure a more accurate encounters/hr for a given route, we need a
620+
# larger sample size because the encounter rate can fluctuate quite a bit in some modes.
621+
#
622+
# So rather than constantly having to edit this file, this allows setting the environment
623+
# variable `POKEBOT_ENCOUNTER_BENCHMARK` to anything but an empty string in order to
624+
# increase the sample size to 1,000.
625+
encounter_buffer_size = 1000 if os.getenv("POKEBOT_ENCOUNTER_BENCHMARK", "") != "" else 100
626+
self._encounter_timestamps: deque[float] = deque(maxlen=encounter_buffer_size)
627+
self._encounter_frames: deque[int] = deque(maxlen=encounter_buffer_size)
616628

617629
def set_data(self, key: str, value: str | None):
618630
self._execute_write("REPLACE INTO base_data (data_key, value) VALUES (?, ?)", (key, value))

0 commit comments

Comments
 (0)