|
@@ -1,6 +1,8 @@
|
|
|
import json
|
|
|
+import math
|
|
|
+
|
|
|
import requests
|
|
|
-from flask import current_app
|
|
|
+import haversine
|
|
|
|
|
|
metadata_url = "https://maps.googleapis.com/maps/api/streetview/metadata"
|
|
|
mapcrunch_url = "http://www.mapcrunch.com/_r/"
|
|
@@ -19,18 +21,30 @@ def generate_coord(key):
|
|
|
|
|
|
for lat, lng in points_js["points"]:
|
|
|
params = {
|
|
|
- "key": key
|
|
|
- "location": f"{lat},{lng}"
|
|
|
+ "key": key,
|
|
|
+ "location": f"{lat},{lng}",
|
|
|
}
|
|
|
js = requests.get(metadata_url, params=params).json()
|
|
|
if js["status"] != "ZERO_RESULTS":
|
|
|
return (lat, lng)
|
|
|
|
|
|
|
|
|
+mean_earth_radius_km = (6378 + 6357) / 2
|
|
|
+# the farthest you can be from another point on Earth
|
|
|
+antipode_dist_km = math.pi * mean_earth_radius_km
|
|
|
+min_dist_km = 0.15 # if you're within 150m, you get a perfect score
|
|
|
+perfect_score = 5000
|
|
|
+
|
|
|
+
|
|
|
def score(target, guess):
|
|
|
"""
|
|
|
Takes in two (latitude, longitude) pairs and produces an int score.
|
|
|
Score is in the (inclusive) range [0, 5000]
|
|
|
Higher scores are closer.
|
|
|
"""
|
|
|
- pass
|
|
|
+ dist_km = haversine.haversine(target, guess)
|
|
|
+ if dist_km <= min_dist_km:
|
|
|
+ return perfect_score
|
|
|
+
|
|
|
+ # TODO might want to try something logarithmic here eventually
|
|
|
+ return perfect_score * (1 - (dist_km / antipode_dist_km))
|