コード例 #1
0
ファイル: test_class.py プロジェクト: holmesal/levr_app
	def get(self):
		#take in geo_point
		#set radius, expand, get all deals
		
		
		
		request_point = levr.geo_converter('42.35,-71.110')
		center_hash = geohash.encode(request_point.lat,request_point.lon,precision=6)
		all_squares = geohash.expand(center_hash)
		
		all = levr.Business.all().count()
		self.response.out.write(all)
		self.response.out.write('<br/>')
		
		keys = []
		for query_hash in all_squares:
			q = levr.Business.all(keys_only=True).filter('geo_hash >=',query_hash).filter('geo_hash <=',query_hash+"{")
			keys.extend(q.fetch(None))
		
		self.response.out.write(str(keys.__len__())+"<br/>")
		
		#get all deals
		deals = levr.Business.get(keys)
		logging.debug(deals)
		for deal in deals:
			self.response.out.write(deal.geo_hash+"<br/>")
コード例 #2
0
ファイル: handlers.py プロジェクト: pnw/geotombstone
    def full_search(self):
        """
		Provides a common method to perform a search on api and website
		
		@warning: should be wrapped in a try,except block
		@return: a list of obituaries
		@rtype: list
		"""
        name = self.rget("name", str) or None
        pob = self.rget("pob", str) or None
        pod = self.rget("pod", str) or None

        # join the string params together if they exist
        search_tokens = utils.tokenize_multi(name, pob, pod)
        logging.info(search_tokens)
        dob = self.rget("dob", self.parse_date) or None
        dod = self.rget("dod", self.parse_date) or None

        lat = self.rget("lat", float)
        lon = self.rget("lon", float)

        logging.info("Sending to search: ")
        logging.info(search_tokens)

        if lat and lon:
            # search by location
            ghash = geohash.encode(lat, lon)
            ghash_list = geohash.expand(ghash)

            precision = self.rget("precision", int) or 4

            return utils.search(search_tokens, dob, dod, ghash_list, precision)
        else:
            return utils.search(search_tokens, dob, dod)
コード例 #3
0
ファイル: levr_utils.py プロジェクト: holmesal/levr_app
def get_deals_in_area(tags,request_point,precision=5):
	'''
	tags = list of tags that are strings
	request point is db.GeoPt format
	precision is int
	'''
	request_point = levr.geo_converter('42.35,-71.110')
	logging.debug(precision)
	center_hash = geohash.encode(request_point.lat,request_point.lon,precision=precision)
	logging.debug(center_hash)
	hash_set = geohash.expand(center_hash)
	logging.debug(hash_set)
	
	##DEBUG
	ref_query = levr.Deal.all().filter('deal_status =','active')
	for tag in tags:
		if tag != 'all':
			ref_query.filter('tags =',tag)
	ref_deals = ref_query.fetch(None)
	logging.info("total number of deals: "+str(ref_deals.__len__()))
#	for d in ref_deals:
#		logging.debug(d.geo_hash)
	##/DEBUG
	
	
	####build search query
	#only grabbing deal keys, then batch get array
	deal_keys = []
	for query_hash in hash_set:
		#only grab keys for deals that have active status
		q = levr.Deal.all(keys_only=True).filter('deal_status =','active')
		#grab all deals where primary_cat is in tags
		for tag in tags:
			#all is a special keyword
			if tag != 'all':
				logging.debug('tag: '+str(tag))
				q.filter('tags =',tag)
		#filter by geohash
		q.filter('geo_hash >=',query_hash).filter('geo_hash <=',query_hash+"{") #max bound
#					logging.debug(q)
#					logging.debug(levr_utils.log_dict(q.__dict__))
		
		#get all keys for this neighborhood
		fetched_deals = q.fetch(None)
		logging.info('From: '+query_hash+", fetched: "+str(fetched_deals.__len__()))
		
		deal_keys.extend(fetched_deals)
#					logging.debug(deal_keys)
	
	#batch get results. here is where we would set the number of results we want and the offset
	deals = levr.Deal.get(deal_keys)
	
	logging.info('number of deals fetched: '+str(deals.__len__()))
	
	return deals
コード例 #4
0
ファイル: api.py プロジェクト: wickila/lunch
 def get_neighbors(self,hash_location,percision):
     result = geohash.expand(hash_location)
     i = 6
     while i>percision:
         temp = result[:]
         for area in temp:
             neighbors = geohash.neighbors(area)
             for neighbor in neighbors:
                 if result.count(neighbor) < 1:
                     result.append(neighbor)
         i-=1
     return result  
コード例 #5
0
ファイル: utils.py プロジェクト: holmesal/musicthing
def create_ghash_list(ghash, n=3):
    '''
	Creates a list of ghashes from the provided geo_point
	Expands the ghash list a number of times depending on the precision
	
	@param geo_point: The center of the requested ghash list box
	@type geo_point: db.GeoPt
	@param precision: The desired precision of the ghashes
	@type precision: int
	
	@return: A unique list of ghashes
	@rtype: list
	'''
    ghash_list = set([ghash])

    # determine number of iterations based on the precision
    for _ in range(0, n):
        # expand each ghash, and remove duplicates to expand a ring
        new_ghashes = set([])
        for ghash in ghash_list:
            new_ghashes.update(geohash.expand(ghash))
        # add new hashes to master list
        ghash_list.update(new_ghashes)
    return ghash_list
コード例 #6
0
ファイル: utils.py プロジェクト: holmesal/musicthing
def create_ghash_list(ghash,n=3):
	'''
	Creates a list of ghashes from the provided geo_point
	Expands the ghash list a number of times depending on the precision
	
	@param geo_point: The center of the requested ghash list box
	@type geo_point: db.GeoPt
	@param precision: The desired precision of the ghashes
	@type precision: int
	
	@return: A unique list of ghashes
	@rtype: list
	'''
	ghash_list = set([ghash])
	
	# determine number of iterations based on the precision
	for _ in range(0,n):
		# expand each ghash, and remove duplicates to expand a ring
		new_ghashes = set([])
		for ghash in ghash_list:
			new_ghashes.update(geohash.expand(ghash))
		# add new hashes to master list
		ghash_list.update(new_ghashes)
	return ghash_list