# HG changeset patch # User Jeff Hammel # Date 1498439623 25200 # Node ID 6891c5523b69165a74c5697805de6acc739ab602 # Parent e69cb496324e7c3c2782cc908d1852b832abfac8 load with neighbors :) diff -r e69cb496324e -r 6891c5523b69 README.txt --- a/README.txt Sun Jun 25 17:45:19 2017 -0700 +++ b/README.txt Sun Jun 25 18:13:43 2017 -0700 @@ -73,6 +73,13 @@ There are 72897 cases with less than 100 in this box and 18444 with less than 10. +Because of this, the closest 50 neighbors were +precomputed and cached as `neighbors.dat`: + +``` +find-neighbors /home/jhammel/tensorflow/cities1000.txt -k 50 --latlon 1. 1. neighbors.dat +``` + ## Web Service @@ -101,6 +108,8 @@ it is a `O(10^10)` operation on the dataset. This should be improved and parallelized +- no through-the-web (TTW) testing was done except manual. + This should be corrected with Selenium and other headless testing ## (Hopefully) Helpful Links diff -r e69cb496324e -r 6891c5523b69 globalneighbors/neighbors.py --- a/globalneighbors/neighbors.py Sun Jun 25 17:45:19 2017 -0700 +++ b/globalneighbors/neighbors.py Sun Jun 25 18:13:43 2017 -0700 @@ -22,7 +22,7 @@ if isinstance(f, string): with open(f) as _f: - return read_neighbors_file(f) + return read_neighbors_file(_f) retval = {} for line in f: diff -r e69cb496324e -r 6891c5523b69 globalneighbors/templates/city.html --- a/globalneighbors/templates/city.html Sun Jun 25 17:45:19 2017 -0700 +++ b/globalneighbors/templates/city.html Sun Jun 25 18:13:43 2017 -0700 @@ -24,5 +24,22 @@
Country:
{{ city['country code'] }} + + {% if neighbors %} +
+

+ {{ neighbors|length }} nearest neighbors: +

+ + + {% for neighbor in neighbors %} + + + + + {% endfor %} +
NeighborDistance (km)
{{ neighbor.name }}{{ neighbor.distance }}
+
+ {% endif %} diff -r e69cb496324e -r 6891c5523b69 globalneighbors/web.py --- a/globalneighbors/web.py Sun Jun 25 17:45:19 2017 -0700 +++ b/globalneighbors/web.py Sun Jun 25 18:13:43 2017 -0700 @@ -180,9 +180,20 @@ city = self.cities.get(geoid) if not city: return - variables = dict(city=city) + variables = dict(city=city, neighbors=None) if self.neighbors: - import pdb; pdb.set_trace() + n_neighbors = request.GET.get('neighbors', 10) + try: + n_neighbors = int(n_neighbors) + except ValueError as e: + n_neighbors = 10 + neighbors = self.neighbors.get(geoid, [])[:n_neighbors] + neighbors = [{'name': self.cities[geoid]['name'], + 'geoid': geoid, + 'distance': distance} + for geoid, distance in neighbors] + variables['neighbors'] = neighbors + return Response(content_type=self.content_type, body=self.citypage.render(variables)) except ValueError: diff -r e69cb496324e -r 6891c5523b69 wsgiapp.py --- a/wsgiapp.py Sun Jun 25 17:45:19 2017 -0700 +++ b/wsgiapp.py Sun Jun 25 18:13:43 2017 -0700 @@ -15,8 +15,11 @@ # XXX use a default not really appropriate for production cities1000 = os.path.join(here, 'tests', 'data', 'cities1000.txt') assert os.path.exists(cities1000) +neighbors = '/home/jhammel/GlobalNeighbors/neighbors.dat' +assert os.path.exists(neighbors) # WSGI App -application = PassthroughFileserver(GlobalHandler(cities1000)) +application = PassthroughFileserver(GlobalHandler(cities1000, + neighbors_file=neighbors)) print ("Finished loading application") sys.stdout.flush()