def undoExampleHardest():
    undoController = UndoController()
    clientRepo = Repository()
    carRepo = Repository()
    '''
    Start rental Controller
    '''
    rentRepo = Repository()
    rentController = RentalController(undoController, rentRepo, carRepo,
                                      clientRepo)
    '''
    Start client Controller
    '''
    clientController = ClientController(undoController, rentController,
                                        clientRepo)
    '''
    Start car Controller
    '''
    carController = CarController(undoController, rentController, carRepo)
    '''
    We add 1 client, 1 car and 2 rentals
    '''
    clientSophia = clientController.create(103, "2990511035588", "Sophia")
    carHyundaiTucson = carController.create(201, "CJ 02 TWD", "Hyundai",
                                            "Tucson")
    rentController.createRental(301, clientSophia, carHyundaiTucson,
                                date(2016, 11, 1), date(2016, 11, 30))
    rentController.createRental(302, clientSophia, carHyundaiTucson,
                                date(2016, 12, 1), date(2016, 12, 31))

    printReposWithMessage("We added Sophia, the Hyundai and its 2 rentals",
                          clientRepo, carRepo, rentRepo)

    carController.delete(201)
    printReposWithMessage("Delete the Hyundai (also deletes its rentals)",
                          clientRepo, carRepo, rentRepo)
    '''
    Now undo the performed operations, one by one
    '''
    undoController.undo()
    printReposWithMessage("1 undo, the Hyundai and its rentals are back",
                          clientRepo, carRepo, rentRepo)

    undoController.undo()
    printReposWithMessage("1 undo deletes the second rental", clientRepo,
                          carRepo, rentRepo)

    undoController.undo()
    printReposWithMessage("1 undo deletes the first rental", clientRepo,
                          carRepo, rentRepo)

    undoController.undo()
    printReposWithMessage("1 undo deletes the Hyundai", clientRepo, carRepo,
                          rentRepo)
    '''
    After 5 undos, all repos should be empty, as we did 5 operations in total
    '''
    undoController.undo()
    printReposWithMessage("1 undo deletes Sophia (no more undos)", clientRepo,
                          carRepo, rentRepo)
    '''
    Redos start here
    '''
    undoController.redo()
    printReposWithMessage("1 redo and Sophia is added", clientRepo, carRepo,
                          rentRepo)

    undoController.redo()
    printReposWithMessage("1 redo adds the Hyundai", clientRepo, carRepo,
                          rentRepo)

    undoController.redo()
    printReposWithMessage("1 redo adds the first rental", clientRepo, carRepo,
                          rentRepo)

    undoController.redo()
    printReposWithMessage("1 redo adds the second rental", clientRepo, carRepo,
                          rentRepo)

    undoController.redo()
    printReposWithMessage("1 redo deletes the Hyundai and its rentals (again)",
                          clientRepo, carRepo, rentRepo)
    '''
    Let's do a few undos again...
    '''
    undoController.undo()
    undoController.undo()
    undoController.undo()

    printReposWithMessage("3 undos later, we have Sophia and the Hyundai",
                          clientRepo, carRepo, rentRepo)
    '''
    Now we try something new - let's add another car!
    
    NB!
        A new operation must invalidate the history for redo() operations
    '''
    carController.create(202, "CJ 02 SSE", "Dacia", "Sandero")
    print("\n Do we have a redo? -", undoController.redo(), "\n")
    '''
    Now we should have 2 cars
    '''
    printReposWithMessage("After adding the Dacia, there is no redo ",
                          clientRepo, carRepo, rentRepo)
    '''
    However, undos is still available !
    '''
    undoController.undo()
    printReposWithMessage("1 undo deletes the Dacia", clientRepo, carRepo,
                          rentRepo)

    undoController.undo()
    printReposWithMessage("1 undo deletes the Hyundai", clientRepo, carRepo,
                          rentRepo)
示例#2
0
def undoExample():
    """
    An example for doing multiple undo operations. 
    This is a bit more difficult than in Lab2-4 due to the fact that there are now several controllers, 
    and each of them can perform operations that require undo support.
     
    Follow the code below and figure out how it works!
    """
    
    undoController = UndoController()
    
    '''
    Start client Controller
    '''
    clientRepo = Repository()
    clientValidator = ClientValidator()
    clientController = ClientController(undoController, clientValidator, clientRepo)
    
    '''
    Start car Controller
    '''
    carRepo = Repository()
    carValidator = CarValidator()
    carController = CarController(undoController, carValidator, carRepo)
    
    '''
    Start rental Controller
    '''
    rentRepo = Repository()
    rentValidator = RentalValidator()
    rentController = RentalController(undoController, rentValidator, rentRepo, carRepo, clientRepo)
    
    print("---> Initial state of repositories")
    print(clientRepo)
    print(carRepo)
    print(rentRepo)
    
    '''
    We add a client, a new car as well as a rental
    '''
    clientController.create(103, "1900102035588", "Dale")
    carController.create(201, "CJ 02 ZZZ", "Dacia", "Sandero")
    
    rentStart = datetime.strptime("2015-11-26", "%Y-%m-%d")
    rentEnd = datetime.strptime("2015-11-30", "%Y-%m-%d")
    rentController.createRental(301, clientRepo.find(103), carRepo.find(201), rentStart, rentEnd)
    
    print("---> We added a client, a new car and a rental")
    print(clientRepo)
    print(carRepo)
    print(rentRepo)
    
    '''
    Now undo the performed operations, one by one
    '''
    undoController.undo()
    print("---> After 1 undo")
    print(clientRepo)
    print(carRepo)
    print(rentRepo)
    
    
    undoController.undo()
    print("---> After 2 undos")
    print(clientRepo)
    print(carRepo)
    print(rentRepo)
    
    undoController.undo()
    print("---> After 3 undos")
    print(clientRepo)
    print(carRepo)
    print(rentRepo)
示例#3
0
def undoExample():
    """
    An example for doing multiple undo operations. 
    This is a bit more difficult than in Lab2-4 due to the fact that there are now several controllers, 
    and each of them can perform operations that require undo support.
     
    Follow the code below and figure out how it works!
    """

    undoController = UndoController()
    '''
    Start client Controller
    '''
    clientRepo = Repository()
    clientValidator = ClientValidator()
    clientController = ClientController(undoController, clientValidator,
                                        clientRepo)
    '''
    Start car Controller
    '''
    carRepo = Repository()
    carValidator = CarValidator()
    carController = CarController(undoController, carValidator, carRepo)
    '''
    Start rental Controller
    '''
    rentRepo = Repository()
    rentValidator = RentalValidator()
    rentController = RentalController(undoController, rentValidator, rentRepo,
                                      carRepo, clientRepo)

    print("---> Initial state of repositories")
    print(clientRepo)
    print(carRepo)
    print(rentRepo)
    '''
    We add a client, a new car as well as a rental
    '''
    clientController.create(103, "1900102035588", "Dale")
    carController.create(201, "CJ 02 ZZZ", "Dacia", "Sandero")

    rentStart = datetime.strptime("2015-11-26", "%Y-%m-%d")
    rentEnd = datetime.strptime("2015-11-30", "%Y-%m-%d")
    rentController.createRental(301, clientRepo.find(103), carRepo.find(201),
                                rentStart, rentEnd)

    print("---> We added a client, a new car and a rental")
    print(clientRepo)
    print(carRepo)
    print(rentRepo)
    '''
    Now undo the performed operations, one by one
    '''
    undoController.undo()
    print("---> After 1 undo")
    print(clientRepo)
    print(carRepo)
    print(rentRepo)

    undoController.undo()
    print("---> After 2 undos")
    print(clientRepo)
    print(carRepo)
    print(rentRepo)

    undoController.undo()
    print("---> After 3 undos")
    print(clientRepo)
    print(carRepo)
    print(rentRepo)
示例#4
0
def statisticsExample():
    """
    An example for the creation of statistics.
    Several cars, clients and rentals are created and then a statistics is calculated over them.
    
    Follow the code below and figure out how it works!
    """
    undoController = UndoController()
    
    '''
    Start client Controller
    '''
    clientRepo = Repository()
    clientValidator = ClientValidator()
    clientController = ClientController(undoController, clientValidator, clientRepo)
    
    clientController.create(100, "1820203556699", "Aaron")
    clientController.create(101, "2750102885566", "Bob")
    clientController.create(102, "1820604536579", "Carol")

    # We name the instances so it's easier to create some test values later
    aaron = clientRepo.find(100)
    bob = clientRepo.find(101)
    carol = clientRepo.find(102)

    '''
    Start car Controller
    '''
    carRepo = Repository()
    carValidator = CarValidator()
    carController = CarController(undoController, carValidator, carRepo)

    carController.create(200, "CJ 01 AAA", "Audi", "A3")
    carController.create(201, "CJ 01 BBB", "Audi", "A4")
    carController.create(202, "CJ 01 CCC", "Audi", "A5")
    carController.create(203, "CJ 01 DDD", "Audi", "A6")

    audiA3 = carRepo.find(200)
    audiA4 = carRepo.find(201)
    audiA5 = carRepo.find(202)
    audiA6 = carRepo.find(203)

    '''
    Start rental Controller
    '''
    rentRepo = Repository()
    rentValidator = RentalValidator()
    rentController = RentalController(undoController, rentValidator, rentRepo, carRepo, clientRepo)

    rentController.createRental(300, aaron, audiA3, datetime.strptime("2015-11-20", "%Y-%m-%d"), datetime.strptime("2015-11-22", "%Y-%m-%d"))
    rentController.createRental(301, carol, audiA5, datetime.strptime("2015-11-24", "%Y-%m-%d"), datetime.strptime("2015-11-25", "%Y-%m-%d"))
    rentController.createRental(302, carol, audiA6, datetime.strptime("2015-12-10", "%Y-%m-%d"), datetime.strptime("2015-12-12", "%Y-%m-%d"))
    rentController.createRental(303, aaron, audiA4, datetime.strptime("2015-11-21", "%Y-%m-%d"), datetime.strptime("2015-11-25", "%Y-%m-%d"))
    rentController.createRental(304, aaron, audiA3, datetime.strptime("2015-11-24", "%Y-%m-%d"), datetime.strptime("2015-11-27", "%Y-%m-%d"))
    rentController.createRental(305, bob, audiA5, datetime.strptime("2015-11-26", "%Y-%m-%d"), datetime.strptime("2015-11-27", "%Y-%m-%d"))
    rentController.createRental(306, carol, audiA6, datetime.strptime("2015-12-15", "%Y-%m-%d"), datetime.strptime("2015-12-20", "%Y-%m-%d"))
    rentController.createRental(307, bob, audiA4, datetime.strptime("2015-12-01", "%Y-%m-%d"), datetime.strptime("2015-12-10", "%Y-%m-%d"))
    rentController.createRental(308, carol, audiA4, datetime.strptime("2015-12-11", "%Y-%m-%d"), datetime.strptime("2015-12-15", "%Y-%m-%d"))
    rentController.createRental(309, aaron, audiA5, datetime.strptime("2015-11-28", "%Y-%m-%d"), datetime.strptime("2015-12-02", "%Y-%m-%d"))

    for cr in rentController.mostRentedCars(): 
        print (cr)
示例#5
0
def statisticsExample():
    """
    An example for the creation of statistics.
    Several cars, clients and rentals are created and then a statistics is calculated over them.
    
    Follow the code below and figure out how it works!
    """
    undoController = UndoController()
    '''
    Start client Controller
    '''
    clientRepo = Repository()
    clientValidator = ClientValidator()
    clientController = ClientController(undoController, clientValidator,
                                        clientRepo)

    clientController.create(100, "1820203556699", "Aaron")
    clientController.create(101, "2750102885566", "Bob")
    clientController.create(102, "1820604536579", "Carol")

    # We name the instances so it's easier to create some test values later
    aaron = clientRepo.find(100)
    bob = clientRepo.find(101)
    carol = clientRepo.find(102)
    '''
    Start car Controller
    '''
    carRepo = Repository()
    carValidator = CarValidator()
    carController = CarController(undoController, carValidator, carRepo)

    carController.create(200, "CJ 01 AAA", "Audi", "A3")
    carController.create(201, "CJ 01 BBB", "Audi", "A4")
    carController.create(202, "CJ 01 CCC", "Audi", "A5")
    carController.create(203, "CJ 01 DDD", "Audi", "A6")

    audiA3 = carRepo.find(200)
    audiA4 = carRepo.find(201)
    audiA5 = carRepo.find(202)
    audiA6 = carRepo.find(203)
    '''
    Start rental Controller
    '''
    rentRepo = Repository()
    rentValidator = RentalValidator()
    rentController = RentalController(undoController, rentValidator, rentRepo,
                                      carRepo, clientRepo)

    rentController.createRental(300, aaron, audiA3,
                                datetime.strptime("2015-11-20", "%Y-%m-%d"),
                                datetime.strptime("2015-11-22", "%Y-%m-%d"))
    rentController.createRental(301, carol, audiA5,
                                datetime.strptime("2015-11-24", "%Y-%m-%d"),
                                datetime.strptime("2015-11-25", "%Y-%m-%d"))
    rentController.createRental(302, carol, audiA6,
                                datetime.strptime("2015-12-10", "%Y-%m-%d"),
                                datetime.strptime("2015-12-12", "%Y-%m-%d"))
    rentController.createRental(303, aaron, audiA4,
                                datetime.strptime("2015-11-21", "%Y-%m-%d"),
                                datetime.strptime("2015-11-25", "%Y-%m-%d"))
    rentController.createRental(304, aaron, audiA3,
                                datetime.strptime("2015-11-24", "%Y-%m-%d"),
                                datetime.strptime("2015-11-27", "%Y-%m-%d"))
    rentController.createRental(305, bob, audiA5,
                                datetime.strptime("2015-11-26", "%Y-%m-%d"),
                                datetime.strptime("2015-11-27", "%Y-%m-%d"))
    rentController.createRental(306, carol, audiA6,
                                datetime.strptime("2015-12-15", "%Y-%m-%d"),
                                datetime.strptime("2015-12-20", "%Y-%m-%d"))
    rentController.createRental(307, bob, audiA4,
                                datetime.strptime("2015-12-01", "%Y-%m-%d"),
                                datetime.strptime("2015-12-10", "%Y-%m-%d"))
    rentController.createRental(308, carol, audiA4,
                                datetime.strptime("2015-12-11", "%Y-%m-%d"),
                                datetime.strptime("2015-12-15", "%Y-%m-%d"))
    rentController.createRental(309, aaron, audiA5,
                                datetime.strptime("2015-11-28", "%Y-%m-%d"),
                                datetime.strptime("2015-12-02", "%Y-%m-%d"))

    for cr in rentController.mostRentedCars():
        print(cr)