Skip to content

Commit

Permalink
Allow highlighting of ex raid gyms on the map
Browse files Browse the repository at this point in the history
Default is not to mark ex raid gyms on the map
except for `raidex.py`
  • Loading branch information
evenly-epic-mule committed Jan 27, 2018
1 parent 8af3c9b commit df08400
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 23 deletions.
2 changes: 2 additions & 0 deletions config.example.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@

# allow displaying the live location of workers on the map
MAP_WORKERS = True
# Highligh EX Raid Gyms on map (default False, uncomment to enable)
#MAP_SHOW_EX_GYMS = True
# filter these Pokemon from the map to reduce traffic and browser load
#MAP_FILTER_IDS = [161, 165, 16, 19, 167]

Expand Down
2 changes: 2 additions & 0 deletions monocle/sanitized.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
'MAP_FILTER_IDS': sequence,
'MAP_PROVIDER_ATTRIBUTION': str,
'MAP_PROVIDER_URL': str,
'MAP_SHOW_EX_GYMS': bool,
'MAP_START': sequence,
'MAP_WORKERS': bool,
'MAX_CAPTCHAS': int,
Expand Down Expand Up @@ -190,6 +191,7 @@
'MAP_FILTER_IDS': None,
'MAP_PROVIDER_URL': '//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
'MAP_PROVIDER_ATTRIBUTION': '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
'MAP_SHOW_EX_GYMS': False,
'MAP_WORKERS': True,
'MAX_CAPTCHAS': 0,
'MAX_RETRIES': 3,
Expand Down
6 changes: 5 additions & 1 deletion monocle/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
box-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
}

.ex-raid-gym {
background: #0f0;
}

.leaflet-control-layers-toggle {
background-image: url('../img/layers.png');
}
Expand Down Expand Up @@ -215,4 +219,4 @@
}
.instinct {
background: #fe9c0a;
}
}
12 changes: 8 additions & 4 deletions monocle/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ function PokemonMarker (raw) {

function FortMarker (raw) {
var icon = new FortIcon({iconUrl: '/static/monocle-icons/forts/' + raw.team + '.png'});
if (raw.ex) {
icon.options.className += " ex-raid-gym"
}
var marker = L.marker([raw.lat, raw.lon], {icon: icon, opacity: 1});
marker.raw = raw;
markers[raw.id] = marker;
Expand Down Expand Up @@ -281,9 +284,9 @@ function RaidMarker (raw) {
}, 2500);

var userPreference = getPreference('raids-'+raw.level);
if (userPreference === 'show'){
if (userPreference === 'show' || (userPreference === 'showex' && raw.ex)){
marker.overlay = 'Raids';
}else if (userPreference === 'hide'){
}else{
marker.overlay = 'Hidden';
}

Expand Down Expand Up @@ -652,7 +655,7 @@ function moveToLayer(id, layer, type){
var m = markers[k];
if ((k.indexOf("raid-") > -1) && (m !== undefined) && (m.raw.level === id)){
m.removeFrom(overlays[m.overlay]);
if (layer === 'show'){
if (layer === 'show' || (layer === 'showex' && m.raw.ex)){
m.overlay = "Raids";
m.addTo(overlays.Raids);
}else{
Expand Down Expand Up @@ -688,6 +691,7 @@ function populateSettingsPanels(){
'<span class="raid-label">Level ' + i + ' (' + _raids_labels[i-1] + ')</span>' +
'<div class="btn-group" role="group" data-group="raids-'+i+'">' +
'<button type="button" class="btn btn-default" data-id="'+i+'" data-value="show">Show</button>' +
'<button type="button" class="btn btn-default" data-id="'+i+'" data-value="showex">EX Gym only</button>' +
'<button type="button" class="btn btn-default" data-id="'+i+'" data-value="hide">Hide</button>' +
'</div>' +
'</div>';
Expand All @@ -701,7 +705,7 @@ function setSettingsDefaults(){
_defaultSettings['filter-'+i] = (_defaultSettings['TRASH_IDS'].indexOf(i) > -1) ? "trash" : "pokemon";
};
for (var i = 1; i <= _raids_count; i++){
_defaultSettings['raids-'+i] = (_defaultSettings['RAIDS_FILTER'].indexOf(i) > -1) ? "show" : "hide";
_defaultSettings['raids-'+i] = (_defaultSettings['RAIDS_FILTER'].indexOf(i) > -1) ? "show" : "showex";
};

$("#settings div.btn-group").each(function(){
Expand Down
44 changes: 42 additions & 2 deletions monocle/web_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,13 @@ def get_pokemarkers(after_id=0):
return tuple(map(sighting_to_marker, pokemons))


def get_raid_markers(names=POKEMON, moves=MOVES):
def get_raid_markers(names=POKEMON, moves=MOVES, show_ex=conf.MAP_SHOW_EX_GYMS):
with session_scope() as session:
markers = []
raids = session.query(Raid) \
.filter(Raid.time_end > time())
if show_ex:
forts = get_forts(session)
for raid in raids:
fort = session.query(Fort) \
.filter(Fort.id == raid.fort_id) \
Expand All @@ -140,6 +142,7 @@ def get_raid_markers(names=POKEMON, moves=MOVES):
.first()
markers.append({
'id': 'raid-' + str(raid.id),
'ex': show_ex and raid.fort_id in get_ex_raid_gyms(forts),
'level': raid.level,
'team': fortsighting.team,
'pokemon_id': raid.pokemon_id,
Expand Down Expand Up @@ -180,11 +183,12 @@ def get_weather():
return markers


def get_gym_markers(names=POKEMON):
def get_gym_markers(names=POKEMON, show_ex=conf.MAP_SHOW_EX_GYMS):
with session_scope() as session:
forts = get_forts(session)
return [{
'id': 'fort-' + str(fort['fort_id']),
'ex': show_ex and fort['fort_id'] in get_ex_raid_gyms(forts),
'sighting_id': fort['id'],
'prestige': fort['prestige'],
'pokemon_id': fort['guard_pokemon_id'],
Expand Down Expand Up @@ -269,6 +273,42 @@ def get_all_parks():

return parks

def get_ex_raid_gyms(forts=None):
gyms = []
with session_scope() as session:
if not forts:
forts = get_forts(session)
try:
pickle = load_pickle('ex_raid_gyms', raise_exception=True)
gyms = pickle['gyms']
max_id = pickle.get('max_id', 0)
for g in forts:
if g['fort_id'] > max_id:
raise KeyError("Cache outdated")
except (FileNotFoundError, TypeError, KeyError):
parks = get_all_parks()
max_id = 0
for g in forts:
gym_point = Point(g['lat'], g['lon'])
cell = Polygon(get_s2_cell_as_polygon(g['lat'], g['lon'], 20)) # s2 lvl 20
for p in parks:
if g['fort_id'] > max_id:
max_id = g['fort_id']
coords = p['coords']
# osm polygon can be a line
if len(coords) == 2:
shape = LineString(coords)
if shape.within(cell.centroid):
gyms.append(g['fort_id'])
break
if len(coords) > 2:
shape = Polygon(coords)
if shape.contains(cell.centroid):
gyms.append(g['fort_id'])
break
dump_pickle('ex_raid_gyms', {"max_id": max_id, "gyms": gyms})
return gyms

def get_s2_cells(n=north, w=west, s=south, e=east, level=12):
region_covered = s2sphere.LatLngRect.from_point_pair(
s2sphere.LatLng.from_degrees(n, w),
Expand Down
19 changes: 3 additions & 16 deletions raidex.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,9 @@ def fullmap(map_html=render_map()):
def gym_data():
gyms = []
parks = get_all_parks()
for g in get_gym_markers():
gym_point = Point(g['lat'], g['lon'])
cell = Polygon(get_s2_cell_as_polygon(g['lat'], g['lon'], 20)) # s2 lvl 20
for p in parks:
coords = p['coords']
# osm polygon can be a line
if len(coords) == 2:
shape = LineString(coords)
if shape.within(cell.centroid):
gyms.append(g)
break
if len(coords) > 2:
shape = Polygon(coords)
if shape.contains(cell.centroid):
gyms.append(g)
break
for g in get_gym_markers(show_ex=True):
if g['ex']:
gyms.append(g)
return jsonify(gyms)

@app.route('/parks_cells')
Expand Down

0 comments on commit df08400

Please sign in to comment.