]> git.openstreetmap.org Git - nominatim.git/blob - mytests/forward_tiger_time.py
Implement geocoding and reverse geocoding with tiger interpolation lines instead...
[nominatim.git] / mytests / forward_tiger_time.py
1 import numpy as np
2 import urllib2 as url
3 import json as json
4 import random_points_bbox
5 import time
6
7 def test(num):
8     #first get some random points in the bbox
9     aPoints = random_points_bbox.getPoints(num, -100.815, 46.789, -100.717, 46.84)
10     #get the addresses
11     sReverseUrl = "http://localhost/nominatim_old/reverse.php?format=json&lat=%f&lon=%f"
12     aAddresses = []
13     for point in aPoints:
14         response = url.urlopen(sReverseUrl % (point[1], point[0]))
15         aAddresses.append(json.load(response)['address'])
16     #print aAddresses
17     # now we have all the addresses of the points in a list
18     # lets forward geocode this list
19     sOldUrl = "http://localhost/nominatim_old/search.php?format=json&city=%s&street=%s&addressdetails=1"
20     sLineUrl = "http://localhost/nominatim/search.php?format=json&city=%s&street=%s&addressdetails=1"
21     start_old = time.time()
22     for address in aAddresses:
23         if 'house_number' in address and 'road' in address:
24             responseOld = url.urlopen(sOldUrl % (address['city'], address['house_number']+' '+address['road']))
25             #dataOld = json.load(responseOld)
26             #print dataOld[0]['display_name']
27         elif 'road' in address:
28             responseOld = url.urlopen(sOldUrl % (address['city'], address['road']))
29             #dataOld = json.load(responseOld)
30             #print dataOld[0]['display_name']
31     end_old = time.time()        
32     for address in aAddresses:
33         if 'house_number' in address and 'road' in address:
34             responseLine = url.urlopen(sLineUrl % (address['city'], address['house_number']+' '+address['road']))
35         elif 'road' in address:
36             responseLine = url.urlopen(sLineUrl % (address['city'], address['road']))
37     end_line = time.time()
38     
39     print "Seconds old search for %d elements: %f" % (num,end_old-start_old)
40     print "Seconds line search for %d elements: %f" % (num,end_line-end_old)
41     
42         
43 test(100)
44 # 100 points: old: 7.11 sec, new: 7.47 sec
45 # 1000 points: old: 65.69 sec, new: 66.96 sec