Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
enabled option to log to file (PokemonGoF#5881)
Browse files Browse the repository at this point in the history
  • Loading branch information
pogarek authored and solderzzc committed Jan 19, 2017
1 parent efda870 commit ce54971
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
1 change: 1 addition & 0 deletions configs/config.json.optimizer.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"action_wait_max": 5,
"transfer": true,
"evolve": true,
"debug": false,
"evolve_to_final": true,
"evolve_time": 25,
"evolve_for_xp": true,
Expand Down
3 changes: 3 additions & 0 deletions docs/pokemon_optimizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ There is only one pass at each action.

It will also collect the candies from your Buddy and select the next buddy.

In case that logging will be enabled, look for .log file in data folder.

[[back to top](#pokemon-optimizer)]

# Configuration
Expand All @@ -53,6 +55,7 @@ It will also collect the candies from your Buddy and select the next buddy.
"enabled": true,
"min_slots_left": 5,
"action_wait_min": 3,
"debug": false,
"action_wait_max": 5,
"transfer": true,
"evolve": true,
Expand Down
37 changes: 21 additions & 16 deletions pokemongo_bot/cell_workers/pokemon_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import math
import os
import time
import datetime

from pokemongo_bot import inventory
from pokemongo_bot.base_dir import _base_dir
Expand All @@ -32,6 +33,7 @@ def initialize(self):
self.last_pokemon_count = 0
self.pokemon_names = [p.name for p in inventory.pokemons().STATIC_DATA]
self.evolution_map = {}
self.debug = self.config.get('debug', False)
self.ongoing_stardust_count = 0
self.buddy = None
self.buddyid = 0
Expand All @@ -46,13 +48,14 @@ def initialize(self):
if self.config.get("keep", None) is not None:
raise ConfigException("Pokemon Optimizer configuration has changed. See docs/pokemon_optimized.md or configs/config.json.optimizer.example")

# log_file_path = os.path.join(_base_dir, "data", "pokemon-optimizer-%s.log" % self.bot.config.username)
#
# with open(log_file_path, "a") as _:
# pass
#
# self.log_file = open(log_file_path, "r+")
# self.log_file.seek(0, 2)
if self.debug:
log_file_path = os.path.join(_base_dir, "data", "pokemon-optimizer-%s.log" % self.bot.config.username)

with open(log_file_path, "a") as _:
pass

self.log_file = open(log_file_path, "r+")
self.log_file.seek(0, 2)

self.config_min_slots_left = self.config.get("min_slots_left", 5)
self.config_action_wait_min = self.config.get("action_wait_min", 3)
Expand Down Expand Up @@ -98,12 +101,12 @@ def initialize(self):
if pokemon.prev_evolutions_all:
self.config_groups["with_previous_evolution"].append(pokemon.name)

# def log(self, txt):
# if self.log_file.tell() >= 1024 * 1024:
# self.log_file.seek(0, 0)
#
# self.log_file.write("[%s] %s\n" % (datetime.datetime.now().isoformat(str(" ")), txt))
# self.log_file.flush()
def log(self, txt):
if self.log_file.tell() >= 1024 * 1024:
self.log_file.seek(0, 0)

self.log_file.write("[%s] %s\n" % (datetime.datetime.now().isoformat(str(" ")), txt))
self.log_file.flush()

def get_pokemon_slot_left(self):
pokemon_count = inventory.Pokemons.get_space_used()
Expand Down Expand Up @@ -364,8 +367,9 @@ def get_family_id(self, pokemon):
def score_and_sort(self, pokemon_list, rule):
pokemon_list = list(pokemon_list)

# self.log("Pokemon %s" % pokemon_list)
# self.log("Rule %s" % rule)
if self.debug:
self.log("Pokemon %s" % pokemon_list)
self.log("Rule %s" % rule)

for pokemon in pokemon_list:
setattr(pokemon, "__score__", self.get_score(pokemon, rule))
Expand Down Expand Up @@ -405,7 +409,8 @@ def get_score(self, pokemon, rule):
may_buddy &= pokemon.in_fort is False
may_buddy &= self.satisfy_requirements(pokemon, may_buddy)

# self.log("%s %s %s %s %s %s" % (pokemon, tuple(score), keep, may_try_evolve, may_try_upgrade, may_buddy))
if self.debug:
self.log("%s %s %s %s %s %s" % (pokemon, tuple(score), keep, may_try_evolve, may_try_upgrade, may_buddy))

return tuple(score), keep, may_try_evolve, may_try_upgrade, may_buddy

Expand Down

0 comments on commit ce54971

Please sign in to comment.