فهرست منبع

Added a first pass at the scoring logic

Kirk Trombley 5 سال پیش
والد
کامیت
e80837ce03
2فایلهای تغییر یافته به همراه33 افزوده شده و 6 حذف شده
  1. 18 4
      server/lib.py
  2. 15 2
      server/requirements.txt

+ 18 - 4
server/lib.py

@@ -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))

+ 15 - 2
server/requirements.txt

@@ -1,2 +1,15 @@
-flask>=1.1.1
-flask-sqlalchemy>=2.4.0
+certifi==2019.6.16
+chardet==3.0.4
+Click==7.0
+Flask==1.1.1
+Flask-SQLAlchemy==2.4.0
+haversine==2.1.2
+idna==2.8
+itsdangerous==1.1.0
+Jinja2==2.10.1
+MarkupSafe==1.1.1
+requests==2.22.0
+SQLAlchemy==1.3.7
+toml==0.10.0
+urllib3==1.25.3
+Werkzeug==0.15.5