From 2738cc2c3de0d18161ce24cd51697dddae018c77 Mon Sep 17 00:00:00 2001 From: derek-hirotsu <132305781+derek-hirotsu@users.noreply.github.com> Date: Tue, 5 Dec 2023 11:00:41 -0800 Subject: [PATCH] Add updated DOTA2 harness (#22) includes changes to improve accuracy of benchmark start and end times for trimming. --- CHANGELOG.md | 4 ++++ dota2/dota2.py | 25 ++++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 948823f..900628e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. Changes are grouped by the date they are merged to the main branch of the repository and are ordered from newest to oldest. Dates use the ISO 8601 extended calendar date format, i.e. YYYY-MM-DD. +## 2023-12-05 + +- Update strategies for marking benchmark start and end times in DOTA 2 test harness + ## 2023-11-23 - Fix issues with links in `CONTRIBUTING.MD` found by @chomes and @OwenHunter diff --git a/dota2/dota2.py b/dota2/dota2.py index 867b089..09afc28 100644 --- a/dota2/dota2.py +++ b/dota2/dota2.py @@ -5,7 +5,7 @@ import time import pyautogui as gui import pydirectinput as user import sys -from dota2_utils import get_resolution, copy_replay, copy_config, get_args, STEAM_GAME_ID +from dota2_utils import get_resolution, copy_replay, copy_config, get_args sys.path.insert(1, os.path.join(sys.path[0], '..')) @@ -24,6 +24,7 @@ from harness_utils.steam import exec_steam_game SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) LOG_DIRECTORY = os.path.join(SCRIPT_DIRECTORY, "run") PROCESS_NAME = "dota2.exe" +STEAM_GAME_ID = 570 setup_log_directory(LOG_DIRECTORY) logging.basicConfig(filename=f'{LOG_DIRECTORY}/harness.log', @@ -76,26 +77,36 @@ def run_benchmark(): console_command("exec_async benchmark") time.sleep(0.2) user.press("\\") + time.sleep(5) + if kerasService.wait_for_word(word="directed", timeout=30, interval=0.1) is None: + logging.error("Didn't see directed camera. Did the replay load?") + sys.exit(1) setup_end_time = time.time() elapsed_setup_time = round(setup_end_time - setup_start_time, 2) logging.info("Harness setup took %f seconds", elapsed_setup_time) - test_start_time = time.time() - + time.sleep(25) # TODO -> Mark benchmark start time using video OCR by looking for a players name - if kerasService.wait_for_word(word="directed", timeout=100, interval=0.5) is None: - logging.error("Game didn't start in time. Check settings and try again.") + if kerasService.wait_for_word(word="120", timeout=30, interval=0.1) is None: + logging.error("Didn't see the gold tick up to 120 to start the benchmark. Check settings and try again.") sys.exit(1) - time.sleep(100) # sleep duration during gameplay + test_start_time = time.time() + + time.sleep(75) # sleep duration during gameplay + + if kerasService.wait_for_word(word="430", timeout=30, interval=0.1) is None: + logging.error("Didn't see 430 Gold. Did the benchmark run?") + sys.exit(1) + test_end_time = time.time() + time.sleep(1) if kerasService.wait_for_word(word="heroes", timeout=25, interval=1) is None: logging.error("Main menu after running benchmark not found, exiting") sys.exit(1) logging.info("Run completed. Closing game.") - test_end_time = time.time() elapsed_test_time = round((test_end_time - test_start_time), 2) logging.info("Benchmark took %f seconds", elapsed_test_time)