Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tanis2000 committed Jul 15, 2016
2 parents ac9a95d + b5c8a9b commit c2d96df
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
34 changes: 31 additions & 3 deletions decode.py
Expand Up @@ -4,7 +4,13 @@
import sys
import numpy
import math

import requests
##Make a secrets.py with bearer= and endpoint=
try:
from secrets import bearer, endpoint
except:
bearer = ""
endpoint = ""
from mitmproxy.script import concurrent
from mitmproxy.models import decoded

Expand Down Expand Up @@ -42,7 +48,22 @@
pokeLocation = {}
request_location = {}

def dumpToMap(data):
if bearer == "":
return
headers = {"Authorization" : "Bearer %s" % bearer}
r = requests.post("%s/api/push/mapobject/bulk" % endpoint, json = data, headers = headers)

def createItem(t, uid, point, meta):
data = {"type" : t,
"uid" : uid,
"location" : point,
"meta" : meta
}
return data

def triangulate((LatA, LonA, DistA), (LatB, LonB, DistB), (LatC, LonC, DistC)):
#grabbed from http://gis.stackexchange.com/questions/66/trilateration-using-3-latitude-and-longitude-points-and-3-distances
#using authalic sphere
#if using an ellipsoid this step is slightly different
#Convert geodetic Lat/Long to ECEF xyz
Expand Down Expand Up @@ -172,6 +193,7 @@ def response(context, flow):

if (key == GET_MAP_OBJECTS):
features = []
bulk = []

for cell in mor.MapCell:
for fort in cell.Fort:
Expand Down Expand Up @@ -205,6 +227,7 @@ def response(context, flow):
p = Point((fort.Longitude, fort.Latitude))
f = Feature(geometry=p, id=fort.FortId, properties=props)
features.append(f)
bulk.append(createItem("gym", fort.FortId, p, f.properties))

for spawn in cell.SpawnPoint:
p = Point((spawn.Longitude, spawn.Latitude))
Expand All @@ -217,6 +240,7 @@ def response(context, flow):
"marker-size": "small",
})
features.append(f)
bulk.append(createItem("spawnpoint", 0, p, f.properties))

for spawn in cell.DecimatedSpawnPoint:
p = Point((spawn.Longitude, spawn.Latitude))
Expand All @@ -240,6 +264,7 @@ def response(context, flow):
"marker-symbol": "suitcase"
})
features.append(f)
bulk.append(createItem("pokemon", pokemon.EncounterId, p, f.properties))

for pokemon in cell.CatchablePokemon:
p = Point((pokemon.Longitude, pokemon.Latitude))
Expand All @@ -252,14 +277,15 @@ def response(context, flow):
"marker-symbol": "circle"
})
features.append(f)
bulk.append(createItem("pokemon", pokemon.EncounterId, p, f.properties))

for poke in cell.NearbyPokemon:
gps = request_location[env.response_id]
if poke.EncounterId in pokeLocation:
add=True
add = True
for loc in pokeLocation[poke.EncounterId]:
if gps[0] == loc[0] and gps[1] == loc[1]:
add=False
add = False
if add:
pokeLocation[poke.EncounterId].append((gps[0], gps[1], poke.DistanceMeters/1000))
else:
Expand All @@ -275,11 +301,13 @@ def response(context, flow):
"marker-color": "FFFFFF",
"marker-symbol": "dog-park"
})
bulk.append(createItem("pokemon", poke.EncounterId, p, f.properties))
features.append(f)


fc = FeatureCollection(features)
dump = geojson.dumps(fc, sort_keys=True)
dumpToMap(bulk)
f = open('ui/get_map_objects.json', 'w')
f.write(dump)

Expand Down
2 changes: 0 additions & 2 deletions ui/index.html
Expand Up @@ -40,7 +40,5 @@
<script src='leaflet-providers.js'></script>
<script src='leaflet-realtime.min.js'></script>
<script src="index.js"></script>

</body>
</html>

0 comments on commit c2d96df

Please sign in to comment.