예제 #1
0
def decidefood(time, lat, lng, start, now, f, input2, places_been,
               hunger_count, input4, counter):

    if time < 0:
        return time, templat, templng, name, hunger_count
    if time < 1:
        data = places.filters({
            '$and': [{
                'category_ids': {
                    '$includes': 338
                }
            }, {
                'category_ids': {
                    '$excludes': 341
                }
            }]
        }).geo(circle(lat, lng, 1000 * time)).data()
        time -= 0.25
    else:
        data = places.filters({
            '$and': [{
                'category_ids': {
                    '$includes': 347
                }
            }]
        }).geo(circle(lat, lng, 1000 * time)).data()
        time -= 1
    f.write("<p><br><br><b>Time for a Snack!</b></p>\n")

    try:
        while True:
            temp_place = data[random.randrange(0, len(data))]
            if temp_place[u'name'] in places_been:
                continue
            else:
                places_been.setdefault(temp_place[u'name'], 0)
                break

        templat = float(temp_place[u'latitude'])
        templng = float(temp_place[u'longitude'])
        name = str(temp_place[u'name'])
        current_time = now + input2 - datetime.timedelta(hours=time)
        current_time = current_time.strftime('%I:%M %p')
        f.write("<p><br><br><b>Go from " + start + " to " + name +
                " starting at time " + str(current_time) + "</b></p>\n")
        time, hunger_count, counter = route(
            now + input2 - datetime.timedelta(hours=time), lat, lng, templat,
            templng, time, f, input2, hunger_count, input4, counter)
        counter = printresults_food(temp_place, f, counter)

        #print time
    except:
        templat = lat
        templng = lng
        name = start
    return time, templat, templng, name, hunger_count, counter
예제 #2
0
 def __init__(self, query, lat, lng, radius):
     factual = Factual(app.config['FACTUAL_KEY'],
                       app.config['FACTUAL_SECRET'])
     places = factual.table('places')
     # Searches for all restaurants
     if query.lower() == 'restaurants':
         self.data = places.filters({'category_ids':{'$includes_any':[312,338]}}).\
             geo(circle(lat, lng, radius)).limit(50).data()
     # Searches according to user's query
     else:
         self.data = places.search(query).geo(circle(
             lat, lng, radius)).limit(50).data()
예제 #3
0
def decidefood(time, lat, lng, start, now,f, input2):
	f.write("<p>Time for a Snack!</p>\n")

	if time<0:
		return time, templat, templng, name
	if time<1:
		data = places.filters({'$and':[{'category_ids':{'$includes':338}}, {'category_ids':{'$excludes':341}}]}).geo(circle(lat,lng,1000*time)).limit(5).data()
		time -= 0.25	
		data = data[random.randrange(0,len(data))]	
	else:
		data = places.filters({'$and':[{'category_ids':{'$includes':347}}]}).geo(circle(lat,lng,1000*time)).limit(5).data()
		time -= 1
	try:
		data = data[random.randrange(0,len(data))]

		templat = float(data[u'latitude'])
		templng = float(data[u'longitude'])
		name = str(data[u'name'])
		f.write("<p>Go from "+ start+" to "+ name+" starting at time " +str(now+input2-datetime.timedelta(hours = time))+"</p>\n")
		time = route(now + input2 - datetime.timedelta(hours = time), lat, lng, templat, templng, time,f, input2)
		printresults_food(data,f)

		#print time
	except:
		templat = lat
		templng = lng
		name = start
	return time, templat, templng, name
예제 #4
0
def matchCoordinates(address):
    query = factual.table("world-geographies").search(address).limit(1)
    query = query.select("longitude,latitude")
    query = query.geo(circle(42.350933, -71.069209, 5000))
    s = query.data()
    if len(s):
      return (s[0][unicode('latitude')], s[0][unicode('longitude')])
    return (42.350933, -71.069209)
예제 #5
0
def decideplace(time, track, lat, lng, start, now, f, input2, places_been,
                hunger_count, input4, counter):
    no_more = 0
    if time < 0:
        return time, templat, templng, name, hunger_count, no_more, counter

    data = places.filters({
        '$and': [{
            'category_ids': {
                '$includes': track
            }
        }]
    }).geo(circle(lat, lng, 1000 * time)).data()
    count_datapoints = 0
    for datapoints in data:
        if datapoints[u'name'] not in places_been:
            break
        count_datapoints += 1
    if count_datapoints == len(data):
        no_more = 1
        templat, templng, name = lat, lng, start
        return time, templat, templng, name, hunger_count, no_more, counter
    if not data:
        templat = lat
        templng = lng
        name = start
    else:
        try:
            while True:
                temp_place = data[random.randrange(0, len(data))]
                if temp_place[u'name'] in places_been:
                    continue
                else:
                    places_been.setdefault(temp_place[u'name'], 0)
                    break

            templat = float(temp_place[u'latitude'])
            templng = float(temp_place[u'longitude'])
            name = str(temp_place[u'name'])
            current_time = now + input2 - datetime.timedelta(hours=time)
            current_time = current_time.strftime('%I:%M %p')
            f.write("<p><br><br><b>Go from " + start + " to " + name +
                    " starting at time " + str(current_time) + "</b></p>\n")
            time, hunger_count, counter = route(
                now + input2 - datetime.timedelta(hours=time), lat, lng,
                templat, templng, time, f, input2, hunger_count, input4,
                counter)
            time -= 1
            hunger_count += 1
            counter = printresults_places(temp_place, f, counter)
        except:
            templat = lat
            templng = lng
            name = start
    if not templat:
        templat, templng, no_more = lat, lng, 1
        return time, templat, templng, name, hunger_count, no_more, counter
    return time, templat, templng, name, hunger_count, no_more, counter
def GetBizNearAddress(category_id, address, radius_meters, offset, n):
    factual = Factual('YK4fO9P1qZFZy4Cu7HDNkeZd9YEN1ut4tyO426OR',
                      '9G1L9zUop7kwMmNkM7eIYsFNbvhINDl8hyxyZnKv')
    places = factual.table('places')
    # All with category_id
    rest = places.filters({"category_ids": {"$includes": category_id}})
    # Latitutde and Longitude of address
    lat, lng = GetLatLng(address)
    near = rest.geo(circle(lat, lng,
                           radius_meters)).offset(offset).limit(n).data()
    return near
예제 #7
0
파일: maps.py 프로젝트: julms/CookATour-2.0
def decideplace(time, track, lat, lng, start, now,f, input2, places_been, hunger_count, input4, counter):
	no_more = 0
	if time<0:
		return time, templat, templng, name, hunger_count, no_more, counter


	data = places.filters({'$and':[{'category_ids':{'$includes':track}}]}).geo(circle(lat,lng, 1000*time)).data()
	count_datapoints = 0
	for datapoints in data:
		if datapoints[u'name'] not in places_been:
			break
		count_datapoints += 1
	if count_datapoints == len(data):
		no_more = 1
		templat,templng,name = lat,lng,start
		return time, templat, templng, name, hunger_count, no_more, counter
	if not data:
		templat = lat
		templng = lng
		name = start
	else:
		try:
			while True:
				temp_place = data[random.randrange(0,len(data))]
				if temp_place[u'name'] in places_been:
					continue
				else:
					places_been.setdefault(temp_place[u'name'], 0)
					break

			templat = float(temp_place[u'latitude'])
			templng = float(temp_place[u'longitude'])
			name = str(temp_place[u'name'])
			current_time = now+input2-datetime.timedelta(hours = time)
			current_time = current_time.strftime('%I:%M %p')
			f.write("<p><br><br><b>Go from "+ start+" to "+ name+" starting at time " +str(current_time)+"</b></p>\n")
			time, hunger_count, counter = route(now + input2 - datetime.timedelta(hours = time), lat, lng, templat, templng, time, f, input2, hunger_count, input4, counter)
			time -= 1
			hunger_count += 1
			counter = printresults_places(temp_place,f, counter)
		except:
			templat = lat
			templng = lng
			name = start
	if not templat:
		templat,templng,no_more = lat,lng,1
		return time, templat, templng, name, hunger_count, no_more, counter
	return time, templat, templng, name, hunger_count, no_more, counter
예제 #8
0
def factual_restaurants():
    latitude = float(request.form.get('latitude'))
    longitude = float(request.form.get('longitude'))
    search_term = request.form.get('search_term')
    if not latitude or not longitude:
        return json.dumps({"error": "No location provided"}), 500
    if not search_term:
        return json.dumps({"error": "No search term provided"}), 500

    radius = 1000

    places = factual.table('places')

    # look up restaurants near location
    result = places.search(search_term).geo(circle(latitude, longitude,
                                                   radius)).data()
    return json.dumps(result), 200
예제 #9
0
def testFactual(request):
  LENGTH_OF_ONE_LAT = 111081.59847784671
  LENGTH_OF_ONE_LON = 82291.40843937476
  lat = 42.418837
  lon = -71.130553
  end_lat = 42.33
  end_lon = -71.033440

  while lat >= end_lat:
    while lon <= end_lon:
      print(str(lat) + "," + str(lon))
      LOC = circle(lat, lon, 100)
      getRestaurantDataFromFactual(LOC)
      lon += (100/LENGTH_OF_ONE_LON)
      sleep(1)
    lat -= (100/LENGTH_OF_ONE_LAT)
    lon = -71.130553
  return HttpResponse("OK")
예제 #10
0
def findMidPlace(latitude, longitude):
    geolocator = Nominatim()
    latitudeSum = sum(latitude)
    longitudeSum = sum(longitude)
    latitudeAverage = latitudeSum / len(latitude)
    longitudeAverage = longitudeSum / len(longitude)
    strlatitudeAverage = str(latitudeAverage)
    strlongitudeAverage = str(longitudeAverage)
    midpointLocation = strlatitudeAverage + ", " + strlongitudeAverage
    newLocation = geolocator.reverse(midpointLocation)
    data = places.search(c).geo(circle(latitudeAverage, longitudeAverage,
                                       1000)).limit(10).data()
    resultingData = json.dumps([{
        'Name': x['name'],
        'Address': x['address'],
        'Telephone': x['tel']
    } for x in data],
                               indent=2,
                               sort_keys=True)
    print resultingData

    indexValue = [
        'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
        'nine', 'ten'
    ]
    if (peopleNumber == 1):
        message = client.messages.create(
            to="+12244029741",
            from_="+12244073037",
            body="These are the places around you" + ": " + resultingData)
    elif (peopleNumber <= 10 and peopleNumber > 1):
        a = indexValue[peopleNumber]
        message = client.messages.create(
            to="+12244029741",
            from_="+12244073037",
            body="These are the places that are between you " + a + ": " +
            '\n' + resultingData)
    else:
        message = client.messages.create(
            to="+12244029741",
            from_="+12244073037",
            body="These are the places that are between your group " + a +
            ": " + '\n' + resultingData)
예제 #11
0
 def get_data(self):
     for i in range(10):
         data = (
         places.geo(circle(loc['lat'], loc['lng'], search.radius))
         .filters(
             {"$and":[{"category_ids":
             {"$includes": search.category}}]}
             #chain_ids
         )
         .offset(50*(i))
         .limit(50)
         .data()
         )
 #q = data.get_url())
     print q
     print "Call successful! Records returned:"
     print len(self.data)
     out.extend(self.data)
     print "Total records"
     print len(self.out)
예제 #12
0
    def get_data(self):
        for i in range(10):
            data = (
                places.geo(circle(loc['lat'], loc['lng'],
                                  search.radius)).filters(
                                      {
                                          "$and": [{
                                              "category_ids": {
                                                  "$includes": search.category
                                              }
                                          }]
                                      }
                                      #chain_ids
                                  ).offset(50 * (i)).limit(50).data())

    #q = data.get_url())
        print q
        print "Call successful! Records returned:"
        print len(self.data)
        out.extend(self.data)
        print "Total records"
        print len(self.out)
예제 #13
0
def decideplace(time, track, lat, lng, start, now,f, input2):

	if time<0:
		return time, templat, templng, name

	data = places.filters({'$and':[{'category_ids':{'$includes':track}}]}).geo(circle(lat,lng, 1000*time)).limit(5).data()
	if not data:
		templat = lat
		templng = lng
		name = start
	else:
		data = data[random.randrange(0,len(data))]

		templat = float(data[u'latitude'])
		templng = float(data[u'longitude'])
		name = str(data[u'name'])
		f.write("<p>Go from "+start+" to "+name+" starting at time "+str(now+input2-datetime.timedelta(hours = time))+"</p>\n")
		time = route(now + input2 - datetime.timedelta(hours = time), lat, lng, templat, templng, time, f, input2)
		time -= 1
		printresults_places(data,f)
		
	return time, templat, templng, name
    def factualSearch(self):
        LOGGER.info('Assessing nearby culture')
        if self.dev == True:
            LOGGER.info('Dev is TRUE')
            with open('db/factual_sample.json') as f:
                factual = json.load(f)
                f.close()
            self.results['factual'] = factual
            return 0

        data = self._places.search('').geo(circle(self.location['lat'],self.location['lng'], 1600)).data()

        # if len(data)> 3:
            # l = 3
        # else:
            # l = len(data)

        res = list()
        for index in range(len(data)):
            this = data[index]
            if this['$distance'] < 100:
                distance = 'on the block'
            elif this['$distance'] < 200:
                distance = 'around the corner'
            else:
                distance = 'in the distance'

            obj = {
                    'name':this.get('name', None),
                    'address': this.get('address', None),
                    'rawDistance': this.get('$distance', None),
                    'distance': distance,
                    'categoryLabels': this.get('category_labels', None),
                    'locality': this.get('locality', None),
                    'hours': this.get('hours', {})
                    }
            res.append(obj)
        self.results['factual'] = res
예제 #15
0
def findMidPlace(a, b, c, d):
    geolocator = Nominatim()
    locationA = geolocator.geocode(a)
    locationB = geolocator.geocode(b)
    midpointLat = (locationA.latitude + locationB.latitude) / 2
    print midpointLat
    midpointLong = (locationA.longitude + locationB.longitude) / 2
    print midpointLong
    strMidpointLat = str(midpointLat)
    strMidpointLong = str(midpointLong)
    midpointLocation = strMidpointLat + ", " + strMidpointLong
    newLocation = geolocator.reverse(midpointLocation)
    data = places.search(c).geo(circle(midpointLat, midpointLong,
                                       d)).limit(10).data()
    #cleanData = json.dumps([{'Name': x['name'], 'Address': x['address'], 'Tel': x['tel'], 'Timings':x['hours'][my_day][0][0]+' - ' + x['hours'][my_day][0][1]} for x in data],indent=2, sort_keys=True)
    cleanData = json.dumps([{
        'Name': x['name'],
        'Address': x['address']
    } for x in data],
                           indent=2,
                           sort_keys=True)

    print cleanData
예제 #16
0
파일: maps.py 프로젝트: julms/CookATour-2.0
def decidefood(time, lat, lng, start, now,f, input2, places_been, hunger_count, input4, counter):

	if time<0:
		return time, templat, templng, name, hunger_count
	if time<1:
		data = places.filters({'$and':[{'category_ids':{'$includes':338}}, {'category_ids':{'$excludes':341}}]}).geo(circle(lat,lng,1000*time)).data()
		time -= 0.25	
	else:
		data = places.filters({'$and':[{'category_ids':{'$includes':347}}]}).geo(circle(lat,lng,1000*time)).data()
		time -= 1
	f.write("<p><br><br><b>Time for a Snack!</b></p>\n")

	try:
		while True:
			temp_place = data[random.randrange(0,len(data))]
			if temp_place[u'name'] in places_been:
				continue
			else:
				places_been.setdefault(temp_place[u'name'], 0)
				break


		templat = float(temp_place[u'latitude'])
		templng = float(temp_place[u'longitude'])
		name = str(temp_place[u'name'])
		current_time = now+input2-datetime.timedelta(hours = time)
		current_time = current_time.strftime('%I:%M %p')
		f.write("<p><br><br><b>Go from "+ start+" to "+ name+" starting at time " +str(current_time)+"</b></p>\n")
		time, hunger_count, counter = route(now + input2 - datetime.timedelta(hours = time), lat, lng, templat, templng, time,f, input2, hunger_count, input4, counter)
		counter = printresults_food(temp_place,f, counter)

		#print time
	except:
		templat = lat
		templng = lng
		name = start
	return time, templat, templng, name, hunger_count, counter
예제 #17
0
 def test_geo(self):
     q = self.places.search('factual').geo(circle(34.06021, -118.41828, 1000))
     row = q.data()[0]
     self.assertEqual('Factual', row['name'])
     self.assertEqual('1801 Avenue Of The Stars', row['address'])
예제 #18
0
 def test_facets_geo(self):
     q = self.facets.select("locality").geo(circle(34.06018, -118.41835, 1000))
     locality = q.data()['locality']
     self.assertTrue(locality['los angeles'] > 3000)
     self.assertTrue(locality['beverly hills'] > 500)
예제 #19
0
 def test_geo(self):
     q = self.places.search("factual").geo(circle(34.06021, -118.41828, 1000))
     row = q.data()[0]
     self.assertEqual("Factual", row["name"])
     self.assertEqual("1801 Avenue Of The Stars", row["address"])
예제 #20
0
 def test_facets_geo(self):
     q = self.facets.select("category").geo(circle(34.06018, -118.41835, 5000))
     category = q.data()["category"]
     self.assertTrue(category["shopping"] > 1000)
     self.assertTrue(category["health & medicine > physicians"] > 1000)
예제 #21
0
 def get_landmarks(self, lat, lng):
     data = self.places.geo(circle(lat, lng, 800)).data()
     return data
예제 #22
0
 def test_geo(self):
     q = self.places.search('factual').geo(
         circle(34.06021, -118.41828, 1000))
     row = q.data()[0]
     self.assertEqual('Factual', row['name'])
     self.assertEqual('1999 Avenue Of The Stars', row['address'])
예제 #23
0
 def geofilters(self, tableName, searchContent, latitude, longitude,
                radius):
     table = self.db.table(tableName)
     data = table.search(searchContent).geo(
         circle(latitude, longitude, radius)).data()
     return data
예제 #24
0
 def test_facets_geo(self):
     q = self.facets.select("category").geo(
         circle(34.06018, -118.41835, 5000))
     category = q.data()['category']
     self.assertTrue(category['shopping'] > 1000)
     self.assertTrue(category['health & medicine > physicians'] > 1000)
예제 #25
0
	def query_restaurants_by_proximity(self, factual, category_ids, lat, long, radius_meters):
		print("Querying restaurants for: lat, long, radius: %f, %f, %f" % (lat, long, radius_meters))
		return self.factual.table(TABLE_ID).filters({'$and': [{'$or': [{'website': {'$blank': False}},  
			{'email': {'$blank': False}}]}, 
			{'category_ids': {'$includes_any':category_ids}}]}).geo(circle(lat, long, radius_meters)).include_count(True)
예제 #26
0
파일: maps.py 프로젝트: rybo449/CookATour
		except:
			print
			print i[u'html_instructions']

	
	time_left -=time_taken/float(60*60)
	sleeper.sleep(0.1)
	return time_left


def decideplace(time, track, lat, lng, start):
>>>>>>> c3df4b30bcb4782fb260bf1a8743f107e0525d61
	if time<0:
		return time, templat, templng, name

	data = places.filters({'$and':[{'category_ids':{'$includes':track}}]}).geo(circle(lat,lng, 1000*time)).limit(5).data()
	if not data:
		templat = lat
		templng = lng
		name = start
	else:
		data = data[random.randrange(0,len(data))]

		templat = float(data[u'latitude'])
		templng = float(data[u'longitude'])
		name = str(data[u'name'])
<<<<<<< HEAD
		f.write("<p>Go from "+start+" to "+name+" starting at time "+str(now+input2-datetime.timedelta(hours = time))+"</p>\n")
		time = route(now + input2 - datetime.timedelta(hours = time), lat, lng, templat, templng, time, f, input2)
		time -= 1
		printresults_places(data,f)
예제 #27
0
파일: __init__.py 프로젝트: rybo449/tlc
 def get_landmarks(self, lat, lng):
     data = self.places.geo(circle(lat, lng, 800)).data()
     return data
예제 #28
0
 def test_facets_geo(self):
     q = self.facets.select("locality").geo(
         circle(34.06018, -118.41835, 1000))
     locality = q.data()['locality']
     self.assertTrue(locality['los angeles'] > 3000)
     self.assertTrue(locality['beverly hills'] > 500)
예제 #29
0
def fetchData(lat, lon):
    from factual.utils import circle
    places = factualClient.table("places")
    data = places.search("bar").geo(circle(lat, lon, 1000)).data()
    return data
예제 #30
0
def get_neighbors(latitude, longitude, radius=DEFAULT_RADIUS):
	factual = Factual('IVLfuMgT7A6YzCX0qcgaN19EfYSoCVg207m7pOIf', 'qVfst8GPhiYUoDueRYo0a8ub5F6yDUW3XIYymHGr')
	places_table = factual.table('places-us')
	data = places_table.filters({'category_ids':{'$includes_any':PLACE_TYPE}}).geo(circle(latitude, longitude, radius)).data()
	return data
예제 #31
0
 def geofilters(self, tableName, searchContent, latitude, longitude, radius):
     table = self.db.table(tableName)
     data = table.search(searchContent).geo(circle(latitude, longitude, radius)).data()
     return data