Skip to content

Commit

Permalink
Minor updates and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ercdndrs committed Feb 5, 2021
1 parent 7127832 commit 67fbaae
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 42 deletions.
6 changes: 3 additions & 3 deletions AutoMaxLair.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
85 changes: 46 additions & 39 deletions scripts/score_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
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
base_dir = dirname(dirname(abspath(__file__)))
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'
Expand Down Expand Up @@ -90,14 +92,49 @@ 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:
q (multiprocessing.Queue): The queue object used for multiprocessing.
"""

# 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)

Expand Down Expand Up @@ -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)
Expand All @@ -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.')

0 comments on commit 67fbaae

Please sign in to comment.