Example #1
0
 def mock_get_all(self) -> List[Ride]:
     return [
         Ride(0, datetime.fromisoformat('2020-01-01T23:00:00'), 24,
              timedelta(seconds=3600)),
         Ride(1, datetime.fromisoformat('2020-01-01T23:00:00'), 48,
              timedelta(seconds=7200)),
     ]
Example #2
0
 def mock_get_all(self) -> List[Ride]:
     return [
         Ride(0, datetime.fromisoformat('2020-01-01T13:00:00'), 0,
              timedelta(seconds=600)),
         Ride(1, datetime.fromisoformat('2020-01-01T13:00:00'), 100,
              timedelta(seconds=0)),
         Ride(2, datetime.fromisoformat('2020-01-01T13:00:00'), 0,
              timedelta(seconds=0))
     ]
Example #3
0
        def start_ride_helper(session, city, rider_id, vehicle_id):
            vehicle = session.query(Vehicle).filter_by(
                city=city, id=vehicle_id
            ) if self.multi_region else session.query(Vehicle).filter_by(
                id=vehicle_id)
            vehicle.update({'status': 'in_use'})
            v = vehicle.first()
            # get promo codes associated with this user's account
            upcs = session.query(UserPromoCode).filter_by(
                city=city, user_id=rider_id).all(
                ) if self.multi_region else session.query(
                    UserPromoCode).filter_by(user_id=rider_id).all()

            # determine which codes are valid
            for upc in upcs:
                promo_code = session.query(PromoCode).filter_by(
                    code=upc.code).first()
                if promo_code and promo_code.expiration_time > datetime.datetime.now(
                ):
                    code_to_update = session.query(UserPromoCode).filter_by(
                        city=city, user_id=rider_id,
                        code=upc.code) if self.multi_region else session.query(
                            UserPromoCode).filter_by(user_id=rider_id,
                                                     code=upc.code)
                    code_to_update.update({'usage_count': upc.usage_count + 1})

            r = Ride(city=city,
                     id=MovRGenerator.generate_uuid(),
                     rider_id=rider_id,
                     vehicle_id=vehicle_id,
                     start_address=v.current_location)

            session.add(r)
            return {'city': r.city, 'id': r.id}
Example #4
0
def writetoDB():
    data = request.get_json()
    if data["table"] == "User":
        # Add a new User
        if data["caller"] == "addUser":
            responseToReturn = Response()
            if checkHash(data["password"]):
                newUser = User(username = data["username"], password = data["password"])
                db.session.add(newUser)
                db.session.commit()
                responseToReturn.status_code = 201
            else:
                responseToReturn.status_code = 400
            return (responseToReturn.text, responseToReturn.status_code, responseToReturn.headers.items())
        # Remove an existing User     
        elif data["caller"] == "removeUser":
            User.query.filter_by(username = data["username"]).delete()
            Ride.query.filter_by(created_by = data["username"]).delete()
            db.session.commit()
            responseToReturn = Response()
            responseToReturn.status_code = 200
            return (responseToReturn.text, responseToReturn.status_code, responseToReturn.headers.items())

    elif data["table"] == "Ride":
        # Add a new Ride
        if data["caller"] == "createRide":
            source = int(data["source"])
            dest = int(data["destination"])
            responseToReturn = Response()
            if source in range(1, noRows + 1) and dest in range(1, noRows + 1):
                newRide = Ride(created_by = data["created_by"], username = "", timestamp = data["timestamp"],
                        source = source, destination = dest)
                db.session.add(newRide)
                db.session.commit()
                responseToReturn.status_code = 201
            else:
                responseToReturn.status_code = 400
            return (responseToReturn.text, responseToReturn.status_code, responseToReturn.headers.items())

        elif data["caller"] == "joinRide":
            rideExists = Ride.query.filter_by(ride_id = data["rideId"]).first()
            if rideExists.username:
                rideExists.username += ", " + data["username"]
            else:
                rideExists.username += data["username"]
            db.session.commit()
            responseToReturn = Response()
            responseToReturn.status_code = 200
            return (responseToReturn.text, responseToReturn.status_code, responseToReturn.headers.items())

        elif data["caller"] == "deleteRide":
            Ride.query.filter_by(ride_id = data["rideId"]).delete()
            db.session.commit()
            responseToReturn = Response()
            responseToReturn.status_code = 200
            return (responseToReturn.text, responseToReturn.status_code, responseToReturn.headers.items())
Example #5
0
    def add_rides_helper(sess, chunk, n):
        users = sess.query(User).filter_by(city=city).all()
        vehicles = sess.query(Vehicle).filter_by(city=city).all()

        rides = []
        for i in range(chunk, min(chunk + chunk_size, num_rides)):
            start_time = datetime.datetime.now() - datetime.timedelta(days=random.randint(0, 30))
            rides.append(Ride(id=MovRGenerator.generate_uuid(),
                              city=city,
                              rider_id=random.choice(users).id,
                              vehicle_id=random.choice(vehicles).id,
                              start_time=start_time,
                              start_address=datagen.address(),
                              end_address=datagen.address(),
                              revenue=MovRGenerator.generate_revenue(),
                              end_time=start_time + datetime.timedelta(minutes=random.randint(0, 60))))
        sess.bulk_save_objects(rides)
Example #6
0
        def start_ride_helper(session, city, rider_id, vehicle_id):
            v = session.query(Vehicle).filter_by(city=city, id=vehicle_id).first()

            # get promo codes associated with this user's account
            upcs = session.query(UserPromoCode).filter_by(city=city, user_id=rider_id).all()

            # determine which codes are valid
            for upc in upcs:
                promo_code = session.query(PromoCode).filter_by(code = upc.code).first()
                if promo_code and promo_code.expiration_time > datetime.datetime.now():
                    upc.usage_count+=1;
                    #@todo: do something with the code

            r = Ride(city=city, vehicle_city=city, id=MovRGenerator.generate_uuid(),
                     rider_id=rider_id, vehicle_id=vehicle_id,
                     start_address=v.current_location)
            session.add(r)
            v.status = "in_use"
            return {'city': r.city, 'id': r.id}
Example #7
0
 def mock_get_all(self) -> List[Ride]:
     return [
         Ride(0, datetime.fromisoformat('2020-01-01T23:00:00'), 192,
              timedelta(seconds=28800)),
     ]