Skip to content

Commit

Permalink
Number of passage max in the follow path task (#4330)
Browse files Browse the repository at this point in the history
* Correct sort on keep best custom

* Some test on follow path

* Number lap max in followpath

* Sleep at end of follow path

* Add restart timer to follow path

* Add example for config path

* Update wiki for follow path, number of lap

* Add login back up after pause

* Forget comma in config path example
  • Loading branch information
supercourgette authored and solderzzc committed Aug 21, 2016
1 parent 9382550 commit 3436e9c
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 12 deletions.
7 changes: 5 additions & 2 deletions configs/config.json.path.example
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@
"config": {
"path_mode": "loop",
"path_start_mode": "first",
"path_file": "configs/path.example.json"
"path_file": "configs/path.example.json",
"number_lap": 10,
"timer_restart_min": "00:10:00",
"timer_restart_max": "00:20:00"

This comment has been minimized.

Copy link
@renato6660

renato6660 Aug 23, 2016

Qual

}
}
],
Expand Down Expand Up @@ -192,4 +195,4 @@
"// Example of keeping the 2 strongest (based on CP) and 3 best (based on IV) Zubat:": {},
"// Zubat": {"keep_best_cp": 2, "keep_best_iv": 3}
}
}
}
14 changes: 14 additions & 0 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,20 @@ Setting the `navigator.type` setting to `path` allows you to specify waypoints w

An example for a JSON file can be found in `configs/path.example.json`. GPX files can be exported from many online tools, such as gpsies.com.The bot loads the first segment of the first track.

#### Number of Laps

In the path navigator configuration task, add a maximum of passage above which the bot stop for a time before starting again. *Note that others tasks (such as SleepSchedule or RandomPause) can stop the bot before.*

- number_lap set-up the number of passage. **To allow for an infinity number of laps, set-up the number at -1**.

`"number_lap": 10` (will do 10 passages before stopping)
- timer_restart_min is the minimum time the bot stop before starting again (format Hours:Minutes:Seconds).

`"timer_restart_min": "00:10:00"` (will stop for a minimum of 10 minutes)
- timer_restart_max is the maximum time the bot stop before starting again (format Hours:Minutes:Seconds).

`"timer_restart_max": "00:20:00"` (will stop for a maximum of 10 minutes)

## Pokemon Nicknaming

A `nickname_template` can be specified for the `NicknamePokemon` task to allow a nickname template to be applied to all pokemon in the user's inventory. For example, a user wanting all their pokemon to have their IV values as their nickname could use a template `{iv_ads}`, which will cause their pokemon to be named something like `13/7/12` (depending on the pokemon's actual IVs).
Expand Down
16 changes: 16 additions & 0 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,22 @@ def _register_events(self):
'distance_unit' # optional
)
)
self.event_manager.register_event(
'path_lap_update',
parameters=(
'number_lap',
'number_lap_max'
)
)
self.event_manager.register_event(
'path_lap_end',
parameters=(
'duration',
'resume'
)
)


self.event_manager.register_event('location_cache_error')

self.event_manager.register_event('bot_start')
Expand Down
60 changes: 50 additions & 10 deletions pokemongo_bot/cell_workers/follow_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from pokemongo_bot.walkers.step_walker import StepWalker
from pgoapi.utilities import f2i
from random import uniform

from utils import getSeconds
from datetime import datetime as dt, timedelta

class FollowPath(BaseTask):
SUPPORTED_TASK_API_VERSION = 1
Expand All @@ -28,7 +29,16 @@ def _process_config(self):
self.path_file = self.config.get("path_file", None)
self.path_mode = self.config.get("path_mode", "linear")
self.path_start_mode = self.config.get("path_start_mode", "first")

self.number_lap_max = self.config.get("number_lap", -1) # if < 0, then the number is inf.
self.timer_restart_min = getSeconds(self.config.get("timer_restart_min", "00:20:00"))
self.timer_restart_max = getSeconds(self.config.get("timer_restart_max", "02:00:00"))

if self.timer_restart_min > self.timer_restart_max:
raise ValueError('path timer_restart_min is bigger than path timer_restart_max') #TODO there must be a more elegant way to do it...

#var not related to configs
self.number_lap = 0

def load_path(self):
if self.path_file is None:
raise RuntimeError('You need to specify a path file (json or gpx)')
Expand Down Expand Up @@ -100,6 +110,23 @@ def find_closest_point_idx(self, points):

return return_idx

def endLaps(self):
duration = int(uniform(self.timer_restart_min, self.timer_restart_max))
resume = dt.now() + timedelta(seconds=duration)

self.emit_event(
'path_lap_end',
formatted="Great job, lot of calories burned! Taking a break now for {duration}, will resume at {resume}.",
data={
'duration': str(timedelta(seconds=duration)),
'resume': resume.strftime("%H:%M:%S")
}
)

self.number_lap = 0 # at the end of the break, start again
sleep(duration)
self.bot.login()

def work(self):
last_lat = self.bot.api._position_lat
last_lng = self.bot.api._position_lng
Expand Down Expand Up @@ -132,14 +159,6 @@ def work(self):
lng
)

if dist <= 1 or (self.bot.config.walk_min > 0 and is_at_destination):
if (self.ptr + 1) == len(self.points):
self.ptr = 0
if self.path_mode == 'linear':
self.points = list(reversed(self.points))
else:
self.ptr += 1

self.emit_event(
'position_update',
formatted="Walking from {last_position} to {current_position}, distance left: ({distance} {distance_unit}) ..",
Expand All @@ -150,4 +169,25 @@ def work(self):
'distance_unit': 'm'
}
)

if dist <= 1 or (self.bot.config.walk_min > 0 and is_at_destination):
if (self.ptr + 1) == len(self.points):
self.ptr = 0
if self.path_mode == 'linear':
self.points = list(reversed(self.points))
if self.number_lap_max >= 0:
self.number_lap+=1
self.emit_event(
'path_lap_update',
formatted="number lap : {number_lap} / {number_lap_max}",
data={
'number_lap': str(self.number_lap),
'number_lap_max': str(self.number_lap_max)
}
)
if self.number_lap >= self.number_lap_max:
self.endLaps()
else:
self.ptr += 1

return [lat, lng]
18 changes: 18 additions & 0 deletions pokemongo_bot/cell_workers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import networkx as nx
import numpy as np

from datetime import datetime as dt, timedelta

init()

TIME_PERIODS = (
Expand Down Expand Up @@ -119,6 +121,22 @@ def format_dist(distance, unit):
return dist_to_str(convert(distance, 'm', unit), unit)


def getSeconds(strTime):
'''
Return the duration in seconds of a time string
:param strTime: string time of format %H:%M:%S
'''
try:
x = dt.strptime(strTime, '%H:%M:%S')
seconds = int(timedelta(hours=x.hour,minutes=x.minute,seconds=x.second).total_seconds())
except ValueError:
seconds = 0;

if seconds < 0:
seconds = 0;

return seconds

def format_time(seconds):
# Return a string displaying the time given as seconds or minutes
num, duration = 0, long(round(seconds))
Expand Down
2 changes: 2 additions & 0 deletions pokemongo_bot/event_handlers/colored_logging_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class ColoredLoggingHandler(EventHandler):
'unknown_spin_result': 'red',
'unset_pokemon_nickname': 'red',
'vip_pokemon': 'red',
'path_lap_end': 'green',
'log_stats': 'magenta',
'show_inventory': 'magenta',

Expand All @@ -86,6 +87,7 @@ class ColoredLoggingHandler(EventHandler):
'pokestop_out_of_range': 'white',
'polyline_request': 'white',
'position_update': 'white',
'path_lap_update': 'white',
'set_start_location': 'white',
'softban_fix': 'white',
'softban_log': 'magenta',
Expand Down

2 comments on commit 3436e9c

@renato6660
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quero miu

@renato6660
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??¿

Please sign in to comment.