Esempio n. 1
0
def install():
    version = get_config_value(lvl, 'java')

    ans = ''
    if silent_mode == 'silent':
        ans = 'y'
    else:
        ans = get_input('Do you want to install/update ' + version +
                        ' ? [y/n] ')

    while ans != 'y' and ans != 'n':
        ans = get_input('Do you want to install/update ' + version +
                        ' ? [y/n] ')
    if (ans == 'n'):
        print('Skipping Java installation.')
        print('Exiting...')
        exit()
    check_java = 'rpm -q java-1.8.0-openjdk-devel.x86_64 > /dev/null'
    result = subprocess.call(check_java, shell='True')
    if result != 0:
        print('Attempting ' + version + ' installation...')
        sleep(2)
        result = subprocess.call('sudo yum -y install ' + version,
                                 shell='True')
        if result == 0:
            print('Installation successful!')
    else:
        print('The required version of java is already installed.')
        print('Exiting...')
Esempio n. 2
0
def main():
    captcha = get_input('../input/day1.in')[0]
    dups = find_dups(captcha)
    print "part 1 total: " + str(sum(dups))

    captcha = get_input('../input/day1-part2.in')[0]
    dups = find_half_dups(captcha)
    print "part 2 total: " + str(sum(dups))
Esempio n. 3
0
 def test_large_motor(self):
     get_input("Attach a LargeMotor then continue")
     d = LargeMotor()
     print(d.driver_name)
     d.run_forever(100, speed_regulation=False)
     print(d.state)
     time.sleep(5)
     d.stop()
 def test_medium_motor(self):
     get_input('Attach a MediumMotor then continue')
     d = MediumMotor()
     print(d.type)
     d.run_forever(100, regulation_mode=False)
     print(d.run)
     time.sleep(5)
     d.stop()
Esempio n. 5
0
 def test_medium_motor(self):
     get_input('Attach a MediumMotor then continue')
     d = MediumMotor()
     print(d.driver_name)
     d.run_forever(100, speed_regulation=False)
     print(d.state)
     time.sleep(5)
     d.stop()
Esempio n. 6
0
 def test_PSPNxV4(self):
     get_input('Attach a PSPNxV4 at port 3 then continue')    	
     d = PSPNxV4(3)
     print(d.version)
     print(d.vendor_id)
     print(d.device_id)
     get_input('test button_set_1')
     print(d.button_set_1)
Esempio n. 7
0
 def test_tone(self):
     get_input('Test beep')
     d= Tone()
     d.play(1000, 3000)
     time.sleep(3)
     d.play(1000)
     time.sleep(3)
     d.stop()
 def test_medium_motor(self):
     get_input('Attach a MediumMotor then continue')
     d = MediumMotor()
     print(d.driver_name)
     d.run_forever(100, speed_regulation=False)
     print(d.state)
     time.sleep(5)
     d.stop()
Esempio n. 9
0
 def test_medium_motor(self):
     get_input('Attach a MediumMotor then continue')
     d = MediumMotor()
     print(d.type)
     d.run_forever(100, regulation_mode=False)
     print(d.run)
     time.sleep(5)
     d.stop()
Esempio n. 10
0
 def test_tone(self):
     get_input('Test beep')
     d = Tone()
     d.play(1000, 3000)
     time.sleep(3)
     d.play(1000)
     time.sleep(3)
     d.stop()
    def test_medium_motor(self):
        get_input('Attach a MediumMotor then continue')
        d = MediumMotor()
        print(d.type)
        #d.run_forever(25, regulation_mode=False)
	d.run_time_limited(time_sp=5000, speed_sp=25, regulation_mode=False,
                           stop_mode=Motor.STOP_MODE.COAST, ramp_up_sp=100, ramp_down_sp=100)
        print(d.run)
        time.sleep(5)
        d.stop()
Esempio n. 12
0
 def test_msensor(self):
     get_input('Attach a Msensor on port 1 then continue')
     d = Msensor(port=1)
     print(d.mode)
     type_id = d.type_id
     print(type_id)
     print(d.port)
     d = Msensor(type_id=type_id)
     print(d.mode)
     print(d.type_id)
     print(d.port)
Esempio n. 13
0
 def test_LegoSensor(self):
     get_input('Attach a Msensor on port 1 then continue')
     d = LegoSensor(port=1)
     print(d.mode)
     print(d.port)
     if (len(glob.glob('/sys/class/lego-sensor/sensor*/name')) >0):
         name = d.name
         print(name)
         d = LegoSensor(name=name)
     print(d.mode)
     print(d.port)
Esempio n. 14
0
 def test_LegoSensor(self):
     get_input('Attach a Msensor on port 1 then continue')
     d = LegoSensor(port=1)
     print(d.mode)
     print(d.port)
     if (len(glob.glob('/sys/class/lego-sensor/sensor*/name')) > 0):
         name = d.name
         print(name)
         d = LegoSensor(name=name)
     print(d.mode)
     print(d.port)
Esempio n. 15
0
 def test_lcd(self):
     get_input('Test lcd')
     d= Lcd()        
     d.draw.ellipse((20, 20, 60, 60))
     d.update()
     time.sleep(2)
     d.reset()
     font = ImageFont.load_default() 
     d.draw.text((10, 10), "hello", font=font)
     d.update()
     time.sleep(2)
     d.reset()
     font = ImageFont.truetype('/usr/share/fonts/truetype/arphic/uming.ttc',15)
     d.draw.text((20, 20), u'你好,世界', font=font)
     d.update()
Esempio n. 16
0
 def test_color_sensor(self):
     get_input('Attach a ColorSensor then continue')
     d = ColorSensor()
     get_input('test rgb')
     print(d.rgb)
     print(d.mode)
     get_input('test color')
     print(d.color)
     print(d.mode)
     get_input('test reflect')
     print(d.reflect)
     print(d.mode)
     get_input('test ambient')
     print(d.ambient)
     print(d.mode)
Esempio n. 17
0
def main():
    spreadsheet = get_input('../input/day2.in')

    differences = []
    for row in spreadsheet:
        differences.append(find_difference(row))

    print "checksum: " + str(sum(differences))

    spreadsheet = get_input('../input/day2-part2.in')
    divisions = []
    for row in spreadsheet:
        divisions.append(find_divisible_difference(row))

    print "divisions sum: " + str(sum(divisions))
Esempio n. 18
0
 def test_msensor(self):
     get_input('Attach a Msensor on port 1 then continue')
     d = Msensor(port=1)
     print(d.mode)
     print(d.port)
     if (len(glob.glob('/sys/class/msensor/sensor*/type_id')) > 0):
         type_id = d.type_id
         print(type_id)
         d = Msensor(type_id=type_id)
     if (len(glob.glob('/sys/class/msensor/sensor*/name')) > 0):
         name = d.name
         print(name)
         d = Msensor(name=name)
     print(d.mode)
     print(d.port)
Esempio n. 19
0
 def test_lcd(self):
     get_input("Test lcd")
     d = Lcd()
     d.draw.ellipse((20, 20, 60, 60))
     d.update()
     time.sleep(2)
     d.reset()
     font = ImageFont.load_default()
     d.draw.text((10, 10), "hello", font=font)
     try:
         font = ImageFont.truetype("/usr/share/fonts/truetype/arphic/uming.ttc", 15)
         d.draw.text((20, 20), u"你好,世界", font=font)
     except IOError:
         print("No uming.ttc found. Skip the CJK test")
     d.update()
Esempio n. 20
0
 def test_msensor(self):
     get_input('Attach a Msensor on port 1 then continue')
     d = Msensor(port=1)
     print(d.mode)
     print(d.port)
     if (len(glob.glob('/sys/class/msensor/sensor*/type_id')) >0):
         type_id = d.type_id
         print(type_id)
         d = Msensor(type_id=type_id)
     if (len(glob.glob('/sys/class/msensor/sensor*/name')) >0):
         name = d.name
         print(name)
         d = Msensor(name=name)
     print(d.mode)
     print(d.port)
 def test_color_sensor(self):
     get_input('Attach a ColorSensor then continue')
     d = ColorSensor()
     get_input('test rgb')
     print(d.rgb)
     print(d.mode)
     get_input('test color')
     print(d.colors[d.color])
     print(d.mode)
     get_input('test reflect')
     print(d.reflect)
     print(d.mode)
     get_input('test ambient')
     print(d.ambient)
     print(d.mode)
Esempio n. 22
0
    def modify(self, modstring):
        # If no modstring was passed as argument, ask the user interactively
        if not modstring:
            with util.current_line_highlighted():
                modstring = util.get_input("Enter modifications: ")

        # We might have two same tasks in the range, make sure we do not pass the
        # same uuid twice
        unique_tasks = set(vimwikitask.task['uuid'] for vimwikitask in self.tasks)
        uuids = list(unique_tasks)

        # Generate the arguments from the modstring
        args = util.tw_modstring_to_args(modstring)

        # Modify all tasks at once
        output = util.tw_execute_safely(self.tw, uuids + ['mod'] + args)

        # Update the touched tasks in buffer, if needed
        cache.load_tasks()
        cache.update_vwtasks_from_tasks()
        cache.update_vwtasks_in_buffer()

        # Output the feedback from TW
        if output:
            print(output[-1])

        cache.buffer.push()
    def initialize(self):
        version = util.get_input('Enter Zoom version [2/3]: ')
        util.Msg('Changing admin password to \'d3fault\'...')

        url_25 = 'http://%s/hag/emweb/PopOutUserModify.htm/FormOne&user=admin&'\
                 'ex_param1=admin&new_pass1=d3fault&new_pass2=d3fault&id=3&'\
                 'cmdSubmit=Save+Changes' % self.config['target'].value
        url_30 = 'http://%s/hag/emweb/PopOutUserModify.htm?id=40&user=admin&'\
                 'Zadv=1&ex_param1=admin&new_pass1=d3fault&new_pass2=d3fault&'\
                 'id=3&cmdSubmit=Save+Changes' % self.config['target'].value
        url_logs = 'http://%s/Action?id=76&cmdClear+Log=Clear+Log' % self.config[
            'target'].value

        try:
            if version == '2':
                urllib.urlopen(url_25).read()
            else:
                urllib.urlopen(url_30).read()

            util.Msg("Password reset, clearing logs...")
            urllib.urlopen(url_logs).read()
            util.Msg('Done.  Connect to %s with admin:d3fault' %
                     self.config['target'].value)
        except Exception, e:
            util.Error('Unable to connect: %s' % e)
Esempio n. 24
0
def main():
    with open(get_input(__file__)) as file:
        orbits = read_input(file)

    print(part1(orbits))
    Node.nodes = {}
    print(part2(orbits))
Esempio n. 25
0
 def test_lcd(self):
     get_input('Test lcd')
     d = Lcd()
     d.draw.ellipse((20, 20, 60, 60))
     d.update()
     time.sleep(2)
     d.reset()
     font = ImageFont.load_default()
     d.draw.text((10, 10), "hello", font=font)
     try:
         font = ImageFont.truetype(
             '/usr/share/fonts/truetype/arphic/uming.ttc', 15)
         d.draw.text((20, 20), u'你好,世界', font=font)
     except IOError:
         print('No uming.ttc found. Skip the CJK test')
     d.update()
Esempio n. 26
0
    def run(self):
        version = util.get_input("Enter Zoom version [2/3]: ")
        util.Msg("Changing admin password to 'd3fault'...")

        url_25 = (
            "http://%s/hag/emweb/PopOutUserModify.htm/FormOne&user=admin&"
            "ex_param1=admin&new_pass1=d3fault&new_pass2=d3fault&id=3&"
            "cmdSubmit=Save+Changes" % self.ip
        )
        url_30 = (
            "http://%s/hag/emweb/PopOutUserModify.htm?id=40&user=admin&"
            "Zadv=1&ex_param1=admin&new_pass1=d3fault&new_pass2=d3fault&"
            "id=3&cmdSubmit=Save+Changes" % self.ip
        )
        url_logs = "http://%s/Action?id=76&cmdClear+Log=Clear+Log" % self.ip

        try:
            if version == "2":
                urllib.urlopen(url_25).read()
            else:
                urllib.urlopen(url_30).read()

            util.Msg("Password reset, clearing logs...")
            urllib.urlopen(url_logs).read()
            util.Msg("Done.  Connect to %s with admin:d3fault" % self.ip)
        except Exception, e:
            util.Error("Unable to connect: %s" % e)
 def test_infrared_sensor(self):
     get_input('Attach a InfraredSensor then continue')
     d= InfraredSensor()
     print(d.mode)
     get_input('test proxy')
     print(d.prox)
     print(d.mode)
     get_input('test remote')
     print(d.remote)
     print(d.mode)
     get_input('test remote_bin')
     print(d.remote_bin)
     print(d.mode)
     get_input('test seek')
     print(d.seek)
     print(d.mode)
 def test_infrared_sensor(self):
     get_input('Attach a InfraredSensor then continue')
     d = InfraredSensor()
     print(d.mode)
     get_input('test proximity')
     print(d.prox)
     print(d.mode)
     get_input('test remote')
     print(d.remote)
     print(d.mode)
     get_input('test remote_bin')
     print(d.remote_bin)
     print(d.mode)
     get_input('test seek')
     print(d.seek)
     print(d.mode)
Esempio n. 29
0
    def modify(self, modstring):
        # If no modstring was passed as argument, ask the user interactively
        if not modstring:
            with util.current_line_highlighted():
                modstring = util.get_input("Enter modifications: ")

        # We might have two same tasks in the range, make sure we do not pass the
        # same uuid twice
        unique_tasks = set(vimwikitask.task['uuid'] for vimwikitask in self.tasks)
        uuids = list(unique_tasks)

        # Generate the arguments from the modstring
        args = util.tw_modstring_to_args(modstring)

        # Modify all tasks at once
        output = util.tw_execute_safely(self.tw, uuids + ['mod'] + args)

        # Update the touched tasks in buffer, if needed
        cache.load_tasks()
        cache.update_vwtasks_from_tasks()
        cache.update_vwtasks_in_buffer()

        # Output the feedback from TW
        if output:
            print(output[-1])
Esempio n. 30
0
    def annotate(self, annotation):
        if not annotation:
            with util.current_line_highlighted():
                annotation = util.get_input("Enter annotation: ")

        for vimwikitask in self.tasks:
            vimwikitask.task.add_annotation(annotation)
            print("Task \"{0}\" annotated.".format(vimwikitask['description']))
Esempio n. 31
0
def main():
    input_data = get_input('../input/day6.in')
    parsed_data = map(int, parse_row(input_data[0]))
    count, dup = infinite_loop(parsed_data)
    print "part1 count: " + str(count)

    refind_count = find_again(dup[:], dup)
    print "refind_count: " + str(refind_count)
Esempio n. 32
0
 def __init__(self, day):
     self.day = day
     self.program_initial = make_program(get_input(day, split=True))
     self.program = self.program_initial.copy()
     self.ip = 0
     self.rb = 0
     self.output_buffer = []
     self.finished = False
Esempio n. 33
0
    def annotate(self, annotation):
        if not annotation:
            with util.current_line_highlighted():
                annotation = util.get_input("Enter annotation: ")

        for vimwikitask in self.tasks:
            vimwikitask.task.add_annotation(annotation)
            print("Task \"{0}\" annotated.".format(vimwikitask['description']))
Esempio n. 34
0
def product_of_sum():
    expense_reports = get_input('./input')
    for i, val_1 in enumerate(expense_reports):
        for j, val_2 in enumerate(expense_reports[i + 1:]):
            for val_3 in expense_reports[j + i + 2:]:
                if val_1 + val_2 + val_3 == 2020:
                    print(val_1, val_2, val_3, val_1 * val_2 * val_3)
                    return
Esempio n. 35
0
 def test_groups_as_lists(self):
     test_input = get_input('test_input.txt')
     retrieved_groups = list(groups_as_lists(test_input))
     self.assertTrue(len(retrieved_groups), 5)
     self.assertEqual(retrieved_groups[0], ['abc'])
     self.assertEqual(retrieved_groups[1], ['a', 'b', 'c'])
     self.assertEqual(retrieved_groups[2], ['ab', 'ac'])
     self.assertEqual(retrieved_groups[3], ['a', 'a', 'a', 'a'])
     self.assertEqual(retrieved_groups[4], ['b'])
Esempio n. 36
0
def checksum():
	content = get_input('day02.txt')
	two = 0
	three = 0
	for line in content:
		counts = [line.count(l) for l in set(line.strip())]
		two += 1 if 2 in counts else 0
		three += 1 if 3 in counts else 0
	return two * three
Esempio n. 37
0
def main():
    all_input = get_input('../input/day7.in')
    all_programs = parse_input(all_input)
    top_parent = find_top_parent(all_programs)
    print "part1 top parent: " + str(top_parent)

    tree = build_tree(all_programs)
    top_program = find_program(tree, top_parent)
    print_holding_weights(top_program)
Esempio n. 38
0
def part_1():
    test_1_1 = IntCode([1002, 4, 3, 4, 33], [1]).run()
    print(f"{test_1_1=}")
    test_1_2 = IntCode([3, 0, 4, 0, 99], [1]).run()
    print(f"{test_1_2=}")

    data = list(map(int, get_input("data/day5")[0].split(',')))
    res_1 = IntCode(data, [1]).run()
    print(f"{res_1=}")
Esempio n. 39
0
def main():
    with open(get_input(__file__)) as file:
        pw_range = list(map(int, file.read().strip().split("-")))

    candidates_part1 = [password for password in range(pw_range[0], pw_range[1]) if part1(str(password))]
    print(len(candidates_part1))

    candidates_part2 = [password for password in range(pw_range[0], pw_range[1]) if part2(str(password))]
    print(len(candidates_part2))
Esempio n. 40
0
    def test_groups(self):
        test_input = get_input('test_input.txt')
        retrieved_groups = list(groups(test_input))

        self.assertTrue(len(retrieved_groups), 5)
        self.assertEqual(retrieved_groups[0], list('abc'))
        self.assertEqual(retrieved_groups[1], list('abc'))
        self.assertEqual(retrieved_groups[2], list('abc'))
        self.assertEqual(retrieved_groups[3], list('a'))
        self.assertEqual(retrieved_groups[4], list('b'))
Esempio n. 41
0
 def test_walkable(self):
     maze = get_input(20, test=1, strip=False)
     expected_walkable = {(9, 2), (9, 3), (9, 4), (9, 5), (9, 6), (10, 3), (11, 3), (12, 3),
                          (13, 3), (14, 3), (15, 3), (16, 3), (17, 3), (17, 4), (17, 5), (17, 6), 
                          (17, 7), (17, 8), (17, 9), (17, 10), (17, 11), (17, 12), (17, 13), (17, 14), 
                          (17, 15), (16, 15), (15, 15), (14, 15), (13, 15), (13, 16), (13, 14), (13, 13), 
                          (12, 13), (11, 13), (11, 12), (2, 15), (3, 15), (3, 14), (3, 13), (2, 13), 
                          (2, 8), (3, 8), (4, 8), (4, 9), (4, 10), (5, 10), (6, 10)}
     walkable = get_walkable(maze)
     self.assertEqual(walkable, expected_walkable)
Esempio n. 42
0
 def test_gyro_sensor(self):
     get_input('Attach a GyroSensor then continue')
     d = GyroSensor()
     get_input('test ang')
     print(d.ang)
     print(d.mode)
     get_input('test rate')
     print(d.rate)
     print(d.mode)
     get_input('test ang_and_rate')
     print(d.ang_and_rate)
     print(d.mode)
Esempio n. 43
0
def main():
    jumps_input = get_input('../input/day5.in')

    jumps = map(int, jumps_input)
    steps = process_instructions(jumps, False)
    print "part1 steps: " + str(steps)

    jumps = map(int, jumps_input)
    steps = process_instructions(jumps, True)
    print "part2 steps: " + str(steps)
Esempio n. 44
0
def main():
    with open(get_input(__file__)) as file:
        file_input = file.read().strip()

    layers = [
        file_input[layer:layer + 25 * 6]
        for layer in range(0, len(file_input), 25 * 6)
    ]
    part1(layers.copy())
    part2(layers)
 def test_absolute_IMU(self):
     get_input('Attach a AbsoluteIMU at port 2 then continue')
     d = AbsoluteIMU(2)
     print(d.version)
     get_input('test compass')
     print(d.compass)
     get_input('test x_gyro')
     print(d.x_gyro)
Esempio n. 46
0
def rename_command():
    project, file = eclim.get_context()    
    # we cannot read the code from TM via stdin, as it will not have 
    # the correct line endings when editing windows files (it will just have \n)
    #code = sys.stdin.read()

    # so we read from disk
    with open(os.environ["TM_FILEPATH"]) as f:
        code = f.read()
    pos = caret_position(code)
    identifier = current_identifier()
    pos = code.find(identifier, pos-len(identifier))
    
    new_name = util.get_input(default=identifier,title="Enter new name")
    
    call_eclim(project, file, len(identifier), pos, new_name)
def count_and_sort():
    freqs = {}
    # The declaration for reactive observation of freqs
    observer = FreqObserver(freqs)
    # Let's get input from the user, or let her
    # feed the input automatically
    while get_input():
        try:
            w = non_stop_words().next()
            lock.acquire()
            freqs[w] = 1 if w not in freqs else freqs[w]+1
            lock.release()
        except StopIteration:
            # Let's wait for the observer thread to die gracefully
            observer.stop()
            sleep(1)
            break
Esempio n. 48
0
    def initialize(self):
        version = util.get_input('Enter Zoom version [2/3]: ')
        util.Msg('Changing admin password to \'d3fault\'...')

        url_25 = 'http://%s/hag/emweb/PopOutUserModify.htm/FormOne&user=admin&'\
                 'ex_param1=admin&new_pass1=d3fault&new_pass2=d3fault&id=3&'\
                 'cmdSubmit=Save+Changes' % self.config['target'].value
        url_30 = 'http://%s/hag/emweb/PopOutUserModify.htm?id=40&user=admin&'\
                 'Zadv=1&ex_param1=admin&new_pass1=d3fault&new_pass2=d3fault&'\
                 'id=3&cmdSubmit=Save+Changes' % self.config['target'].value
        url_logs = 'http://%s/Action?id=76&cmdClear+Log=Clear+Log' % self.config['target'].value

        try:
            if version == '2':
                urllib.urlopen(url_25).read()
            else:
                urllib.urlopen(url_30).read()

            util.Msg("Password reset, clearing logs...")
            urllib.urlopen(url_logs).read()
            util.Msg('Done.  Connect to %s with admin:d3fault' % self.config['target'].value)
        except Exception, e:
            util.Error('Unable to connect: %s' % e)
Esempio n. 49
0
# hyperparameters
HIDDEN_LAYER_SIZE = 256
DEPTH = 3
DROPOUT_RATE = 0.1
STABILIZING_TERM_WEIGHT = 10

SEQ_SIZE = 100
BATCH_SIZE = 10
L_RATE = 0.002
MAX_ITERATIONS = 100000
EVAL_INTERVAL = 100
PRINT_SAMPLES = True
TEMPERATURE = 0.7

# get input
input, VOCABULARY_SIZE, char_to_index, index_to_char = util.get_input('shakespear_train.txt', -1)
validation_input, _, _, _, = util.get_input('shakespear_val.txt', 5000)

# model parameters
Wxh = [input_matrix_init(VOCABULARY_SIZE if d == 0 else HIDDEN_LAYER_SIZE, HIDDEN_LAYER_SIZE) for d in xrange(DEPTH)]
Whh = [recurrent_matrix_init_IRNN(HIDDEN_LAYER_SIZE) for d in xrange(DEPTH)]
bh = [np.zeros((1, HIDDEN_LAYER_SIZE)) for d in xrange(DEPTH)]
Why = np.random.randn(HIDDEN_LAYER_SIZE, VOCABULARY_SIZE) * 0.0001
by = np.zeros((1, VOCABULARY_SIZE))

def forward_backward(inputs, targets, initial_states):
	'''
	Computes forward and backward pass through the recurrent net, for SEQ_SIZE time steps
	-inputs is an array of shape [BATCH_SIZE, SEQ_SIZE, VOCABULARY_SIZE] and holds one hot encoded inputs to the model
	-targets has a shape [BATCH_SIZE, SEQ_SIZE], holds just the indices of the target chars
	-initial_states contains state of all the recurrent hidden units, shape [DEPTH, BATCH_SIZE, HIDDEN_LAYER_SIZE]
Esempio n. 50
0
 def test_led(self):
     get_input('Test LED')
     led = LED()
     get_input('Test left red')
     led.left.color=LED.COLOR.RED
     get_input('Test left green')
     led.left.color=LED.COLOR.GREEN
     get_input('Test left amber')
     led.left.color=LED.COLOR.AMBER
     get_input('Test right blink')
     led.right.blink(color=LED.COLOR.GREEN,delay_on=1000, delay_off=2000 )
     time.sleep(10)
     get_input('Test left and right on')
     led.left.on()
     led.right.on()
     time.sleep(5)
     get_input('Test left and right off')
     led.left.off()
     led.right.off()
Esempio n. 51
0
 def test_i2cs(self):
     get_input("Attach an I2CS sensor on port 3 then continue")
     d = I2CS(port=3, addr=0x01)
     print(d.read_byte())
     print(d.read_byte_data(0x00))
Esempio n. 52
0
from ev3.lego import UltrasonicSensor
from util import get_input

get_input('Start')

d = Ultrasonic_Sensor()
distStart = d.dist_cm
#Initialisiere System
while distStart == d.dist_cm:
 pass # Sobald sich der Wert ändere beginne mit der Aufzeichnung
timeStart = datetime.datetime.now()
distStart = d.dist_cm
while distStart == d.dist_cm:
 pass# Sobald sich der ert erneut ändert breche die Aufzeichnung ab
timeEnd = datetime.datetime.now()
distEnd = d.dist_cm
timeDiff = timeEnd - timeDiff
#print(timeDiff)
distDiff = distEnd - distStart
#print(distDiff)
timeDiff
distDiff
    def count(self):
        def non_stop_words():
            stopwords = set(open('../stop_words.txt').read().split(',')  + list(string.ascii_lowercase))
            for line in f:
                yield [w for w in re.findall('[a-z]{2,}', line.lower()) if w not in stopwords]

        words = next(non_stop_words())
        lock.acquire()
        for w in words:
            self.freqs[w] = 1 if w not in self.freqs else self.freqs[w]+1
        lock.release()

#
# The controller
#
print("Press space bar to fetch words from the file one by one")
print("Press ESC to switch to automatic mode")
model = WordsCounter()
view = FreqObserver(model.freqs)
with open(sys.argv[1]) as f:
    while get_input():
        try:
            model.count()
        except StopIteration:
            # Let's wait for the view thread to die gracefully
            view.stop()
            sleep(1)
            break


 def test_ultrasonic_sensor(self):
     get_input('Attach a UltrasonicSensor then continue')        
     d = UltrasonicSensor()        
     get_input('test dist_cm')
     print(d.dist_cm)
     print(d.mode)
     get_input('test dist_in')
     print(d.dist_in)
     print(d.mode)
     get_input('test listen')
     print(d.listen)
     print(d.mode)
     get_input('test si_cm')
     print(d.si_cm)
     print(d.mode)
     get_input('test si_in')
     print(d.si_in)
     print(d.mode)
Esempio n. 55
0
 def test_key(self):
     d = Key()
     get_input('Test keyboard. Hold Up key')
     print(d.up)
     get_input('Test keyboard. Release Up key')
     print(d.up)
     get_input('Test keyboard. Hold Down key')
     print(d.down)
     get_input('Test keyboard. Release Down key')
     print(d.down)
     get_input('Test keyboard. Hold Left key')
     print(d.left)
     get_input('Test keyboard. Release Left key')
     print(d.left)
     get_input('Test keyboard. Hold Right key')
     print(d.right)
     get_input('Test keyboard. Release Right key')
     print(d.right)
     get_input('Test keyboard. Hold Backspace key')
     print(d.backspace)
     get_input('Test keyboard. Release Backspace key')
     print(d.backspace)
     get_input('Test keyboard. Hold Enter key')
     print(d.enter)
     get_input('Test keyboard. Release Enter key')
     print(d.enter)
 def test_touch_sensor(self):
     get_input('Attach a TouchSensor then continue')    	
     d = TouchSensor()
     get_input('test pushed')
     print(d.is_pushed)
     print(d.mode)