예제 #1
0
    def test_get_dist(self):
        point1 = (0, 0)
        point2 = (2, 0)
        # basic test
        self.assertEqual(FoodTruck.get_dist(point1, point2), 2)

        # make sure it works, tested with wolfram alpha
        point2 = (37.111, 120.55)
        self.assertEqual(FoodTruck.get_dist(point1, point2), 126.13298070290736)
예제 #2
0
    def test_get_dist(self):
        point1 = (0, 0)
        point2 = (2, 0)
        # basic test
        self.assertEqual(FoodTruck.get_dist(point1, point2), 2)

        # make sure it works, tested with wolfram alpha
        point2 = (37.111, 120.55)
        self.assertEqual(FoodTruck.get_dist(point1, point2),
                         126.13298070290736)
예제 #3
0
def find_closest(request):
    get_data = request.GET
    errors = []
    user_lat = get_data.get('latitude', '')
    user_lon = get_data.get('longitude', '')
    num_trucks = get_data.get('num_trucks', 10)
    nearest_trucks = FoodTruck.get_closest(user_lat, user_lon, num_trucks)
    response = {'status': 200, 'nearest_trucks': nearest_trucks}
    return HttpResponse(json.dumps(response), content_type='application/json')
예제 #4
0
	def endElement(self, name):
		if name == 'Placemark':
			truck = FoodTruck(key=self.curr_id, name=self.curr_name, foodType=self.curr_description, position=self.curr_position)
			truck.save()
			print "saved: "+ str(truck);
			self.curr_name = ""
			self.curr_description = ""
			self.curr_position = Position(lat=0,lon=0)
			self.curr_id = 0
			self.buff = ""
		elif name == 'name':
			self.curr_name = self.buff
		elif name == 'description':
			self.curr_description = self.buff
		elif name == 'coordinates':
			coords = self.buff.split(",")
			print "float(coords[0])" + str(coords[0]) + "float(coords[1])" + str(coords[1])
			self.curr_position = Position(lat=float(coords[1]), lon=float(coords[0]))
			self.curr_position.save()
		self.buff = ""
예제 #5
0
    def test_get_closest(self):
        truck1 = FoodTruck.objects.get(truck_name="truck1")
        truck2 = FoodTruck.objects.get(truck_name="truck2")
        truck3 = FoodTruck.objects.get(truck_name="truck3")
        truck4 = FoodTruck.objects.get(truck_name="truck4")
        truck5 = FoodTruck.objects.get(truck_name="truck5")

        # results closest to origin should be truck 1 and truck 3, it should ignore truck 2 because it
        # does not have sane long/lat values
        result = FoodTruck.get_closest(0, 0, 2)
        self.assertIn(truck1.get_info(), result)
        self.assertIn(truck3.get_info(), result)
        self.assertNotIn(truck2.get_info(), result)
        self.assertNotIn(truck4.get_info(), result)
        self.assertNotIn(truck5.get_info(), result)

        # results closest on the opposite end of origin should be truck 4 and truck 5,
        result = FoodTruck.get_closest(100, 100, 2)
        self.assertIn(truck4.get_info(), result)
        self.assertIn(truck5.get_info(), result)
예제 #6
0
    def test_get_closest(self):
        truck1 = FoodTruck.objects.get(truck_name="truck1")
        truck2 = FoodTruck.objects.get(truck_name="truck2")
        truck3 = FoodTruck.objects.get(truck_name="truck3")
        truck4 = FoodTruck.objects.get(truck_name="truck4")
        truck5 = FoodTruck.objects.get(truck_name="truck5")

        # results closest to origin should be truck 1 and truck 3, it should ignore truck 2 because it
        # does not have sane long/lat values
        result = FoodTruck.get_closest(0, 0, 2)
        self.assertIn(truck1.get_info(), result)
        self.assertIn(truck3.get_info(), result)
        self.assertNotIn(truck2.get_info(), result)
        self.assertNotIn(truck4.get_info(), result)
        self.assertNotIn(truck5.get_info(), result)

        # results closest on the opposite end of origin should be truck 4 and truck 5,
        result = FoodTruck.get_closest(100, 100, 2)
        self.assertIn(truck4.get_info(), result)
        self.assertIn(truck5.get_info(), result)
예제 #7
0
def find_closest(request):
    get_data = request.GET 
    errors = []
    user_lat = get_data.get('latitude', '')
    user_lon = get_data.get('longitude', '')
    num_trucks = get_data.get('num_trucks', 10)
    nearest_trucks = FoodTruck.get_closest(user_lat, user_lon, num_trucks)
    response = {
               'status': 200,
               'nearest_trucks': nearest_trucks
              }
    return HttpResponse(json.dumps(response), content_type='application/json')
예제 #8
0
def saveRowAsTruck(worksheet, row_index):
	if (isValidTruck(worksheet, row_index)):
		flat = worksheet.cell_value(row_index, 6)
		flon = worksheet.cell_value(row_index, 7)
		floc = worksheet.cell_value(row_index, 4)
		p = Position(lat=float(flat), lon=float(flon))
		p.save()

		if (worksheet.cell_type(row_index, 3) is not 1):
			fname = "Food Cart"
		else:
			fname = worksheet.cell_value(row_index, 3)

		if (worksheet.cell_type(row_index, 5) is not 1):
			fdescription = "Mystery Food"
		else:
			fdescription = worksheet.cell_value(row_index, 5)

		fkey = worksheet.cell_value(row_index, 0)
		t = FoodTruck(key=fkey, name=fname, foodType=fdescription, position=p, location=floc)
		t.save()
예제 #9
0
파일: server.py 프로젝트: rkrage/grubfinder
 def get(self):
     args = self.reqparse.parse_args()
     address = args['address']
     latitude = args['latitude']
     longitude = args['longitude']
     result = []
     if address is not None:
         latitude, longitude = self.geocode(address)
     if latitude is not None and longitude is not None:
         # get 20 trucks closest to geolocation ordered by distance (will only return trucks within 3 km)
         query = FoodTruck.query.filter(FoodTruck.distance(latitude,longitude) < 3).order_by(FoodTruck.distance(latitude,longitude)).limit(20)
     else:
         query = FoodTruck.query.all()
     for truck in query:
         result.append(truck.as_dict())
     return result