コード例 #1
0
def visualization_test_main():
    elevators = [Elevator(1), Elevator(2), Elevator(3), Elevator(4)]
    building = Building(name=1, elevators=elevators, n_floors=10)
    vis = Visualization(building)

    # Option 1: pyglet.app.run()
    # Option 2: event_loop = pyglet.app.EventLoop()
    # event_loop.run()
    # Option 3: custom event loop which dispatches an on_draw event, which updates the screen to the current state
    vis.pyglet_window.dispatch_event("on_draw")
    while vis.alive == 1:
        print("Running loop")
        time.sleep(7)

        # These three lines are needed
        pyglet.clock.tick()
        vis.pyglet_window.dispatch_events()
        vis.pyglet_window.dispatch_event("on_draw")

        building.elevators[0].position += 3
        building.elevators[2].position += 2
        building.elevators[0].state = ElevatorState.LOADING_UNLOADING
        building.elevators[1].state = ElevatorState.UP
        building.elevators[2].state = ElevatorState.DOWN
        building.elevators[3].state = ElevatorState.NO_ACTION
コード例 #2
0
 def setUp(self):
     self.height = 3
     self.floors = 15
     self.wait_time = 120.0
     self.speed = 1.5
     self.elevator = Elevator(self.floors, self.height, self.speed,
                              self.wait_time)
コード例 #3
0
class RadiationContainmentSimulator:
  def __init__(self, initial_state:SimulatorState):
    self.floors = Floors(initial_state.floors)
    self.elevator = Elevator(initial_state.get_elevator_floor())

  def get_simulator_state(self) -> SimulatorState:
    state = SimulatorState(self.elevator.get_floor())
    state.set_floors(self.floors)
    return state

  def current_floor_items(self) -> list[str]:
    elevator_floor = self.elevator.get_floor()
    return self.floors.get_floors()[elevator_floor]

  def elevator_up(self, cargo:list[str]):
    one_floor_up = self.elevator.get_floor() + 1
    if one_floor_up > 3:
      raise ElevatorMoveError('Cannot go above fourth floor')
    self.elevator.elevator_move(cargo, one_floor_up, self.floors)

  def elevator_down(self, cargo:list[str]):
    one_floor_down = self.elevator.get_floor() - 1
    if one_floor_down < 0:
      raise ElevatorMoveError('Cannot go below zeroth floor')
    self.elevator.elevator_move(cargo, one_floor_down, self.floors)
コード例 #4
0
class ElevatorTestCase(unittest.TestCase):
    def setUp(self):
        self.height = 3
        self.floors = 15
        self.wait_time = 120.0
        self.speed = 1.5
        self.elevator = Elevator(self.floors, self.height, self.speed,
                                 self.wait_time)

    def test_initial_state(self):
        e = self.elevator
        self.assertEqual(e.height, self.height)
        self.assertEqual(e.floors, self.floors)
        self.assertEqual(e.wait_time, self.wait_time)
        self.assertEqual(e.speed, self.speed)
        self.assertEqual(e.state, States.closed)
        self.assertEqual(e._floor, 0)

    def test_possible_floors(self):
        self.assertEqual((0, self.floors), self.elevator.possible_floors())

    def test_change_state_to_incorrect(self):
        e = self.elevator
        self.assertEqual(e.state, States.closed)

        e.state = 'Incorrect state type or value'
        self.assertEqual(e.state, States.closed)

        e.state = 2
        self.assertEqual(e.state, States.closed)
        e.state = 3
        self.assertEqual(e.state, States.closed)

        e.state = str()
        self.assertEqual(e.state, States.closed)

    def test_change_state_to_correct(self):
        e = self.elevator

        e.state = States.closed
        self.assertEqual(e.state, States.closed)

        e.state = States.opened
        self.assertEqual(e.state, States.opened)

        e.state = States.passing
        self.assertEqual(e.state, States.passing)

        e.state = States.closed
        self.assertEqual(e.state, States.closed)

    def test_properties_change(self):
        e = self.elevator

        with self.assertRaises(AttributeError):
            e.floors = []
コード例 #5
0
def process(command: Command, elevator: Elevator):
    if command.action == 'moveToFloor':
        try:
            floor = int(command.value)
        except ValueError:
            print('Sorry, bad value. Integer is required')
            return
        print(f'Moving to floor {floor}')
        elevator.current_floor = floor
    else:
        print('Sorry, not implemented at the moment')
コード例 #6
0
def test_simple():
    elevator = Elevator(tonnage=1000,
                        floors_count=25,
                        current_direction=0,
                        current_weight=0,
                        current_floor=17,
                        is_light_on=True,
                        is_smoked=True,
                        requests=[],
                        is_communication_on=False,
                        is_doors_open=False,
                        is_empty=True)
    operator = Operator([elevator])
    operator.open_doors(0)
    assert elevator.is_doors_open == True

    operator.close_doors(0)
    assert elevator.is_doors_open == False

    assert operator.open_doors(1) == 'Wrong elevator number'
コード例 #7
0
ファイル: app.py プロジェクト: ivanbukhtiyarov/elevators
def initialize_elevator() -> Elevator:
    print('First of all, we need to define some basic elevator parameters')
    tonnage = int(
        input('Please, define tonnage of the elevator in kilograms\n'))
    floors_count = int(
        input('Please, define amount of floors in the building\n'))
    print('Setting up the elevator...')
    elevator = Elevator(tonnage=tonnage,
                        floors_count=floors_count,
                        current_direction=0,
                        current_weight=0,
                        is_light_on=False,
                        is_smoked=False,
                        requests=[],
                        is_communication_on=False,
                        is_doors_open=False,
                        is_empty=True,
                        current_floor=1)
    print('The elevator is set up and ready to go. Have fun!')
    return elevator
コード例 #8
0
 def __init__(self, initial_state:SimulatorState):
   self.floors = Floors(initial_state.floors)
   self.elevator = Elevator(initial_state.get_elevator_floor())