Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions config/config.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#port: # Port to listen on (default=5000)
#hash-key: # Key for hash server (default=None)
#accountcsv: # Load accounts instead from a CSV file containing "auth-service,username,password" lines.
#speed-scan # Use speed-scan as the search scheduler.
#location: # Location, can be an address or coordinates.
#step-limit: # Steps (default=10)
#scan-delay: # Time delay between requests in scan threads. (default=12)
Expand Down Expand Up @@ -54,10 +53,8 @@

#beehive # Use beehive configuration for multiple accounts, one account per hex.
# Make sure to keep -st under 5, and -w under the total amount of accounts available.
#spawnpoint-scanning # Use spawnpoint scanning (instead of hex grid).
# Scans in a circle based on step_limit when on DB.
# A spawnpoint-file can be added optinal as value for "spawnpoint-scanning".
#dump-spawnpoints # Dump the spawnpoints from the db to json (only for use with -ss).
#speed-scan # Use speed-scan as the search scheduler.
#dump-spawnpoints # Dump the spawnpoints from the db to spawnpoints.json


# Search settings
Expand Down
47 changes: 0 additions & 47 deletions docs/extras/Spawnpoint-Scanning-Scheduler.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/extras/Speed-Scheduler.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Speed Scheduler

Speed Scheduler is an alternative scheduler to Hex Scan or Spawnpoint Scan with a speed limit and full support for spawnpoint discovery, exact spawnpoint spawntime and duration identification, and automatic transition from spawnpoint discovery to identification to only scanning spawnpoints.
Speed Scheduler is an alternative scheduler to Hex Scan with a speed limit and full support for spawnpoint discovery, exact spawnpoint spawntime and duration identification, and automatic transition from spawnpoint discovery to identification to only scanning spawnpoints.

## Features

Expand Down
13 changes: 4 additions & 9 deletions docs/first-run/commandline.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
[-msl MIN_SECONDS_LEFT] [-dc] [-H HOST] [-P PORT]
[-L LOCALE] [-c] [-m MOCK] [-ns] [-os] [-sc] [-nfl] -k
GMAPS_KEY [--skip-empty] [-C] [-D DB] [-cd] [-np] [-ng]
[-nk] [-ss [SPAWNPOINT_SCANNING]] [-speed] [-kph KPH]
[-nk] [-speed] [-kph KPH]
[-hkph HLVL_KPH] [-ldur LURE_DURATION]
[--dump-spawnpoints] [-pd PURGE_DATA] [-px PROXY] [-pxsc]
[-pxt PROXY_TIMEOUT] [-pxd PROXY_DISPLAY]
Expand Down Expand Up @@ -218,8 +218,7 @@
Google Maps Javascript API Key. [env var:
POGOMAP_GMAPS_KEY]
--skip-empty Enables skipping of empty cells in normal scans -
requires previously populated database (not to be used
with -ss) [env var: POGOMAP_SKIP_EMPTY]
requires previously populated database [env var: POGOMAP_SKIP_EMPTY]
-C, --cors Enable CORS on web server. [env var: POGOMAP_CORS]
-D DB, --db DB Database filename for SQLite. [env var: POGOMAP_DB]
-cd, --clear-db Deletes the existing database before starting the
Expand All @@ -230,10 +229,6 @@
into local db). [env var: POGOMAP_NO_GYMS]
-nk, --no-pokestops Disables PokeStops from the map (including parsing
them into local db). [env var: POGOMAP_NO_POKESTOPS]
-ss [SPAWNPOINT_SCANNING], --spawnpoint-scanning [SPAWNPOINT_SCANNING]
Use spawnpoint scanning (instead of hex grid). Scans
in a circle based on step_limit when on DB. [env var:
POGOMAP_SPAWNPOINT_SCANNING]
-speed, --speed-scan Use speed scanning to identify spawn points and then
scan closest spawns. [env var: POGOMAP_SPEED_SCAN]
-kph KPH, --kph KPH Set a maximum speed in km/hour for scanner movement.
Expand All @@ -246,8 +241,8 @@
Change duration for lures set on pokestops. This is
useful for events that extend lure duration. [env var:
POGOMAP_LURE_DURATION]
--dump-spawnpoints Dump the spawnpoints from the db to json (only for use
with -ss). [env var: POGOMAP_DUMP_SPAWNPOINTS]
--dump-spawnpoints Dump the spawnpoints from the db to specified JSON file.
[env var: POGOMAP_DUMP_SPAWNPOINTS]
-pd PURGE_DATA, --purge-data PURGE_DATA
Clear Pokemon from database this many hours after they
disappear (0 to disable). [env var:
Expand Down
148 changes: 10 additions & 138 deletions pogom/schedulers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import logging
import math
import geopy
import json
import time
import sys
from timeit import default_timer
Expand All @@ -61,8 +60,8 @@
from datetime import datetime, timedelta
from .transform import get_new_coords
from .models import (hex_bounds, Pokemon, SpawnPoint, ScannedLocation,
ScanSpawnPoint)
from .utils import now, cur_sec, cellid, equi_rect_distance
ScanSpawnPoint, HashKeys)
from .utils import now, cellid, equi_rect_distance
from .altitude import get_altitude

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -334,138 +333,6 @@ def _generate_locations(self):
return locations


# Spawn Scan searches known spawnpoints at the specific time they spawn.
class SpawnScan(BaseScheduler):

def __init__(self, queues, status, args):
BaseScheduler.__init__(self, queues, status, args)
# On the first scan, we want to search the last 15 minutes worth of
# spawns to get existing pokemon onto the map.
self.firstscan = True

# If we are only scanning for pokestops/gyms, the scan radius can be
# 450m. Otherwise 70m.
if self.args.no_pokemon:
self.step_distance = 0.450
else:
self.step_distance = 0.070

self.step_limit = args.step_limit
self.locations = False

# Generate locations is called when the locations list is cleared - the
# first time it scans or after a location change.
def _generate_locations(self):
# Attempt to load spawns from file.
if self.args.spawnpoint_scanning != 'nofile':
log.debug('Loading spawn points from json file @ %s',
self.args.spawnpoint_scanning)
try:
with open(self.args.spawnpoint_scanning) as file:
self.locations = json.load(file)
except ValueError as e:
log.error('JSON error: %s; will fallback to database', repr(e))
except IOError as e:
log.error(
'Error opening json file: %s; will fallback to database',
repr(e))

# No locations yet? Try the database!
if not self.locations:
log.debug('Loading spawn points from database')
self.locations = Pokemon.get_spawnpoints_in_hex(
self.scan_location, self.args.step_limit)

# Well shit...
# if not self.locations:
# raise Exception('No availabe spawn points!')

# locations[]:
# {"lat": 37.53079079414139, "lng": -122.28811690874117,
# "spawnpoint_id": "808f9f1601d", "time": 511

log.info('Total of %d spawns to track', len(self.locations))

# locations.sort(key=itemgetter('time'))

if self.args.very_verbose:
for i in self.locations:
sec = i['time'] % 60
minute = (i['time'] / 60) % 60
m = 'Scan [{:02}:{:02}] ({}) @ {},{}'.format(
minute, sec, i['time'], i['lat'], i['lng'])
log.debug(m)

# 'time' from json and db alike has been munged to appearance time as
# seconds after the hour.
# Here we'll convert that to a real timestamp.
for location in self.locations:
# For a scan which should cover all CURRENT pokemon, we can offset
# the comparison time by 15 minutes so that the "appears" time
# won't be rolled over to the next hour.

# TODO: Make it work. The original logic (commented out) was
# producing bogus results if your first scan was in the last
# 15 minute of the hour. Wrapping my head around this isn't
# work right now, so I'll just drop the feature for the time
# being. It does need to come back so that
# repositioning/pausing works more nicely, but we can live
# without it too.

# if sps_scan_current:
# cursec = (location['time'] + 900) % 3600
# else:
cursec = location['time']

if cursec > cur_sec():
# Hasn't spawn in the current hour.
from_now = location['time'] - cur_sec()
appears = now() + from_now
else:
# Won't spawn till next hour.
late_by = cur_sec() - location['time']
appears = now() + 3600 - late_by

location['appears'] = appears
location['leaves'] = appears + 900

# Put the spawn points in order of next appearance time.
self.locations.sort(key=itemgetter('appears'))

# Match expected structure:
# locations = [((lat, lng, alt), ts_appears, ts_leaves),...]
retset = []
for step, location in enumerate(self.locations, 1):
altitude = get_altitude(self.args, [location['lat'],
location['lng']])
retset.append((step, (location['lat'], location['lng'], altitude),
location['appears'], location['leaves']))

return retset

# Schedule the work to be done.
def schedule(self):
if not self.scan_location:
log.warning(
'Cannot schedule work until scan location has been set')
return

# SpawnScan needs to calculate the list every time, since the times
# will change.
self.locations = self._generate_locations()

for location in self.locations:
# FUTURE IMPROVEMENT - For now, queues is assumed to have a single
# queue.
self.queues[0].put(location)
log.debug("Added location {}".format(location))

# Clear the locations list so it gets regenerated next cycle.
self.size = len(self.locations)
self.locations = None
self.ready = True


# SpeedScan is a complete search method that initially does a spawnpoint
# search in each scan location by scanning five two-minute bands within
# an hour and ten minute intervals between bands.
Expand Down Expand Up @@ -1160,7 +1027,6 @@ class SchedulerFactory():
__schedule_classes = {
"hexsearch": HexSearch,
"hexsearchspawnpoint": HexSearchSpawnpoint,
"spawnscan": SpawnScan,
"speedscan": SpeedScan,
}

Expand All @@ -1180,18 +1046,24 @@ def get_scheduler(name, *args, **kwargs):
# server keys.
class KeyScheduler(object):

def __init__(self, keys):
def __init__(self, keys, db_updates_queue):
self.keys = {}
for key in keys:
self.keys[key] = {
'remaining': 0,
'maximum': 0,
'peak': 0
'peak': 0,
'expires': None
}

self.key_cycle = itertools.cycle(keys)
self.curr_key = ''

hashkeys = self.keys
for key in hashkeys:
hashkeys[key]['key'] = key
db_updates_queue.put((HashKeys, hashkeys))

def keys(self):
return self.keys

Expand Down
17 changes: 5 additions & 12 deletions pogom/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,14 @@ def get_args():
help=('Disables PokeStops from the map (including ' +
'parsing them into local db).'),
action='store_true', default=False)
parser.add_argument('-ss', '--spawnpoint-scanning',
help=('Use spawnpoint scanning (instead of hex ' +
'grid). Scans in a circle based on step_limit ' +
'when on DB.'),
nargs='?', const='nofile', default=False)
parser.add_argument('-speed', '--speed-scan',
help=('Use speed scanning to identify spawn points ' +
'and then scan closest spawns.'),
action='store_true', default=False)
parser.add_argument('--dump-spawnpoints',
help=('Dump the spawnpoints from the db to the ' +
'specified json file.'),
default=False)
parser.add_argument('-kph', '--kph',
help=('Set a maximum speed in km/hour for scanner ' +
'movement.'),
Expand All @@ -306,10 +305,6 @@ def get_args():
help=('Change duration for lures set on pokestops. ' +
'This is useful for events that extend lure ' +
'duration.'), type=int, default=30)
parser.add_argument('--dump-spawnpoints',
help=('Dump the spawnpoints from the db to json ' +
'(only for use with -ss).'),
action='store_true', default=False)
parser.add_argument('-pd', '--purge-data',
help=('Clear Pokemon from database this many hours ' +
'after they disappear (0 to disable).'),
Expand Down Expand Up @@ -714,9 +709,7 @@ def get_args():
args.webhook_whitelist = [int(i) for i in
args.webhook_whitelist]
# Decide which scanning mode to use.
if args.spawnpoint_scanning:
args.scheduler = 'SpawnScan'
elif args.skip_empty:
if args.skip_empty:
args.scheduler = 'HexSearchSpawnpoint'
elif args.speed_scan:
args.scheduler = 'SpeedScan'
Expand Down
10 changes: 4 additions & 6 deletions runserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,13 @@ def main():

# Attempt to dump the spawn points (do this before starting threads of
# endure the woe).
if (args.spawnpoint_scanning and
args.spawnpoint_scanning != 'nofile' and
args.dump_spawnpoints):
with open(args.spawnpoint_scanning, 'w+') as file:
log.info('Saving spawn points to %s', args.spawnpoint_scanning)
if args.dump_spawnpoints:
with open(args.dump_spawnpoints, 'w+') as file:
log.info('Saving spawn points to %s', args.dump_spawnpoints)
spawns = Pokemon.get_spawnpoints_in_hex(
position, args.step_limit)
file.write(json.dumps(spawns))
log.info('Finished exporting spawn points')
log.info('Finished exporting spawn points.')

argset = (args, new_location_queue, pause_bit,
heartbeat, db_updates_queue, wh_updates_queue)
Expand Down