def main():
    car = Car("Ford Pinto")
    bike = Bike("BMX")

    vehicles = [car, bike]

    for vehicle in vehicles:
        vehicle.start()
        vehicle.move()
        vehicle.stop()
Beispiel #2
0
    def __populateVehicles(self, vehicle_file):
        """Gets vehicles from vehicle_file. Raises InvalidFileFormatError."""
        
        empty_str = ''

        # init vehicle string file headers
        vehicle_file_headers = ('#CARS#', '#VANS#', '#TRUCKS#')
        vehicle_type_index = 0
        
        # read first line of file (#CARS# expected)
        vehicle_str = vehicle_file.readline()
        vehicle_info = vehicle_str.rstrip().split(',')
        file_header_found = vehicle_info[0]
        expected_header = vehicle_file_headers[0]

        if file_header_found != expected_header:
            raise InvalidFileFormatError(expected_header, VEHICLES_FILENAME)
        else:
            # read next line of file after #CARS# header line
            vehicle_str = vehicle_file.readline()
            
            while vehicle_str != empty_str:

                # convert comma-separated string into list of strings
                vehicle_info = vehicle_str.rstrip().split(',')

                if vehicle_info[0][0] == '#':
                    vehicle_type_index = vehicle_type_index + 1
                    file_header_found = vehicle_info[0]
                    expected_header = vehicle_file_headers[vehicle_type_index]

                    if file_header_found !=  expected_header:
                        raise InvalidFileFormatError(expected_header,
                                                     VEHICLES_FILENAME)
                else:    

                    # create new vehicle object of the proper type
                    if file_header_found == '#CARS#':
                        vehicle = Car(*vehicle_info)
                    elif file_header_found == '#VANS#':
                        vehicle = Van(*vehicle_info)
                    elif file_header_found == '#TRUCKS#':
                        vehicle = Truck(*vehicle_info)
                    
                    # add new vehicle to vehicles list
                    self.__vehicles.addVehicle(vehicle)

                # read next line of vehicle information
                vehicle_str = vehicle_file.readline()
Beispiel #3
0
 def spawnVehicle(self, entryL = None, exitL = None):
     if not entryL:
         entryL = self.crossroad.randomEntry()
     if not entryL:
         #print('I: Could not spawn vehicle right now')
         return
     if not exitL:
         exitL = self.crossroad.randomExit(entryL)
     if const.randint(0,100) >= const.SPAWN_TYPE:
         newVehicle = Bus(self, self.crossroad, entryL)
     else:
         newVehicle = Car(self, self.crossroad, entryL)
     # For now we set that all cars do not turn
     newVehicle.setObjective(exitL)#self.crossroad.getOppositeLanes(newVehicle,const.LEFT)[0])#
     self.vehicles.append(newVehicle)
     self.hourlyData['vehicle_count'] += 1
     return newVehicle
Beispiel #4
0
def main():

    print(f'Please check debug output at {LOG_FILE}\n')

    new_car = Car(capacity=500,
                  weight=2000,
                  number_of_wheels=4,
                  engine_number_of_cylinders=4,
                  engine_type='gazoline',
                  engine_capacity=2000,
                  fuel=5)
    print(new_car)
    new_car.make_beep()
    new_car.start()
    new_car.stop()

    print()
    new_boat = Boat(
        capacity=500,
        weight=2500,
        number_of_passengers=2,
    )
    print(new_boat)
    new_boat.make_beep()
    new_boat.start()
    new_boat.stop()

    print()
    new_wherry = Wherry(capacity=50000,
                        weight=60000,
                        number_of_passengers=4,
                        engine_number_of_cylinders=12,
                        engine_type='diesel',
                        engine_capacity=20000,
                        fuel=50)
    print(new_wherry)
    new_wherry.make_beep()
    new_wherry.start()
    new_wherry.stop()
    print('Setting fuel to 0 and trying to start engine.')
    new_wherry.fuel = 0
    new_wherry.start()
def add_vehicle_to_inventory():

    if request.method == "POST":

        req = request.form

        print(req)

        vehicle_type = req.get("vehicle_type").title()
        vehicle_colour = req.get("colour")
        vehicle_weight = req.get("weight")
        vehicle_brand = req.get("brand")
        vehicle_motor_type = req.get("motor_type")

        if vehicle_type.title() == 'Car':
            new_car = Car(vehicle_colour, vehicle_weight, vehicle_brand)

            print(new_car)

            VehicleInventory.ALL_VEHICLES.append(new_car)

        if vehicle_type.title() == 'Boat':
            new_boat = Boat(vehicle_colour, vehicle_weight, vehicle_brand,
                            vehicle_motor_type)

            print(new_boat)

            VehicleInventory.ALL_VEHICLES.append(new_boat)

        if vehicle_type.title() == 'Plane':
            new_plane = Plane(vehicle_colour, vehicle_weight, vehicle_brand)

            print(new_plane)

            VehicleInventory.ALL_VEHICLES.append(new_plane)

        return redirect('/')

    return render_template("index.html")
        x3, y3 = 727, 187
        x4, y4 = 790, 719
        lineThickness = 2
        cv2.line(frame, (x3, y3), (x4, y4), (0, 0, 255), 2)

        gray = cv2.cvtColor(frame[180:], cv2.COLOR_BGR2GRAY)

        objects = car_cascade.detectMultiScale(gray, 1.2, 5)

        for (x, y, w, h) in objects:
            y += 180
            found = False
            cx, cy = x + w / 2, y + h / 2
            if len(cars) == 0:
                newCar = Car(pid, cx, cy, frameCount)
                cars.append(newCar)
                allCars.add(newCar)
                pid += 1
                continue
            for i in cars:
                if abs(cx - i.getCX()) <= 30 and abs(cy - i.getCY()) <= 30:
                    found = True
                    i.updateCoords(cx, cy)
                    i.updateFrameCount(frameCount)
                    allCars.add(i)
                    break
            if not found:
                newCar = Car(pid, cx, cy, frameCount)
                cars.append(newCar)
                allCars.add(newCar)
Beispiel #7
0
def create_vehicles(race: Race):
    for i in range(10):
        race.register_racer(Car())
        race.register_racer(Motorcycle())
        race.register_racer(Truck())
Beispiel #8
0
    def handle_input(self):

        self.ans = input("What would you like to do? ")

        # Enter a Vehicle
        if self.ans == "1":
            choice = input("Enter vehicle type\n1: Car\n"
                           "2: Plane\n"
                           "3: Boat\n")

            # Car
            if choice == "1":

                car_colour = input("Car Colour: ")
                car_weight = int(input("Car Weight: "))
                car_brand = input("Brand: ")

                new_car = Car(car_colour, car_weight, car_brand)

                # str_new_car = str(new_car).replace('\n', " ")

                VehicleInventory.ALL_VEHICLES.append(new_car)

                main_menu()

            # Plane
            elif choice == "2":

                plane_colour = input("Plane Colour: ")
                plane_weight = int(input("Plane Weight: "))
                plane_brand = input("Brand: ")

                new_plane = Plane(plane_colour, plane_weight, plane_brand)

                # str_new_plane = str(new_plane).replace('\n', " ")

                VehicleInventory.ALL_VEHICLES.append(new_plane)

                main_menu()

            # Boat
            elif choice == "3":

                boat_colour = input("Boat Colour: ")
                boat_weight = int(input("Boat Weight: "))
                boat_brand = input("Boat Brand: ")
                boat_motor_type = input("Motor Type: ")

                new_boat = Boat(boat_colour, boat_weight, boat_brand,
                                boat_motor_type)

                # str_new_boat = str(new_boat).replace('\n', " ")

                VehicleInventory.ALL_VEHICLES.append(new_boat)

                main_menu()

        # Remove a Vehicle
        elif self.ans == "2":
            vehicle_to_remove = int(input('Vehicle number to be removed: '))
            index_of_vehicle_to_remove = vehicle_to_remove - 1
            del VehicleInventory.ALL_VEHICLES[index_of_vehicle_to_remove]
            main_menu()

        # Print all Vehicles
        elif self.ans == "3":
            print('\n')
            print("Printing all vehicles...\n")
            for (i, item) in enumerate(VehicleInventory.ALL_VEHICLES, start=1):
                print(i, item)
            main_menu()

        # Exit system
        elif self.ans == "4":
            sys.exit()

        # Handle other inputs
        elif self.ans != "":
            print("\n Not Valid Choice Try again")
            main_menu()
Beispiel #9
0
from vehicles import Car, ElectricCar

ferrari = Car("Ferrari", "200")
ferrari.run_car()

leaf = ElectricCar("Leaf", "70", "all electric")
leaf.run_car()
leaf.display_electric_type()

# alternatively one can import all the classes at once by just naming
# the module.  but then you
# can't access the classes unless you prefix them with the
# module name:
import vehicles

ferrari = vehicles.Car("Ferrari", "200")
ferrari.run_car()

leaf = vehicles.ElectricCar("Leaf", "70", "all electric")
leaf.run_car()
leaf.display_electric_type()


Beispiel #10
0
from vehicles import Car, Motorcycle

car1 = Car("Ford", "blue")
car2 = Car("Honda", "red")
car3 = Car("Volkswagon", "green")

bike1 = Motorcycle(200, "pink")
bike2 = Motorcycle(175, "grey")

car2.display()
bike1.display()
Beispiel #11
0
 def do_enter(self, args):
     """Simulates vehicle entering the parking queue"""
     vh = Car()
     pl.enter_parking_lot_queue(vh)
Beispiel #12
0
    def handle_input(self):
        """Get the user choice from the main menu"""

        self.ans = input("What would you like to do? ")

        # Enter a Vehicle
        if self.ans == "1":
            vehicle_choice = input("Enter vehicle type, choose from:\n"
                                   "1: Car\n"
                                   "2: Plane\n"
                                   "3: Boat\n"
                                   "\nChoice: ")

            # Car
            if vehicle_choice == "1":
                print('\nEnter Car details:\n')
                car_colour = input("Car Colour: ")
                car_weight = int(input("Car Weight: "))
                car_brand = input("Brand: ")

                new_car = Car(car_colour,
                              car_weight,
                              car_brand)

                # str_new_car = str(new_car).replace('\n', " ")

                VehicleInventory.ALL_VEHICLES.append(new_car)

                main_menu()

            # Plane
            elif vehicle_choice == "2":
                print('\nEnter Plane details:\n')
                plane_colour = input("Plane Colour: ")
                plane_weight = int(input("Plane Weight: "))
                plane_brand = input("Brand: ")

                new_plane = Plane(plane_colour,
                                  plane_weight,
                                  plane_brand)

                # str_new_plane = str(new_plane).replace('\n', " ")

                VehicleInventory.ALL_VEHICLES.append(new_plane)

                main_menu()

            # Boat
            elif vehicle_choice == "3":
                print('\nEnter Boat details:\n')
                boat_colour = input("Boat Colour: ")
                boat_weight = int(input("Boat Weight: "))
                boat_brand = input("Boat Brand: ")
                boat_motor_type = input("Motor Type: ")

                new_boat = Boat(boat_colour,
                                boat_weight,
                                boat_brand,
                                boat_motor_type)

                # str_new_boat = str(new_boat).replace('\n', " ")

                VehicleInventory.ALL_VEHICLES.append(new_boat)

                main_menu()

        # Remove a Vehicle
        elif self.ans == "2":
            vehicle_to_remove_from_inventory \
                = int(input('Vehicle number to be removed: '))
            index_of_vehicle_to_remove_from_inventory \
                = vehicle_to_remove_from_inventory - 1
            del VehicleInventory \
                .ALL_VEHICLES[index_of_vehicle_to_remove_from_inventory]
            main_menu()

        # Print all Vehicles
        elif self.ans == "3":
            print('\n')
            print("All vehicles in inventory...\n")
            for (i, item) in enumerate(VehicleInventory.ALL_VEHICLES, start=1):
                print(i, item)
            main_menu()

        # Current rentals
        elif self.ans == "4":
            print('\n')
            print('Currently rented vehicles...\n')
            for (i, item) in enumerate(RentalLog.CURRENT_RENTALS, start=1):
                print(i, item)
            main_menu()

        # Rent a Vehicle
        elif self.ans == "5":
            print('\n')
            print("All vehicles available to rent: \n")
            for (i, item) in enumerate(VehicleInventory.ALL_VEHICLES, start=1):
                print(i, item)
            vehicle_number_to_rent = int(input(
                '\nWhich vehicle number do you want to rent: '))
            vehicle_index = vehicle_number_to_rent - 1
            RentVehicle(vehicle_index)
            main_menu()

        # Exit system
        elif self.ans == "6":
            sys.exit()

        # Handle other inputs
        elif self.ans != "":
            print("\n Not Valid Choice Try again")
            main_menu()
Beispiel #13
0
from vehicles import Car
from vehicles import Trinket
from protocol import *
from logger import *
from crypto_side import *

if __name__ == '__main__':

    # turns logger off, on - 1
    Logger.config(0)

    # initialize sides
    car_alice = Car('Camry 3.5')
    trinket_bob = Trinket('Bob')
    trinket_eva = Trinket('Eva')

    # reset crypto-keys (public and secret)
    car_alice.reset_keys()
    trinket_bob.reset_keys()
    trinket_eva.reset_keys()

    # creating car-trinket pair
    register(trinket_bob, car_alice)

    # test of closing car
    print('\n===== TEST: Bob, Alice, close =====\n')
    trinket_bob.set_command(1)  # 0 - open, 1 - close, other - unknown
    handshake(trinket_bob, car_alice)
    challenge(trinket_bob, car_alice)
    response(trinket_bob, car_alice)
Beispiel #14
0
    def is_queue_full(self):
        '''
        checks if the queue is full
        '''
        return len(self._vehicles) == MAX_VEHICLES_IN_QUEUE

    def get_current_number_of_vehicles_inqueue(self):
        return len(self._vehicles)


if __name__ == '__main__':
    # my quick unit test area
    lot = ParkingLot()
    for v in [
            Car(),
            MotorCycle(),
            MotorCycle(),
            Car(),
            MotorCycle(),
            Car(),
            MotorCycle(),
            Car(),
            MotorCycle(),
            Car()
    ]:
        if lot.enter_parking_lot_queue(v):
            print "entered lot"
        else:
            print "did not enter"
    print lot.get_current_occupancy_details()
            self.vehicles.remove(vehicle)
            print 'The {} has left {}.'.format(vehicle.description, self.name)

        else:
            raise TypeError('Only vehicles are allowed in garages.')

    def __len__(self):
        """
        Python builtin to support len function
        """
        return len(self.vehicles)

    def __iter__(self):
        """
        Python builtin to support iteration
        """
        for v in self.vehicles:
            yield v


##########################################################################
## Execution
##########################################################################

if __name__ == '__main__':
    g = Garage("Al's Garage")
    c = Car('silver', 'Porsche', 'Boxster')
    g.enter(c)
    g.exit(c)