From f053ad50a8b858d8602c77a01ca4b2032d91680c Mon Sep 17 00:00:00 2001 From: walaoaaa1234 Date: Tue, 4 Apr 2017 12:50:21 +0800 Subject: [PATCH 1/9] Bulktransfer improvement. --- .../cell_workers/pokemon_optimizer.py | 98 +++++++++++++++---- 1 file changed, 77 insertions(+), 21 deletions(-) diff --git a/pokemongo_bot/cell_workers/pokemon_optimizer.py b/pokemongo_bot/cell_workers/pokemon_optimizer.py index f1264f5e3d..3dd622b41c 100644 --- a/pokemongo_bot/cell_workers/pokemon_optimizer.py +++ b/pokemongo_bot/cell_workers/pokemon_optimizer.py @@ -699,13 +699,15 @@ def transfer_pokemon(self, transfer): 4: 'ERROR_POKEMON_IS_EGG', 5: 'ERROR_POKEMON_IS_BUDDY' } - pokemons = list(transfer) if self.config_bulktransfer_enabled and len(pokemons) > 1: while len(pokemons) > 0: + action_delay(self.config_action_wait_min, self.config_action_wait_max) pokemon_ids = [] count = 0 + transfered = [] while len(pokemons) > 0 and count < self.config_max_bulktransfer: pokemon = pokemons.pop() + transfered.append(pokemon) pokemon_ids.append(pokemon.unique_id) count = count + 1 try: @@ -717,32 +719,86 @@ def transfer_pokemon(self, transfer): return False except Exception: return False - for pokemon in transfer: - candy = inventory.candies().get(pokemon.pokemon_id) + + for x in transfered: + candy = inventory.candies().get(x.pokemon_id) + + if self.config_transfer and (not self.bot.config.test): + candy.add(1) + + self.emit_event("pokemon_release", + formatted="Exchanged {pokemon} [IV {iv}] [CP {cp}] [{candy} candies]", + data={"pokemon": x.name, + "iv": x.iv, + "cp": x.cp, + "candy": candy.quantity}) - if self.config_transfer and (not self.bot.config.test): - candy.add(1) - - self.emit_event("pokemon_release", - formatted="Exchanged {pokemon} [IV {iv}] [CP {cp}] [{candy} candies]", - data={"pokemon": pokemon.name, - "iv": pokemon.iv, - "cp": pokemon.cp, - "candy": candy.quantity}) + if self.config_transfer: + inventory.pokemons().remove(x.unique_id) - if self.config_transfer: - inventory.pokemons().remove(pokemon.unique_id) + with self.bot.database as db: + cursor = db.cursor() + cursor.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='transfer_log'") - with self.bot.database as db: - cursor = db.cursor() - cursor.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='transfer_log'") + db_result = cursor.fetchone() - db_result = cursor.fetchone() + if db_result[0] == 1: + db.execute("INSERT INTO transfer_log (pokemon, iv, cp) VALUES (?, ?, ?)", (x.name, x.iv, x.cp)) - if db_result[0] == 1: - db.execute("INSERT INTO transfer_log (pokemon, iv, cp) VALUES (?, ?, ?)", (pokemon.name, pokemon.iv, pokemon.cp)) + else:error_codes = { + 0: 'UNSET', + 1: 'SUCCESS', + 2: 'POKEMON_DEPLOYED', + 3: 'FAILED', + 4: 'ERROR_POKEMON_IS_EGG', + 5: 'ERROR_POKEMON_IS_BUDDY' + } + if self.config_bulktransfer_enabled and len(pokemons) > 1: + while len(pokemons) > 0: + action_delay(self.config_action_wait_min, self.config_action_wait_max) + pokemon_ids = [] + count = 0 + transfered = [] + while len(pokemons) > 0 and count < self.config_max_bulktransfer: + pokemon = pokemons.pop() + transfered.append(pokemon) + pokemon_ids.append(pokemon.unique_id) + count = count + 1 + try: + if self.config_transfer: + response_dict = self.bot.api.release_pokemon(pokemon_ids=pokemon_ids) + result = response_dict['responses']['RELEASE_POKEMON']['result'] + if result != 1: + self.logger.error(u'Error while transfer pokemon: {}'.format(error_codes[result])) + return False + except Exception: + return False + + for x in transfered: + candy = inventory.candies().get(x.pokemon_id) + + if self.config_transfer and (not self.bot.config.test): + candy.add(1) + + self.emit_event("pokemon_release", + formatted="Exchanged {pokemon} [IV {iv}] [CP {cp}] [{candy} candies]", + data={"pokemon": x.name, + "iv": x.iv, + "cp": x.cp, + "candy": candy.quantity}) + + if self.config_transfer: + inventory.pokemons().remove(x.unique_id) + + with self.bot.database as db: + cursor = db.cursor() + cursor.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='transfer_log'") + + db_result = cursor.fetchone() + + if db_result[0] == 1: + db.execute("INSERT INTO transfer_log (pokemon, iv, cp) VALUES (?, ?, ?)", (x.name, x.iv, x.cp)) - action_delay(self.config_action_wait_min, self.config_action_wait_max) else: for pokemon in pokemons: if self.config_transfer and (not self.bot.config.test): From 23cf321f66df5e8eadfb14905fad322d196fb7ac Mon Sep 17 00:00:00 2001 From: walaoaaa1234 Date: Tue, 4 Apr 2017 12:55:32 +0800 Subject: [PATCH 2/9] Revert "Bulktransfer improvement." This reverts commit f053ad50a8b858d8602c77a01ca4b2032d91680c. --- .../cell_workers/pokemon_optimizer.py | 98 ++++--------------- 1 file changed, 21 insertions(+), 77 deletions(-) diff --git a/pokemongo_bot/cell_workers/pokemon_optimizer.py b/pokemongo_bot/cell_workers/pokemon_optimizer.py index 3dd622b41c..f1264f5e3d 100644 --- a/pokemongo_bot/cell_workers/pokemon_optimizer.py +++ b/pokemongo_bot/cell_workers/pokemon_optimizer.py @@ -699,15 +699,13 @@ def transfer_pokemon(self, transfer): 4: 'ERROR_POKEMON_IS_EGG', 5: 'ERROR_POKEMON_IS_BUDDY' } + pokemons = list(transfer) if self.config_bulktransfer_enabled and len(pokemons) > 1: while len(pokemons) > 0: - action_delay(self.config_action_wait_min, self.config_action_wait_max) pokemon_ids = [] count = 0 - transfered = [] while len(pokemons) > 0 and count < self.config_max_bulktransfer: pokemon = pokemons.pop() - transfered.append(pokemon) pokemon_ids.append(pokemon.unique_id) count = count + 1 try: @@ -719,86 +717,32 @@ def transfer_pokemon(self, transfer): return False except Exception: return False - - for x in transfered: - candy = inventory.candies().get(x.pokemon_id) - - if self.config_transfer and (not self.bot.config.test): - candy.add(1) - - self.emit_event("pokemon_release", - formatted="Exchanged {pokemon} [IV {iv}] [CP {cp}] [{candy} candies]", - data={"pokemon": x.name, - "iv": x.iv, - "cp": x.cp, - "candy": candy.quantity}) - - if self.config_transfer: - inventory.pokemons().remove(x.unique_id) - - with self.bot.database as db: - cursor = db.cursor() - cursor.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='transfer_log'") - - db_result = cursor.fetchone() - - if db_result[0] == 1: - db.execute("INSERT INTO transfer_log (pokemon, iv, cp) VALUES (?, ?, ?)", (x.name, x.iv, x.cp)) + for pokemon in transfer: + candy = inventory.candies().get(pokemon.pokemon_id) - else:error_codes = { - 0: 'UNSET', - 1: 'SUCCESS', - 2: 'POKEMON_DEPLOYED', - 3: 'FAILED', - 4: 'ERROR_POKEMON_IS_EGG', - 5: 'ERROR_POKEMON_IS_BUDDY' - } - if self.config_bulktransfer_enabled and len(pokemons) > 1: - while len(pokemons) > 0: - action_delay(self.config_action_wait_min, self.config_action_wait_max) - pokemon_ids = [] - count = 0 - transfered = [] - while len(pokemons) > 0 and count < self.config_max_bulktransfer: - pokemon = pokemons.pop() - transfered.append(pokemon) - pokemon_ids.append(pokemon.unique_id) - count = count + 1 - try: - if self.config_transfer: - response_dict = self.bot.api.release_pokemon(pokemon_ids=pokemon_ids) - result = response_dict['responses']['RELEASE_POKEMON']['result'] - if result != 1: - self.logger.error(u'Error while transfer pokemon: {}'.format(error_codes[result])) - return False - except Exception: - return False - - for x in transfered: - candy = inventory.candies().get(x.pokemon_id) - - if self.config_transfer and (not self.bot.config.test): - candy.add(1) - - self.emit_event("pokemon_release", - formatted="Exchanged {pokemon} [IV {iv}] [CP {cp}] [{candy} candies]", - data={"pokemon": x.name, - "iv": x.iv, - "cp": x.cp, - "candy": candy.quantity}) + if self.config_transfer and (not self.bot.config.test): + candy.add(1) + + self.emit_event("pokemon_release", + formatted="Exchanged {pokemon} [IV {iv}] [CP {cp}] [{candy} candies]", + data={"pokemon": pokemon.name, + "iv": pokemon.iv, + "cp": pokemon.cp, + "candy": candy.quantity}) - if self.config_transfer: - inventory.pokemons().remove(x.unique_id) + if self.config_transfer: + inventory.pokemons().remove(pokemon.unique_id) - with self.bot.database as db: - cursor = db.cursor() - cursor.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='transfer_log'") + with self.bot.database as db: + cursor = db.cursor() + cursor.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='transfer_log'") - db_result = cursor.fetchone() + db_result = cursor.fetchone() - if db_result[0] == 1: - db.execute("INSERT INTO transfer_log (pokemon, iv, cp) VALUES (?, ?, ?)", (x.name, x.iv, x.cp)) + if db_result[0] == 1: + db.execute("INSERT INTO transfer_log (pokemon, iv, cp) VALUES (?, ?, ?)", (pokemon.name, pokemon.iv, pokemon.cp)) + action_delay(self.config_action_wait_min, self.config_action_wait_max) else: for pokemon in pokemons: if self.config_transfer and (not self.bot.config.test): From a04549484da16e0a5a2f5d78fec1ac57101dcfdd Mon Sep 17 00:00:00 2001 From: walaoaaa1234 Date: Tue, 4 Apr 2017 12:56:26 +0800 Subject: [PATCH 3/9] Bulktransfer improve --- .../cell_workers/pokemon_optimizer.py | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/pokemongo_bot/cell_workers/pokemon_optimizer.py b/pokemongo_bot/cell_workers/pokemon_optimizer.py index f1264f5e3d..3932c172f3 100644 --- a/pokemongo_bot/cell_workers/pokemon_optimizer.py +++ b/pokemongo_bot/cell_workers/pokemon_optimizer.py @@ -699,13 +699,15 @@ def transfer_pokemon(self, transfer): 4: 'ERROR_POKEMON_IS_EGG', 5: 'ERROR_POKEMON_IS_BUDDY' } - pokemons = list(transfer) if self.config_bulktransfer_enabled and len(pokemons) > 1: while len(pokemons) > 0: + action_delay(self.config_action_wait_min, self.config_action_wait_max) pokemon_ids = [] count = 0 + transfered = [] while len(pokemons) > 0 and count < self.config_max_bulktransfer: pokemon = pokemons.pop() + transfered.append(pokemon) pokemon_ids.append(pokemon.unique_id) count = count + 1 try: @@ -717,32 +719,32 @@ def transfer_pokemon(self, transfer): return False except Exception: return False - for pokemon in transfer: - candy = inventory.candies().get(pokemon.pokemon_id) - - if self.config_transfer and (not self.bot.config.test): - candy.add(1) - - self.emit_event("pokemon_release", - formatted="Exchanged {pokemon} [IV {iv}] [CP {cp}] [{candy} candies]", - data={"pokemon": pokemon.name, - "iv": pokemon.iv, - "cp": pokemon.cp, - "candy": candy.quantity}) + + for x in transfered: + candy = inventory.candies().get(x.pokemon_id) + + if self.config_transfer and (not self.bot.config.test): + candy.add(1) + + self.emit_event("pokemon_release", + formatted="Exchanged {pokemon} [IV {iv}] [CP {cp}] [{candy} candies]", + data={"pokemon": x.name, + "iv": x.iv, + "cp": x.cp, + "candy": candy.quantity}) - if self.config_transfer: - inventory.pokemons().remove(pokemon.unique_id) + if self.config_transfer: + inventory.pokemons().remove(x.unique_id) - with self.bot.database as db: - cursor = db.cursor() - cursor.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='transfer_log'") + with self.bot.database as db: + cursor = db.cursor() + cursor.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='transfer_log'") - db_result = cursor.fetchone() + db_result = cursor.fetchone() - if db_result[0] == 1: - db.execute("INSERT INTO transfer_log (pokemon, iv, cp) VALUES (?, ?, ?)", (pokemon.name, pokemon.iv, pokemon.cp)) + if db_result[0] == 1: + db.execute("INSERT INTO transfer_log (pokemon, iv, cp) VALUES (?, ?, ?)", (x.name, x.iv, x.cp)) - action_delay(self.config_action_wait_min, self.config_action_wait_max) else: for pokemon in pokemons: if self.config_transfer and (not self.bot.config.test): From 9840bfdf4821b59addae7407cbed7b959ec9052e Mon Sep 17 00:00:00 2001 From: walaoaaa1234 Date: Tue, 4 Apr 2017 13:03:06 +0800 Subject: [PATCH 4/9] Update bulktransfer docs --- docs/pokemon_optimizer.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/pokemon_optimizer.md b/docs/pokemon_optimizer.md index 9a0de8bbce..dbb28d6b1a 100644 --- a/docs/pokemon_optimizer.md +++ b/docs/pokemon_optimizer.md @@ -4,6 +4,8 @@ - [Default configuration](#default-configuration) - [Understand parameters](#understand-parameters) - [enabled](#enabled) + - [bulktransfer_enabled](#bulktransfer_enabled) + - [max_bulktransfer](#max_bulktransfer) - [min_slots_left](#min_slots_left) - [action_wait_min](#action_wait_min) - [action_wait_max](#action_wait_max) From 4705ee490ae7a7c035efdf3c2b8f89f8ee31c08d Mon Sep 17 00:00:00 2001 From: walaoaaa1234 Date: Tue, 4 Apr 2017 13:19:49 +0800 Subject: [PATCH 5/9] Update and fix docs --- docs/configuration_files.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/configuration_files.md b/docs/configuration_files.md index b72319682a..e58ca3a6ed 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -35,25 +35,25 @@ - [Example](#example) - [Sniping _(Sniper)_](#sniper) - [Description](#description) - - [Options](#options) + - [Options](#options-1) - [Example](#example) - [FollowPath Settings](#followpath-settings) - [Description](#description) - - [Options](#options) - - [Sample Configuration](#sample-configuration) + - [Options](#options-2) + - [Sample Configuration](#sample-configuration-1) - [UpdateLiveStats Settings](#updatelivestats-settings) - - [Options](#options) - - [Sample Configuration](#sample-configuration) + - [Options](#options-3) + - [Sample Configuration](#sample-configuration-2) - [UpdateLiveInventory Settings](#updateliveinventory-settings) - [Description](#description) - - [Options](#options) - - [Sample configuration](#sample-configuration) + - [Options](#options-4) + - [Sample configuration](#sample-configuration-3) - [Example console output](#example-console-output) - [UpdateHashStats Settings](#updatehashstats-settings) - [Description](#description) - - [Options](#options) - - [Sample configuration](#sample-configuration) - - [Example console output](#example-console-output) + - [Options](#options-5) + - [Sample configuration](#sample-configuration-4) + - [Example console output](#example-console-output-1) - [Random Pause](#random-pause) - [Egg Incubator](#egg-incubator) - [ShowBestPokemon](#showbestpokemon) From 12ef062c7f0ef3781613868ae4cf423a4e19867e Mon Sep 17 00:00:00 2001 From: walaoaaa1234 Date: Tue, 4 Apr 2017 13:21:46 +0800 Subject: [PATCH 6/9] Docs --- docs/configuration_files.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/configuration_files.md b/docs/configuration_files.md index e58ca3a6ed..5e887a9de9 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -34,23 +34,23 @@ - [Options](#options) - [Example](#example) - [Sniping _(Sniper)_](#sniper) - - [Description](#description) + - [Description](#description-1) - [Options](#options-1) - [Example](#example) - [FollowPath Settings](#followpath-settings) - - [Description](#description) + - [Description](#description-2) - [Options](#options-2) - [Sample Configuration](#sample-configuration-1) - [UpdateLiveStats Settings](#updatelivestats-settings) - [Options](#options-3) - [Sample Configuration](#sample-configuration-2) - [UpdateLiveInventory Settings](#updateliveinventory-settings) - - [Description](#description) + - [Description](#description-3) - [Options](#options-4) - [Sample configuration](#sample-configuration-3) - [Example console output](#example-console-output) - [UpdateHashStats Settings](#updatehashstats-settings) - - [Description](#description) + - [Description](#description-4) - [Options](#options-5) - [Sample configuration](#sample-configuration-4) - [Example console output](#example-console-output-1) From 0ed2b4e2d6232c10942ef788cbd52a7655d961bf Mon Sep 17 00:00:00 2001 From: walaoaaa1234 Date: Tue, 4 Apr 2017 13:23:54 +0800 Subject: [PATCH 7/9] Fix --- docs/configuration_files.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/configuration_files.md b/docs/configuration_files.md index 5e887a9de9..5da0496dea 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -1147,7 +1147,7 @@ Simulates the random pause of the day (speaking to someone, getting into a store - `min_interval`: (HH:MM:SS) the minimum interval between each pause - `max_interval`: (HH:MM:SS) the maximum interval between each pause -###Example Config +### Example Config ``` { "type": "RandomPause", @@ -1160,7 +1160,7 @@ Simulates the random pause of the day (speaking to someone, getting into a store } ``` -##Egg Incubator +## Egg Incubator [[back to top](#table-of-contents)] Configure how the bot should use the incubators. @@ -1170,7 +1170,7 @@ Configure how the bot should use the incubators. - `infinite`: ([2], [2,5], [2,5,10], []) the type of egg the infinite (ie. unbreakable) incubator(s) can incubate. If set to [2,5], the incubator(s) can only incubate the 2km and 5km eggs. If set to [], the incubator(s) will not incubate any type of egg. - `breakable`: ([2], [2,5], [2,5,10], []) the type of egg the breakable incubator(s) can incubate. If set to [2,5], the incubator(s) can only incubate the 2km and 5km eggs. If set to [], the incubator(s) will not incubate any type of egg. -###Example Config +### Example Config ``` { "type": "IncubateEggs", From 4f8d8d52ef63affb5f0373176100f4cd885d504b Mon Sep 17 00:00:00 2001 From: walaoaaa1234 Date: Tue, 4 Apr 2017 13:25:56 +0800 Subject: [PATCH 8/9] Fix --- docs/configuration_files.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/configuration_files.md b/docs/configuration_files.md index 5da0496dea..791f8cca32 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -121,7 +121,7 @@ Pauses the execution of the bot every day for some time Simulates the user going to sleep every day for some time, the sleep time and the duration is changed every day by a random offset defined in the config file. -###Example Config +### Example Config ``` "sleep_schedule": { "enabled": true, @@ -436,7 +436,7 @@ Define a list of criteria to keep the best Pokemons according to those criteria. The list of criteria is the following:```'cp','iv', 'iv_attack', 'iv_defense', 'iv_stamina', 'moveset.attack_perfection', 'moveset.defense_perfection', 'hp', 'hp_max'``` -####Examples: +#### Examples: - Keep the top 25 Zubat with the best hp_max: From e2024f53266a465365a34503bdb6ed20c0dae318 Mon Sep 17 00:00:00 2001 From: walaoaaa1234 Date: Tue, 4 Apr 2017 15:04:05 +0800 Subject: [PATCH 9/9] Rename variable --- pokemongo_bot/cell_workers/pokemon_optimizer.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pokemongo_bot/cell_workers/pokemon_optimizer.py b/pokemongo_bot/cell_workers/pokemon_optimizer.py index 3932c172f3..34a7824841 100644 --- a/pokemongo_bot/cell_workers/pokemon_optimizer.py +++ b/pokemongo_bot/cell_workers/pokemon_optimizer.py @@ -720,21 +720,21 @@ def transfer_pokemon(self, transfer): except Exception: return False - for x in transfered: - candy = inventory.candies().get(x.pokemon_id) + for pokemon in transfered: + candy = inventory.candies().get(pokemon.pokemon_id) if self.config_transfer and (not self.bot.config.test): candy.add(1) self.emit_event("pokemon_release", formatted="Exchanged {pokemon} [IV {iv}] [CP {cp}] [{candy} candies]", - data={"pokemon": x.name, - "iv": x.iv, - "cp": x.cp, + data={"pokemon": pokemon.name, + "iv": pokemon.iv, + "cp": pokemon.cp, "candy": candy.quantity}) if self.config_transfer: - inventory.pokemons().remove(x.unique_id) + inventory.pokemons().remove(pokemon.unique_id) with self.bot.database as db: cursor = db.cursor() @@ -743,7 +743,7 @@ def transfer_pokemon(self, transfer): db_result = cursor.fetchone() if db_result[0] == 1: - db.execute("INSERT INTO transfer_log (pokemon, iv, cp) VALUES (?, ?, ?)", (x.name, x.iv, x.cp)) + db.execute("INSERT INTO transfer_log (pokemon, iv, cp) VALUES (?, ?, ?)", (pokemon.name, pokemon.iv, pokemon.cp)) else: for pokemon in pokemons: