def main(): name_gen = NameGenerator() device_map = {} tree = device_parser.parse_data('xmls/data_grouped.xml') devices_data = device_parser.parse_groupings(tree) while True: inp = input_str(MENU_STR, valid={'a', 'p', 'r', 'q', 'd'}) print() if inp == 'a': dev_key = input_device_model(devices_data, '') key,value = device_parser.search_data(tree, dev_key) device_map[name_gen.generate_name(key)] = value if 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] else: print('There are no devices to delete\n') if inp == 'p': print(set(device_map.keys())) if inp == 'r': input_generators = make_input_generators(device_map) integration_period = input_int('Enter integration period: ') run_sim(integration_period, input_generators) write_to_ifile('csvs/test_group.csv', integration_period, input_generators) analyze_data('csvs/test_group.csv', integration_period, device_map) print() if inp == 'q': return
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
def main(): name_gen = NameGenerator() device_map = {} tree = device_parser.parse_data('xmls/data_grouped.xml') devices_data = device_parser.parse_groupings(tree) while True: inp = input_str(MENU_STR, valid={'a', 'p', 'r', 'q', 'd'}) print() if inp == 'a': dev_key = input_device_model(devices_data, '') key,value = device_parser.search_data(tree, dev_key) device_map[name_gen.generate_name(key)] = value if 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] else: print('There are no devices to delete\n') if inp == 'p': print(set(device_map.keys())) if inp == 'r': input_generators = make_input_generators(device_map) integration_period = input_int('Enter integration period: ') run_sim(integration_period, input_generators) write_to_ifile('csvs/test_group.csv', integration_period, input_generators) write_to_peramfile('csvs/run_perams.cfg', integration_period, device_map) print ("CSV File Input Gen:") print(input_generators) print ("Integration Period:") print(integration_period) print ("Device Map:") print(device_map) #template code in place, input parsernot fully implemented #read_back_integration_period, read_back_device_map = read_from_peramfile('csvs/run_perams.cfg') #print ("Read-back Integration Period:") #print(read_back_integration_period) #print ("Read-back Device Map:") #print(read_back_device_map) input("CSV Schedule File Written - Press Enter to continue with analysis ...") analyze_data('csvs/test_group.csv', integration_period, device_map) print() if inp == 'q': return
def input_at_interval(ig_list: ['InputGenerator'], time_interval: int): '''helper function for running the simulation''' for inp_gen in ig_list: inp = input_str('Are you using the {} [yes/no]: '.format(inp_gen.dev_name), {'yes', 'y', 'no', 'n'}) if inp.lower() in ['yes', 'y']: 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 it in {}: '.format( sorted(zip(rlen, inp_gen.states()))), valid=inp_gen.states().union(str_rlen)) input_dict = dict(zip(rlen, inp_gen.states())) if not state in inp_gen.states(): state = input_dict[int(state)] inp_gen.write_on_state(state, time_interval) elif inp.lower() in ['no', 'n']: inp_gen.write_on_state('off', time_interval)