Skip to content

Commit 904172a

Browse files
committed
Slightly improve backend code
1 parent 94979ab commit 904172a

File tree

4 files changed

+55
-58
lines changed

4 files changed

+55
-58
lines changed

app.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def closest_pano_to_coord(lat, lon):
9292
smallest_distance = distance
9393
closest = pano
9494
#print(x,y)
95-
return jsonify(date="asdf",lat = closest.lat, lon = closest.lon, panoid = str(closest.panoid), region_id = str(closest.region_id), unknown10 = closest.unknown10, unknown11 = closest.unknown11, heading = closest.heading())
95+
return jsonify(date=closest.date,lat = closest.lat, lon = closest.lon, panoid = str(closest.panoid), region_id = str(closest.region_id), unknown10 = closest.unknown10, unknown11 = closest.unknown11, heading = closest.heading)
9696

9797

9898

@@ -129,7 +129,6 @@ def relay_full_pano(panoid, region_id, zoom):
129129
image = None
130130

131131
TILE_SIZE = round(heic_array[0].width * (256 / 5632))
132-
print("TILE_SIZE:", TILE_SIZE)
133132
WIDTH_SIZE = round(heic_array[0].width * (1024 / 5632))
134133
widths, heights = zip(*(i.size for i in heic_array))
135134
total_width, max_height = (sum(widths)-WIDTH_SIZE), max(heights)
@@ -153,7 +152,6 @@ def relay_full_pano(panoid, region_id, zoom):
153152

154153
@app.route("/panodbg/<int:panoid>/<int:region_id>/<int:zoom>/")
155154
def relay_pano_dbg(panoid, region_id, zoom):
156-
print("Starting")
157155
heic_array = []
158156
for i in range(4):
159157
heic_bytes = fetch_pano_segment(panoid, region_id, i, zoom, auth)

lookaround/lookaround/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import requests
33

44
from .proto import MapTile_pb2
5-
from .geo import wgs84_to_tile_coord
5+
from .geo import wgs84_to_tile_coord, heading_from_unkown10_unknown11
66
from .panorama import LookaroundPanorama
77

88
from google.protobuf.json_format import MessageToJson
@@ -27,7 +27,7 @@ def get_coverage_tile(tile_x, tile_y, tile_z = 17):
2727
pano_obj = LookaroundPanorama(
2828
pano.panoid,
2929
tile.unknown13[pano.region_id_idx].region_id,
30-
lat, lon, pano.unknown4.unknown10, pano.unknown4.unknown11)
30+
lat, lon, pano.unknown4.unknown10, pano.unknown4.unknown11, heading_from_unkown10_unknown11(pano.unknown4.unknown10, pano.unknown4.unknown11))
3131
pano_obj.date = datetime.fromtimestamp(int(pano.timestamp) / 1000.0)
3232
panos.append(pano_obj)
3333
return panos
@@ -58,9 +58,6 @@ def _get_coverage_tile_raw(tile_x, tile_y, tile_z = 17):
5858
response = requests.get("https://gspe76-ssl.ls.apple.com/api/tile?", headers=headers)
5959
tile = MapTile_pb2.MapTile()
6060
tile.ParseFromString(response.content)
61-
json_obj = MessageToJson(tile)
62-
with open("tile.json", "w") as f:
63-
f.write(json_obj)
6461
return tile
6562

6663
def get_pano_segment_url(panoid, region_id, segment, zoom, auth):

lookaround/lookaround/geo.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,52 @@ def tile_coord_to_wgs84(x, y, zoom):
4848
world_coord = (pixel_coord[0] / scale, pixel_coord[1] / scale)
4949
lat_lon = mercator_to_wgs84(world_coord[0], world_coord[1])
5050
return lat_lon
51+
52+
53+
54+
'''
55+
Approximate heading of the panorama, assuming the POV is facing
56+
to the left of the Apple Car in cthe direction of driving.
57+
'''
58+
def heading_from_unkown10_unknown11(unknown10, unknown11):
59+
# Whatever is the logic behind this?
60+
# Who at Apple thought of these values?
61+
62+
# unknown10
63+
# These are the extreme values of unkown10 I have observed in a random selection of about 1000 tiles.
64+
# The values are in two clusters.
65+
# In the range [1,2159] you're looking more west than east.
66+
# In the range [14318,16383] you're looking more east than west.
67+
westmin = 1
68+
westmax = 2159
69+
eastmin = 16383 # looking (north/south) and very slightly east
70+
eastmax = 14318 # looking slightly (north/south) directly east
71+
72+
# unknown11
73+
# This is slightly more speculative
74+
northmin = 8204 # this is likely lower
75+
northmax = 6054
76+
southmin = 8204 # this is likely lower
77+
southmax = 10173
78+
79+
80+
ew=0
81+
if unknown10 < westmax:
82+
# Looking west
83+
ew = -(float(unknown10 - westmin) / float(westmax - westmin))
84+
elif unknown10 > eastmax:
85+
# Looking east
86+
ew = (float(unknown10 - eastmin) / float(eastmax - eastmin))
87+
88+
ns=0
89+
if unknown11 <= northmin:
90+
# Looking north
91+
ns = (float(unknown11 - northmin) / float(northmax - northmin))
92+
else:
93+
ns = -(float(unknown11 - southmin) / float(southmax - southmin))
94+
95+
96+
r = math.degrees(math.atan2(ew,ns))
97+
if r < 0:
98+
r += 360
99+
return r

lookaround/lookaround/panorama.py

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,19 @@
1-
import math
21
class LookaroundPanorama:
3-
def __init__(self, panoid, region_id, lat, lon, unknown10, unknown11):
2+
def __init__(self, panoid, region_id, lat, lon, unknown10, unknown11, heading):
43
self.panoid = panoid
54
self.region_id = region_id
65
self.lat = lat
76
self.lon = lon
87
self.unknown10 = unknown10
98
self.unknown11 = unknown11
109
self.date = None
10+
self.heading = heading
1111

12-
'''
13-
Approximate heading of the panorama, assuming the POV is facing
14-
to the left of the Apple Car in cthe direction of driving.
15-
'''
16-
def heading(self):
17-
# Whatever is the logic behind this?
18-
# Who at Apple thought of these values?
19-
20-
# unknown10
21-
# These are the extreme values of unkown10 I have observed in a random selection of about 1000 tiles.
22-
# The values are in two clusters.
23-
# In the range [1,2159] you're looking more west than east.
24-
# In the range [14318,16383] you're looking more east than west.
25-
westmin = 1
26-
westmax = 2159
27-
eastmin = 16383 # looking (north/south) and very slightly east
28-
eastmax = 14318 # looking slightly (north/south) directly east
29-
30-
# unknown11
31-
# This is slightly more speculative
32-
northmin = 8204 # this is likely lower
33-
northmax = 6054
34-
southmin = 8204 # this is likely lower
35-
southmax = 10173
36-
37-
38-
ew=0
39-
if self.unknown10 < westmax:
40-
# Looking west
41-
ew = -(float(self.unknown10 - westmin) / float(westmax - westmin))
42-
elif self.unknown10 > eastmax:
43-
# Looking east
44-
ew = (float(self.unknown10 - eastmin) / float(eastmax - eastmin))
45-
46-
ns=0
47-
if self.unknown11 <= northmin:
48-
# Looking north
49-
ns = (float(self.unknown11 - northmin) / float(northmax - northmin))
50-
else:
51-
ns = -(float(self.unknown11 - southmin) / float(southmax - southmin))
52-
53-
54-
print(ns,ew)
55-
r = math.degrees(math.atan2(ew,ns))
56-
if r < 0:
57-
r += 360
58-
return r
5912

6013

6114
def __repr__(self):
6215
return str(self)
6316

6417
def __str__(self):
65-
return f"{self.panoid}/{self.region_id} ({self.lat:.6}, {self.lon:.6}) " \
18+
return f"{self.panoid}/{self.region_id} ({self.lat:.6}, {self.lon:.6}) {self.heading}" \
6619
f"[{self.date.strftime('%Y-%m-%d')}]"

0 commit comments

Comments
 (0)