Exemplo n.º 1
0
def input_device_model(devices_data: {dict}, p_string: str) -> list:
    if type(devices_data) == set:
        z = zip(range(1, len(devices_data) + 1), devices_data)
        str_range = set(str(x) for x in range(1, len(devices_data) + 1))
        inp = input_str(
            'Which type of {} device do you want to choose? {}: '.format(
                p_string, sorted(z)),
            valid=devices_data.union(str_range))
        input_dict = dict(zip(range(1, len(devices_data) + 1), devices_data))

        if not inp in devices_data:
            inp = input_dict[int(inp)]

        print('selected: {}'.format(inp))
        return [inp]
    else:
        keys_set = set(devices_data.keys())
        z = zip(range(1, len(keys_set) + 1), keys_set)
        str_range = set(str(x) for x in range(1, len(devices_data) + 1))
        inp = input_str(
            'Which type of {} device do you want to choose? {}: '.format(
                p_string, sorted(z)),
            valid=keys_set.union(str_range))

        input_dict = dict(zip(range(1, len(keys_set) + 1), keys_set))

        if not inp in keys_set:
            inp = input_dict[int(inp)]

        p_string += '{}:'.format(inp)
        to_return = [inp]
        print('selected: {}'.format(inp))
        to_return.extend(input_device_model(devices_data[inp], p_string))

        return to_return
Exemplo n.º 2
0
def input_device_model(devices_data: {dict}, p_string: str) -> list:
    if type(devices_data) == set:
        z = zip(range(1, len(devices_data) + 1), sorted(devices_data))
        str_range = set(str(x) for x in range(1, len(devices_data) + 1))
        inp = input_str(
            'Which type of {} device do you want to choose? {}: '.format(
                p_string, sorted(z)),
            valid=devices_data.union(str_range))
        #         print("Input_device_model: INPUT: ")
        #         print(inp)
        input_dict = dict(
            zip(range(1,
                      len(devices_data) + 1), sorted(devices_data)))

        if not inp in devices_data:
            inp = input_dict[int(inp)]

        print('selected: {}'.format(inp))
        return [inp]
    else:
        keys_set = set(devices_data.keys())
        z = zip(range(1, len(keys_set) + 1), sorted(keys_set))
        str_range = set(str(x) for x in range(1, len(devices_data) + 1))
        #This is the input that the program will prompt the use to input
        inp = input_str(
            'Which type of {} device do you want to choose? {}: '.format(
                p_string, sorted(z)),
            valid=keys_set.union(str_range))
        #         print("ELSE: input: ")
        #         print(inp)
        input_dict = dict(zip(range(1, len(keys_set) + 1), sorted(keys_set)))

        if not inp in keys_set:
            inp = input_dict[int(inp)]

        p_string += '{}:'.format(inp)
        to_return = [inp]
        print('selected: {}'.format(inp))
        #         print("ELSE: about to call input_device_model again")
        to_return.extend(input_device_model(devices_data[inp], p_string))

        return to_return
Exemplo n.º 3
0
def input_at_interval(ig_list: ['InputGenerator'], time_interval: int):
    '''helper function for running the simulation'''
    for inp_gen in ig_list:
        rlen = range(1, len(inp_gen.states()) + 1)
        str_rlen = set(str(x) for x in rlen)
        state = input_str('Which of the following states is \"{}\" in {}: '.format(inp_gen.dev_name,\
                          sorted(zip(rlen, sorted(inp_gen.states())))), valid=inp_gen.states().union(str_rlen))

        input_dict = dict(zip(rlen, sorted(inp_gen.states())))
        if not state in sorted(inp_gen.states()):
            state = input_dict[int(state)]

        inp_gen.write_on_state(state, time_interval)
Exemplo n.º 4
0
def run_sim_state(integration_period: int, input_generators: list):
    while True:
        for inp_gen in input_generators:
            rlen = range(1, len(inp_gen.states()) + 1)
            str_rlen = set(str(x) for x in rlen)
            state = input_str('Which of the following states is \"{}\" in {}[enter 0 to end the simulation]: '.format(inp_gen.dev_name,\
                                sorted(zip(rlen, sorted(inp_gen.states())))), valid=inp_gen.states().union(str_rlen))
            if state == '0':
                return
            input_dict = dict(zip(rlen, sorted(inp_gen.states())))
            if not state in sorted(inp_gen.states()):
                state = input_dict[int(state)]
            time_interval = input_int(
                'How long is this time interval (in minutes)[enter 0 to end the simulation]: '
            )
            if time_interval == 0:
                return
            num_periods_interval = int(60 / integration_period * time_interval)
            inp_gen.write_on_state(state, num_periods_interval)
Exemplo n.º 5
0
    #Error Handling: File Parsing
    try:
        # Parse xml
        tree = parse_data(file_location)
    except:
        print("Error: Unable to parse XML file")
        print("Program Quit")
        sys.exit(1)

    # All labels {class,type,brand,model} without any data
    devices_data = parse_groupings(tree)
    # devices_data = reorder_tree(devices_data)

    while True:
        #Ask user if they want to manually input or read from a file.
        inputOption = input_str(INPUT_OPT_STR, valid={'m', 'f'}).lower()

        if inputOption == 'm':  #User choose to input data manually
            inp = input_str(MENU_STR, valid={'a', 'd', 'p', 'r', 'q'}).lower()
            print()
            '''
            a = add. 
            a -> add devices. there are data inside the devices. After adding devices, we are pulling data of those devices from
            csv files.
            '''
            if inp == 'a':
                # dev_key[list of choice by steps]
                dev_key = input_device_model(devices_data, '')
                # key -> "type+brand+model", value -> power and etc
                key, value = search_data(tree, dev_key)
                # name_gen.generate_name checks DUPLICATES and add a number at the end if DUPLICATED
Exemplo n.º 6
0
    #Error Handling: File Parsing
    try:
        # Parse xml
        tree = parse_data(file_location)
    except:
        print("Error: Unable to parse XML file")
        print("Program Quit")
        sys.exit(1)

    # All labels {class,type,brand,model} without any data
    devices_data = parse_groupings(tree)
    # devices_data = reorder_tree(devices_data)

    while True:
        inp = input_str(MENU_STR, valid={'a', 'd', 'p', 'r', 'q'}).lower()
        print()
        if inp == 'a':
            # dev_key[list of choice by steps]
            dev_key = input_device_model(devices_data, '')
            # key -> "type+brand+model", value -> power and etc
            key, value = search_data(tree, dev_key)
            # name_gen.generate_name checks DUPLICATES and add a number at the end if DUPLICATED
            device_map[name_gen.generate_name(key)] = value
        elif inp == 'd':
            valid = set(device_map.keys())
            if len(valid) > 0:
                to_delete = input_str(
                    'Which device do you want to delete? {}: '.format(valid),
                    valid)
                del device_map[to_delete]
Exemplo n.º 7
0
    #Error Handling: File Parsing
    try:
        # Parse xml
        tree = parse_data(file_location)
    except:
        print("Error: Unable to parse XML file")
        print("Program Quit")
        sys.exit(1)

    # All labels {class,type,brand,model} without any data
    devices_data = parse_groupings(tree)
    # devices_data = reorder_tree(devices_data)

    while True:
        inp = input_str(MENU_STR, valid={'a', 'b', 'd', 'e', 'p', 'r',
                                         'q'}).lower()
        print()
        if inp == 'a':
            # dev_key[list of choice by steps]
            dev_key = input_device_model(devices_data, '')
            # key -> "type+brand+model", value -> power and etc
            key, value = search_data(tree, dev_key)
            # name_gen.generate_name checks DUPLICATES and add a number at the end if DUPLICATED
            device_map[name_gen.generate_name(key)] = value
        elif inp == 'b':
            # TODO: ASK FOR input filename and path
            batch_file_name = input_str(
                'Please enter the name CSV file you would like to process [ex. batch_file1.csv ]: '
            )
            print("DEVICE MAP")
            print(device_map)