Save stats to new file (#316)

This commit is contained in:
aeon0
2021-12-23 14:08:49 +01:00
committed by GitHub
parent 5f44213692
commit 269fd2246f
5 changed files with 26 additions and 30 deletions

1
.gitignore vendored
View File

@@ -20,4 +20,5 @@ config/custom.ini
.vs/
info_screenshots/
loot_screenshots/
stats/
.venv

View File

@@ -150,14 +150,12 @@ class IChar:
wait(0.3, 0.35)
keyboard.send(self._char_config["battle_command"])
wait(0.1, 0.19)
for _ in range(2):
mouse.click(button="right")
wait(self._cast_duration + 0.16, self._cast_duration + 0.18)
mouse.click(button="right")
wait(self._cast_duration + 0.16, self._cast_duration + 0.18)
keyboard.send(self._char_config["battle_orders"])
wait(0.1, 0.19)
for _ in range(2):
mouse.click(button="right")
wait(self._cast_duration + 0.16, self._cast_duration + 0.18)
mouse.click(button="right")
wait(self._cast_duration + 0.16, self._cast_duration + 0.18)
keyboard.send(self._char_config["weapon_switch"])
wait(0.3, 0.35)
# Make sure that we are back at the previous skill

View File

@@ -1,11 +1,12 @@
from logger import Logger
import time
import threading
import inspect
from beautifultable import BeautifulTable
from logger import Logger
from config import Config
from messenger import Messenger
from utils.misc import hms
import inspect
from beautifultable import BeautifulTable
from version import __version__
@@ -26,6 +27,7 @@ class GameStats:
self._failed_game_time = 0
self._location = None
self._location_stats = {}
self._stats_filename = f'stats_{time.strftime("%Y%m%d_%H%M%S")}.log'
def update_location(self, loc: str):
if self._location != loc:
@@ -76,8 +78,6 @@ class GameStats:
def log_merc_death(self):
self._merc_death_counter += 1
# TODO: That message comes up a bit often, either make a param for it or remove it completely
# self._send_message_thread(f"{self._config.general['name']}: Merc has died{self.get_location_msg()}")
if self._location is not None:
self._location_stats[self._location]["merc_deaths"] += 1
@@ -150,7 +150,14 @@ class GameStats:
totals["merc_deaths"] += stats["merc_deaths"]
totals["failed_runs"] += stats["failed_runs"]
table.rows.append([location, len(stats["items"]), stats["chickens"], stats["deaths"], stats["merc_deaths"], stats["failed_runs"]])
table.rows.append(["T" if self._config.general['discord_status_condensed'] else "Total", totals["items"], totals["chickens"], totals["deaths"], totals["merc_deaths"], totals["failed_runs"]])
table.rows.append([
"T" if self._config.general['discord_status_condensed'] else "Total",
totals["items"],
totals["chickens"],
totals["deaths"],
totals["merc_deaths"],
totals["failed_runs"]
])
if self._config.general['discord_status_condensed']:
table.columns.header = ["Run", "I", "C", "D", "MD", "F"]
else:
@@ -165,17 +172,18 @@ class GameStats:
def _save_stats_to_file(self):
msg = self._create_msg()
msg += "\nItems:"
msg += "\nItems:"
for location in self._location_stats:
stats = self._location_stats[location]
msg += f"\n {location}:"
for item_name in stats["items"]:
msg += f"\n {item_name}"
with open("stats.log", "w+") as f:
with open(f"stats/{self._stats_filename}", "w+") as f:
f.write(msg)
if __name__ == "__main__":
game_stats = GameStats()
game_stats.log_item_pickup("rune_12", True)
game_stats._save_stats_to_file()

View File

@@ -89,6 +89,7 @@ def main():
print(f"ERROR: Unkown logg_lvl {config.general['logg_lvl']}. Must be one of [info, debug]")
# Create folder for debug screenshots if they dont exist yet
os.system("mkdir stats")
if not os.path.exists("info_screenshots") and config.general["info_screenshots"]:
os.system("mkdir info_screenshots")
if not os.path.exists("loot_screenshots") and config.general["loot_screenshots"]:

View File

@@ -156,31 +156,19 @@ class UiManager():
:return: Bool if action was successful
"""
Logger.debug("Wait for Play button")
# To test the start_game() function seperatly, just run:
# (botty) >> python src/ui_manager.py
# then go to D2r window -> press "f11", you can exit with "f12"
while 1:
# grab img which will be used to search the "play button"
img = self._screen.grab()
# the template finder can be used to search for a specific template, in this case the play btn.
# it returns a bool value (True or False) if the button was found, and the position of it
# roi = Region of interest. It reduces the search area and can be adapted within game.ini
# by running >> python src/screen.py you can visualize all of the currently set region of interests
found_btn = self._template_finder.search(["PLAY_BTN", "PLAY_BTN_GRAY"], img, roi=self._config.ui_roi["offline_btn"], threshold=0.8, best_match=True)
found_btn_off = self._template_finder.search(["PLAY_BTN", "PLAY_BTN_GRAY"], img, roi=self._config.ui_roi["offline_btn"], threshold=0.8, best_match=True)
found_btn_on = self._template_finder.search(["PLAY_BTN", "PLAY_BTN_GRAY"], img, roi=self._config.ui_roi["online_btn"], threshold=0.8, best_match=True)
found_btn = found_btn_off if found_btn_off.valid else found_btn_on
if found_btn.name == "PLAY_BTN":
# We need to convert the position to monitor coordinates (e.g. if someone is using 2 monitors or windowed mode)
x, y = self._screen.convert_screen_to_monitor(found_btn.position)
Logger.debug(f"Found Play Btn")
mouse.move(x, y, randomize=[35, 7], delay_factor=[1.0, 1.8])
wait(0.1, 0.15)
mouse.click(button="left")
break
else:
found_btn = self._template_finder.search("PLAY_BTN", img, roi=self._config.ui_roi["online_btn"], threshold=0.8)
if found_btn.valid:
Logger.error("Botty only works for single player. Please switch to offline mode and restart botty!")
return False
time.sleep(3.0)
wait(2.0, 3.0)
difficulty=self._config.general["difficulty"].upper()
while 1: