예제 #1
0
    def test_lift_call_is_valid_and_status_up(self):
        # floor_max = 100, current_floor = 1
        lift = Lift(current_floor=1,floor_max=100)

        # call lift at floor 10
        lift.callAt(10)
        self.assertEqual('UP', lift.getStatus())
예제 #2
0
    def test_lift_call_is_valid_and_status_down(self):
        # floor_max = 100, current_floor = 10
        lift = Lift(current_floor=10,floor_max=100)

        # call lift at floor 1
        lift.callAt(1)
        self.assertEqual('DOWN', lift.getStatus())
예제 #3
0
    def test_lift_call_isnot_valid_and_status_stop(self):
        # floor_max = 100, current_floor = 10
        lift = Lift(current_floor=10,floor_max=100)

        # call lift at floor 101
        lift.callAt(101)

        self.assertEqual('STOP', lift.getStatus())
def test_sample_lift_system():
    liftA = Lift("A", floor=3, requested_floors=[0])
    liftB = Lift("B", floor=2)
    liftC = Lift("C", floor=2, doors_open=True)
    liftD = Lift("D", floor=0, requested_floors=[0])
    lift_system = LiftSystem(floors=[0, 1, 2, 3],
                             lifts=[liftA, liftB, liftC, liftD],
                             calls=[Call(1, Direction.DOWN)])
    verify(print_lifts(lift_system))
예제 #5
0
    def __init__(self, onRobot):
        IO = IOTools(onRobot)
        print('Grabber initialised')
        self.camera = IO.camera.initCamera('pi', 'low')
        self.getInputs = IO.interface_kit.getInputs
        self.getSensors = IO.interface_kit.getSensors
        self.mc = IO.motor_control
        self.mc.stopMotors()
        self.sc = IO.servo_control
        self.sc.engage()
        self.grabber = Grabber(self.mc, self.MOTOR_PORT, self.sc)
        #self.grabber.prepare_grabber()
        self.lift = Lift(onRobot, self.mc)

        self.lift_pos = 0
        self.s = None
예제 #6
0
def reply_photo(update: Update, context: CallbackContext):

    update.message.reply_text("New Lift Created!")

    template_lift = Lift(0, 'https://telegram.org/img/t_logo.png',
                         LiftState.NONE, "S", "O", "None")
    context.user_data[UD.NEW_LIFT] = template_lift

    # NEW
    id = context.bot_data[BD.LAST_ID] + 1
    context.user_data[UD.NEW_LIFT].id = id

    context.user_data[UD.NEW_LIFT].from_user = update.message.from_user.name

    photo = update.message.photo[-1]
    file_id = photo.file_id

    context.user_data[UD.NEW_LIFT].photo = photo

    new_file = context.bot.getFile(file_id)

    file_path = "A:\photos/" + str(id) + ".jpg"
    new_file.download(Path(file_path))

    update.message.reply_text("Which site?")

    context.user_data[UD.NEW_LIFT].site = None
    context.user_data[UD.NEW_LIFT].opening = None
    context.user_data[UD.NEW_LIFT].note = None

    return ConversationState.SITE
예제 #7
0
def test_smart_travel():
    lift = Lift(queues, capacity)
    lift.direction_of_travel = 'up'
    lift.smart_travel()
    assert lift.current_floor == 4

    lift.direction_of_travel = 'down'
    lift.smart_travel()
    assert lift.current_floor == 2
예제 #8
0
    def test_lift_weight_isnot_valid_and_status_stop_and_beep(self):
        # floor_max = 100, current_floor = 1
        lift = Lift(current_floor=1,floor_max=100)
        
        # call lift at floor 1
        lift.callAt(1)

        # select floor = 10,weight = 100
        lift.start(10,weight=1001)

        self.assertEqual('STOP', lift.getStatus())
        self.assertEqual(True, lift.getBeep())
예제 #9
0
    def test_lift_weight_is_valid_and_status_down_and_not_beep(self):
        # floor_max = 100, current_floor = 1
        lift = Lift(current_floor=1,floor_max=100)
        
        # call lift at floor 10
        lift.callAt(10)

        # select floor = 1,weight = 100
        lift.start(1,weight=100)

        self.assertEqual('DOWN', lift.getStatus())
        self.assertEqual(False, lift.getBeep())
예제 #10
0
def test_passengers_pickup_no_queue():
    lift = Lift(queues, 2)
    lift.direction_of_travel = 'down'
    lift.current_floor = 1
    floor_queue = lift.queues[1]
    lift.passengers_pickup()
    assert lift.occupants == []
예제 #11
0
def test_passengers_pickup_going_up():
    lift = Lift(queues, 2)
    lift.current_floor = 2
    lift.passengers_pickup()
    assert lift.number_of_occupants() == 2
    assert lift.occupants == [5,5]
    assert lift.queues == {0:(), 1:(), 2: (5,), 3:(), 4:(3,), 5:(), 6:()}
예제 #12
0
    def test_lift_select_floor_is_valid_and_status_stop(self):
        # floor_max = 100, current_floor = 1
        lift = Lift(current_floor=1,floor_max=100)
        
        # call lift at floor 1
        lift.callAt(1)

        # select floor = 1
        lift.start(1)

        self.assertEqual('STOP', lift.getStatus())
예제 #13
0
def test_passengers_pickup_going_down():
    lift = Lift(queues, 2)
    lift.direction_of_travel = 'down'
    lift.current_floor = 4
    floor_queue = lift.queues[4]
    lift.passengers_pickup()
    assert lift.occupants == [3]
    assert lift.queues == {0:(), 1:(), 2: (5,5,5), 3:(), 4:(), 5:(), 6:()}
예제 #14
0
def parse_fullpower_csv(url, csv_list, start_index, endIdx):
    # column format: (Weight, <empty>, Lift, Kgs, Lbs, <empty>, Name, Date)
    lift_col_index = 2
    weight_col_index = 3
    name_col_index = 6
    date_col_index = 7

    result = []

    weight_class = None
    for i in range(start_index, endIdx):
        row = csv_list[i]
        weight_class_text = str(row[0]).strip()

        # if we have reached the next weight class
        if (weight_class_text):
            match = re.search(r"(\d*\.?\d+)kg", weight_class_text)
            if (match):
                weight_class = match.group(1)
            elif ("SHW" in weight_class_text):
                weight_class = "SHW"
            else:
                raise ValueError(
                    "Weight class not recognized from \"{}\"".format(
                        weight_class_text))

        if (weight_class == None):
            raise ValueError("Weight class could not be determined")
        else:
            name = row[name_col_index]

            # if (string is null) or (string is empty)
            if (name == None) or (not name.strip()):
                # blank line or empty record, skip
                continue

            # Parse the lift
            lift = Lift()
            lift.weight_class = weight_class
            lift.lift_type = row[lift_col_index]
            lift.weight_lifted = row[weight_col_index]
            lift.name = row[name_col_index]
            lift.date = row[date_col_index]
            lift.source = url
            result.append(lift)

    return result
예제 #15
0
def preview_button(update: Update, context: CallbackContext):
    query = update.callback_query

    query.answer()

    new_lift = Lift(id=context.user_data[UD.NEW_LIFT].id,
                    from_user=context.user_data[UD.NEW_LIFT].from_user,
                    photo=context.user_data[UD.NEW_LIFT].photo,
                    state=LiftState.NONE,
                    site=context.user_data[UD.NEW_LIFT].site,
                    opening=context.user_data[UD.NEW_LIFT].opening,
                    note=context.user_data[UD.NEW_LIFT].note)

    if (query.data == BCD.REPLY_SEND_LIFT.name):
        add_lift(new_lift)

        context.bot_data[BD.LIFT_LIST].append(new_lift)

        keyboard = [[
            InlineKeyboardButton("Follow " + u'\U0001F91D',
                                 callback_data=BCD.FOLLOW_SITE_YES.name)
        ]]
        reply_markup = InlineKeyboardMarkup(keyboard)

        context.bot.send_photo(-1001123729341,
                               context.user_data[UD.NEW_LIFT].photo,
                               combine(context),
                               reply_markup=reply_markup)

        context.bot_data[BD.LIFT_LIST].append(new_lift)

        context.user_data[UD.NEW_LIFT].clear()

        query.edit_message_text(text="Send to group " + u'\U0001F91D')

    elif (query.data == BCD.REPLY_CANCEL_LIFT.name):
        context.user_data[UD.NEW_LIFT].clear()

        query.edit_message_text(text="Canceled")

    return ConversationHandler.END
예제 #16
0
 def GetNewEntity(self, entitytype, entitySubtype=""):
     entity = None
     if (entitytype == "Wall"):
         entity = Wall()
     elif (entitytype == "Door"):
         entity = Door()
     elif (entitytype == "Lift"):
         entity = Lift()
     elif (entitytype == "Generator"):
         entity = Generator()
     elif (entitytype == "Slab"):
         if (entitySubtype == "MapSlab"):
             entity = MapSlab()
         elif (entitySubtype == "SaveSlab"):
             entity = SaveSlab()
         elif (entitySubtype == "PentagramSlab"):
             entity = PentagramSlab()
         elif (entitySubtype == "BombSlab"):
             entity = BombSlab()
     elif (entitytype == "Table"):
         entity = Obstacle(obstacleType="Table", width=2, length=1)
     elif (entitytype == "Computer"):
         entity = Obstacle(obstacleType="Computer", width=3, length=1)
     elif (entitytype == "Container"):
         entity = Obstacle(obstacleType="Container", width=1, length=1)
     elif (entitytype == "Start"):
         entity = StartPosition()
     elif (entitytype == "Barrel"):
         entity = Obstacle(obstacleType="Barrel", width=1, length=1)
     elif (entitytype == "Box"):
         entity = Obstacle(obstacleType="Box", width=1, length=1)
     elif (entitytype == "Closet"):
         entity = Obstacle(obstacleType="Closet", width=1, length=1)
     else:
         raise Exception("Invalid type: " + entitytype)
     return entity
예제 #17
0
from lift import Lift
from quick_sort import Quicksort
from selection_sort import selection_sort

if __name__ == "__main__":
    lifts_list = []

    lift1 = Lift(234, 124)
    lift2 = Lift(124, 4224)
    lift3 = Lift(7654, 14224)
    lift4 = Lift(544, 3224)
    lift5 = Lift(5434, 2324)

    lifts_list.append(lift1)
    lifts_list.append(lift2)
    lifts_list.append(lift3)
    lifts_list.append(lift4)
    lifts_list.append(lift5)

    for lift in lifts_list:
        print(lift.power)
    print "------------------------------------------------------------------------------------------------"

    selection_sort(lifts_list)

    for lift in lifts_list:
        print(lift.power)
    print "------------------------------------------------------------------------------------------------"

    for lift in lifts_list:
        print(lift.capacity)
예제 #18
0
def test_illegal_states():
    liftA = Lift("A", floor=0, requested_floors=[0], doors_open=True)
    lifts = LiftSystem(floors=[0, 1], lifts=[liftA])
    verify(print_lifts(lifts))
예제 #19
0
def test_large_lift_system():
    liftA = Lift("A", floor=0, requested_floors=[3, 5, 7])
    liftB = Lift("B", floor=2, doors_open=True)
    liftC = Lift("C", floor=-2)
    liftC.requested_floors = [-2, 0]
    liftD = Lift("D", floor=8, doors_open=True)
    liftD.requested_floors = [0, -1, -2]
    liftSVC = Lift("SVC", floor=10)
    liftSVC.requested_floors = [0, -1]
    liftF = Lift("F", floor=8)
    lift_system = LiftSystem(
        floors=[-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
        lifts=[liftA, liftB, liftC, liftD, liftSVC, liftF],
        calls=[
            Call(1, Direction.DOWN),
            Call(6, Direction.DOWN),
            Call(5, Direction.UP),
            Call(5, Direction.DOWN),
            Call(-1, Direction.UP)
        ])
    verify(print_lifts(lift_system))
예제 #20
0
def test_no_doors():
    liftA = Lift("A", floor=3, requested_floors=[0])
    lift_system = LiftSystem(floors=[0, 1, 2, 3],
                             lifts=[liftA],
                             calls=[Call(1, Direction.DOWN)])
    verify(print_lifts(lift_system, lift_printer=SimpleLiftPrinter()))
예제 #21
0
 def create_lift(self):
     self.lift = Lift(-c.lift_width, 0)
     self.entities.add(self.lift)
예제 #22
0
class Toddler:
    MOTOR_PORT = 1
    BUMP_SENSOR_SHELF_1 = 0
    BUMP_SENSOR_SHELF_2 = 1
    BUMP_SENSOR_GRABBER_FRONT = 2
    BUMP_SENSOR_GRABBER_BACK = 3

    def __init__(self, onRobot):
        IO = IOTools(onRobot)
        print('Grabber initialised')
        self.camera = IO.camera.initCamera('pi', 'low')
        self.getInputs = IO.interface_kit.getInputs
        self.getSensors = IO.interface_kit.getSensors
        self.mc = IO.motor_control
        self.mc.stopMotors()
        self.sc = IO.servo_control
        self.sc.engage()
        self.grabber = Grabber(self.mc, self.MOTOR_PORT, self.sc)
        #self.grabber.prepare_grabber()
        self.lift = Lift(onRobot, self.mc)

        self.lift_pos = 0
        self.s = None
        # self.mc.setMotor(self.MOTOR_PORT, 100)
        # time.sleep(3)
        # self.mc.stopMotors()

    def kill_socket(self):
        s.close()

    def listen(self):
        global halt
        try:
            PORT = 65432  # Port to listen on (non-privileged ports are > 1023)
            self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            # HOST = socket.gethostbyname(socket.gethostname())
            HOST = '192.168.105.139'
            self.s.bind(('192.168.105.139', PORT))
            print("Listening on {}:{}".format(HOST, PORT))

            self.s.listen(1)
            conn, addr = self.s.accept()
            while not (halt['stop']):

                data = conn.recv(1024)
                data = data.decode('utf-8')
                data = data.split(' ')
                print("Listen: " + data[0])
                if data[0] == 'grab':
                    self.grabber.grab(self)
                elif data[0] == 'upper_grab':
                    self.grabber.upper_grab(self)
                elif data[0] == 'prepare':
                    self.grabber.prepare_grabber()
                elif data[0] == 'retract':
                    self.grabber.retract_grabber()
                elif data[0] == 'wait_for_bump':
                    inp = self.getInputs()
                    while inp[self.BUMP_SENSOR_SHELF_1] == 0 or inp[
                            self.BUMP_SENSOR_SHELF_2] == 0:
                        print(inp)
                    print("bump")
                elif data[0] == 'lift':
                    if int(data[1]) < self.lift_pos:
                        print('down')
                        self.lift.lift('down')
                    elif int(data[1]) > self.lift_pos:
                        print('up')
                        self.lift.lift('up')
                    self.lift_pos = int(data[1])
                    time.sleep(0.5)
                elif data[0] == 'drop':
                    self.grabber.prepare_grabber()
                    while inp[self.BUMP_SENSOR_GRABBER_BACK] == 0:
                        print('Waiting for collection')
                    self.grabber.retract_grabber()
                print("Listen done")
                conn.sendall(b'done')
            conn.close()
        except KeyboardInterrupt:
            conn.close()
            return

    def control(self):
        global halt

        try:
            thread = Thread(target=self.listen)
            thread.daemon = True
            thread.start()
            print("here")
            rjr = RobotJobListener(('192.168.105.38', 9000),
                                   ('192.168.105.139', 65432),
                                   ('192.168.105.94', 65433))
            rjr.start_reliable_listener('robot')
            # start pinging the server
            # server, rasppi, ev3
        except KeyboardInterrupt:
            halt['stop'] = True
            self.sc.disengage()
            return

    def vision(self):
        # image = self.camera.getFrame()
        # self.camera.imshow('Camera', image)
        time.sleep(0.05)
        return
예제 #23
0
def todo_test_something():
    liftA = Lift("A", 0)
    lifts = LiftSystem(floors=[0, 1], lifts=[liftA])
    lifts.tick()
    verify(print_lifts(lifts))
예제 #24
0
def test_run():
    lift = Lift(queues, capacity)
    lift_controller = LiftController(lift)
    lift_controller.run(lift)
    assert lift.journey_history == [0, 4, 3, 2, 5, 0]
예제 #25
0
def todo_test_something():
    liftA = Lift("A", 0)
    lifts = LiftSystem(floors=[0, 1], lifts=[liftA])
    lifts.tick()
예제 #26
0
import py, pytest
import sys, os
myPath = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, myPath + '/../src')

from lift_controller import LiftController
from lift import Lift

queues = ((), (), (5, 5, 5), (), (3, ), (), ())
capacity = 5
lift = Lift(queues, capacity)
lift_controller = LiftController(lift)


def test_empty_travel():
    lift_controller.empty_travel(lift)
    assert lift.journey_history == [4]
    assert lift.occupants == [3]
    assert lift.direction_of_travel == 'down'
    assert lift.destination_floor == 3


def test_run():
    lift = Lift(queues, capacity)
    lift_controller = LiftController(lift)
    lift_controller.run(lift)
    assert lift.journey_history == [0, 4, 3, 2, 5, 0]


queues2 = ((), (0, ), (), (), (2, ), (3, ), ())
lift2 = Lift(queues2, capacity)
예제 #27
0
 def getLiftManager(liftsCount=StaticValues.lifts):
     return LiftManager([Lift(i) for i in range(liftsCount)])
예제 #28
0
                                             lunchOtherFloorSelector)
    eveningOtherFloorSelector = BetaFloorSelector(0, 0)
    eveningOtherFloorGenerator = BetaGenerator(HG, 16.5 * 3600, 18 * 3600,
                                               eveningOtherFloorSelector)

    #f=Floor(i,[dayOtherFloorGenerator,lunchOtherFloorGenerator,eveningOtherFloorGenerator],[vanisher])
    #Test floor
    testSelector = BetaFloorSelector(0, 10)
    testGenerator = BetaGenerator(HG, 0, 3000, testSelector, 2, 2)

    f = Floor(i, [testGenerator], [vanisher])
    floors.append(f)

########## END FLOOR DEFINITIONS ####################
########## START LIFT DEFINITIONS ####################
l1 = Lift(0, 10, 0, 10, False, None)  #this lift goes across all floors
l2 = Lift(0, 10, 0, 10, False, None)  #this lift goes across all floors
l3 = Lift(0, 10, 0, 10, False, None)  #this lift goes across all floors
#l2=Lift(0,20,0,5,False,None)  #services the first 6 floors, more capacity
#l3=Lift(0,5,3,10,False,None)  #services floor 4 - 10, less capacity
########## END LIFT DEFINITIONS ####################

########## REPLACE WITH OWN CONTROLLER####################
#controller=MyController()
controller = Controller()
########## BUILDING DEFINITION ####################
startTime = 0  #int(7.5*3600)
#building=Building(floors,[l1,l2,l3],controller,startTime)
building = Building(floors, [l1], controller, startTime)

########## RUN OVER A SINGLE 24 HOUR PERIOD####################
예제 #29
0
파일: main.py 프로젝트: tomviner/lift-sim
import sys

from display import Display
from lift import Lift

display = Display(int(sys.argv[1]), 0)

lift = Lift(display)

lift.start()
예제 #30
0
 def test_lift_current_floor(self):
     # floor_max = 100, current_floor = 1
     lift = Lift(current_floor=10,floor_max=100)
     self.assertEqual(10, lift.getCurrentFloor())