예제 #1
0
 def post(self):
     required_params = {
         'user_id':'str',
         'origin_venue':'str',
         'dest_lon':'float',
         'dest_lat':'float',
         'departure_time':'float'
     }
     if not self.check_params(required_params): return
     
     if 'ride_id' not in self.request.arguments or not self.get_argument('ride_id'): ride_id=None            
     else: ride_id=self.get_argument('ride_id')
     
     if 'origin_pickup' not in self.request.arguments or not self.get_argument('origin_pickup'): origin_pickup=None            
     else: origin_pickup=self.get_argument('origin_pickup')
     
     user_id = self.get_argument('user_id')
     origin_venue = self.get_argument('origin_venue')
     origin_pick_up = self.get_argument('origin_pickup')
     dest_lon = float(self.get_argument('dest_lon'))
     dest_lat = float(self.get_argument('dest_lat'))
     departure_time = float(self.get_argument('departure_time'))
         
     resp = RideHelper.create_or_update_ride(user_id=user_id, ride_id=ride_id, origin_venue=origin_venue, 
                                             origin_pick_up=origin_pickup,
                                             dest_lon=dest_lon, dest_lat=dest_lat, 
                                             departure_time=departure_time)
     self.write(resp)
예제 #2
0
    def post(self):
        required_params = {
            'user_id': 'str',
            'origin_venue': 'str',
            'dest_lon': 'float',
            'dest_lat': 'float',
            'departure_time': 'float'
        }
        if not self.check_params(required_params): return

        if 'ride_id' not in self.request.arguments or not self.get_argument(
                'ride_id'):
            ride_id = None
        else:
            ride_id = self.get_argument('ride_id')

        if 'origin_pickup' not in self.request.arguments or not self.get_argument(
                'origin_pickup'):
            origin_pickup = None
        else:
            origin_pickup = self.get_argument('origin_pickup')

        user_id = self.get_argument('user_id')
        origin_venue = self.get_argument('origin_venue')
        origin_pick_up = self.get_argument('origin_pickup')
        dest_lon = float(self.get_argument('dest_lon'))
        dest_lat = float(self.get_argument('dest_lat'))
        departure_time = float(self.get_argument('departure_time'))

        resp = RideHelper.create_or_update_ride(user_id=user_id,
                                                ride_id=ride_id,
                                                origin_venue=origin_venue,
                                                origin_pick_up=origin_pickup,
                                                dest_lon=dest_lon,
                                                dest_lat=dest_lat,
                                                departure_time=departure_time)
        self.write(resp)
예제 #3
0
def add_rides():
    # Using user_1 add a ride that will be used to search for matches
    phone = test_data.user_1.get('phone')
    user = UserHelper.get_user_by_phone(phone)
    user_id = user.get(User.A_USER_ID)
    dt = datetime.datetime.now()
    departure_timestamp = time.mktime(dt.timetuple())
    dest_lat = 40.65
    dest_lon = 73.78
    origin_place = 'jfk'
    origin_pick_up = 'Terminal A'
    ride_id_doc = RideHelper.create_or_update_ride(user_id, origin_place,
                                                   origin_pick_up, dest_lon,
                                                   dest_lat,
                                                   departure_timestamp)
    ride_id = ride_id_doc.get('ride_id')

    # Check to see that the ride info was stored
    ride = RideHelper.get_ride(ride_id)
    print "ride to match"
    print ride
    print "ride to match id"
    print ride_id
    ride_to_match_id = ride_id

    # Check for a ride that does not exist
    ride_id = "10291032491203"
    ride = RideHelper.get_ride(ride_id)
    print "should return an error, no ride exists"
    print ride

    # Switch users to user_4
    phone = test_data.user_4.get('phone')
    user = UserHelper.get_user_by_phone(phone)
    user_id = user.get("user_id")
    print "current user:"******"Ride that will leave 2 hrs later"
    print ride

    # Create another ride that will go to a far away destination for user_4

    ride_id = RideHelper.create_or_update_ride(user_id, origin_place,
                                               origin_pick_up, dest_lon + 10,
                                               dest_lat + 10,
                                               departure_timestamp)
    ride_id = ride_id_doc.get('ride_id')
    # Check to see that the ride info was stored
    ride = RideHelper.get_ride(ride_id)
    print "Ride with far away destination"
    print ride

    # Create another ride that will be an ideal match, only .5 degrees further for user_4
    ride_id = RideHelper.create_or_update_ride(user_id, origin_place,
                                               origin_pick_up,
                                               dest_lon + 0.005,
                                               dest_lat + 0.005,
                                               departure_timestamp)
    ride_id = ride_id_doc.get('ride_id')
    # Check to see that the ride info was stored
    ride = RideHelper.get_ride(ride_id)
    print "Ride with only .5 degrees distance from ride to match"
    print ride

    # Switch to user 3
    phone = test_data.user_3.get('phone')
    user = UserHelper.get_user_by_phone(phone)
    user_id = user.get(User.A_USER_ID)

    # Create another ride that will be an ideal match with only .5 degrees further for user_3
    ride_id = RideHelper.create_or_update_ride(user_id, origin_place,
                                               origin_pick_up,
                                               dest_lon + 0.003,
                                               dest_lat + 0.003,
                                               departure_timestamp + 10 * 60)
    ride_id = ride_id_doc.get('ride_id')
    # Check to see that the ride info was stored
    ride = RideHelper.get_ride(ride_id)
    print "Ride with only .3 degrees distance from ride to match"
    print ride

    # Create another ride that leaves from a different origin for user_3
    origin_place = "jfk"
    origin_pick_up = "Terminal B"
    ride_id = RideHelper.create_or_update_ride(user_id, origin_place,
                                               origin_pick_up, dest_lon,
                                               dest_lat, departure_timestamp)
    # Check to see that the ride info was stored
    ride = RideHelper.get_ride(ride_id)
    print "Ride with different origin, same max distance"
    print ride
    return ride_to_match_id