From 67fbaae2252d2e1a9fc740a4433ae96327e49b83 Mon Sep 17 00:00:00 2001 From: ercdndrs Date: Thu, 4 Feb 2021 22:37:14 -0500 Subject: [PATCH] Minor updates and fixes --- AutoMaxLair.py | 6 +-- scripts/score_pokemon.py | 85 ++++++++++++++++++++++------------------ 2 files changed, 49 insertions(+), 42 deletions(-) diff --git a/AutoMaxLair.py b/AutoMaxLair.py index 2230688f..04233cb9 100644 --- a/AutoMaxLair.py +++ b/AutoMaxLair.py @@ -54,7 +54,7 @@ language = config['language']['LANGUAGE'] PHRASES = config[language] -ENABLE_DEBUG_LOGS = config['default']['ENABLE_DEBUG_LOGS'] == 'True' +ENABLE_DEBUG_LOGS = config['default']['ENABLE_DEBUG_LOGS'].lower() == 'true' def join(inst) -> str: @@ -72,7 +72,7 @@ def join(inst) -> str: inst.push_button(b'v', 1) inst.push_buttons( - (b'a', 1.5), (b'a', 1), (b'a', 1.5), (b'a', 4), (b'v', 1), (b'a', 5) + (b'a', 1.5), (b'a', 1), (b'a', 1.5), (b'a', 4), (b'v', 1), (b'a', 3) ) # Next, read what rental Pokemon are available to choose. @@ -316,7 +316,7 @@ def catch(inst) -> str: # Start by navigating to the ball selection screen inst.push_button(b'a', 2) # then navigate to the ball specified in the config file - while (inst.get_target_ball() != 'DEFAULT' + while (inst.get_target_ball().lower() != 'default' and inst.get_target_ball() not in inst.check_ball() ): inst.push_button(b'<', 2, 1) diff --git a/scripts/score_pokemon.py b/scripts/score_pokemon.py index 7730a836..08a83472 100644 --- a/scripts/score_pokemon.py +++ b/scripts/score_pokemon.py @@ -9,7 +9,7 @@ import os import pickle import sys -from automaxlair import matchup_scoring +import time # We need to import some things from the parent directory. from os.path import dirname, abspath @@ -17,6 +17,8 @@ sys.path.insert(1, base_dir) sys.path.insert(1, base_dir+'\\automaxlair') +from automaxlair import matchup_scoring # Needs to be lower than path insert. + # Config values for the log and multiprocessing. LOG_NAME = 'packagePokemon' @@ -90,7 +92,7 @@ def worker_init(q): logger.addHandler(qh) -def main(q): +def main(): """Main function that loads the Pokemon data files, uses a multiprocessing pool to compute their matchups, and saves the results. Parameters: @@ -98,6 +100,41 @@ def main(q): """ + # Configure the logger. + logger = logging.getLogger(LOG_NAME) + logger.setLevel(logging.DEBUG if ENABLE_DEBUG_LOGS else logging.INFO) + formatter = logging.Formatter( + '%(asctime)s | %(name)s | %(levelname)s: %(message)s' + ) + + # Configure the console, which will print logged information. + console = logging.StreamHandler() + console.setLevel(logging.INFO) + console.setFormatter(formatter) + + # Configure the file handler, which will save logged information. + fileHandler = logging.handlers.TimedRotatingFileHandler( + filename=os.path.join(base_dir, 'logs', 'packagePokemonScript.log'), + when='midnight', + backupCount=30 + ) + fileHandler.setFormatter(formatter) + fileHandler.setLevel(logging.DEBUG if ENABLE_DEBUG_LOGS else logging.INFO) + + # Add the handlers to the logger so that it will both print messages to the + # console as well as save them to a log file. + logger.addHandler(console) + logger.addHandler(fileHandler) + + # Configure the queue and listener that will receive information to be + # logged from all of the processes. + q = mp.Queue() + ql = logging.handlers.QueueListener(q, console, fileHandler) + ql.start() + + logger.info('Started scoring Pokemon.') + + with open(base_dir+'/data/rental_pokemon.pickle', 'rb') as rental_file: rental_pokemon = pickle.load(rental_file) @@ -125,6 +162,8 @@ def main(q): for key in rental_pokemon_scores: rental_pokemon_scores[key] /= (total_score/len(rental_pokemon)) + ql.stop() + # Pickle the score lookup tables for later use. with open(base_dir+'/data/boss_matchup_LUT.pickle', 'wb') as file: pickle.dump(boss_matchup_LUT, file) @@ -135,41 +174,9 @@ def main(q): if __name__ == '__main__': - - # Configure the logger. - logger = logging.getLogger(LOG_NAME) - logger.setLevel(logging.DEBUG if ENABLE_DEBUG_LOGS else logging.INFO) - formatter = logging.Formatter( - '%(asctime)s | %(name)s | %(levelname)s: %(message)s' - ) - - # Configure the console, which will print logged information. - console = logging.StreamHandler() - console.setLevel(logging.INFO) - console.setFormatter(formatter) - - # Configure the file handler, which will save logged information. - fileHandler = logging.handlers.TimedRotatingFileHandler( - filename=os.path.join('logs', 'packagePokemonScript.log'), - when='midnight', - backupCount=30 - ) - fileHandler.setFormatter(formatter) - fileHandler.setLevel(logging.DEBUG if ENABLE_DEBUG_LOGS else logging.INFO) - - # Add the handlers to the logger so that it will both print messages to the - # console as well as save them to a log file. - logger.addHandler(console) - logger.addHandler(fileHandler) - - # Configure the queue and listener that will receive information to be - # logged from all of the processes. - q = mp.Queue() - ql = logging.handlers.QueueListener(q, console, fileHandler) - ql.start() - # Call main, then clean up. - logger.info('Started scoring Pokemon.') - main(q) - ql.stop() - logger.info('Finished scoring Pokemon.') + start_time = time.time() + main() + end_time = time.time() + logger = logging.getLogger(LOG_NAME) + logger.info(f'Finished scoring Pokemon, taking {end_time - start_time} s.')