def processData(self): sourceFilepath = QtGui.QFileDialog.getOpenFileName(self, "Select data file", "", "*.txt") if os.path.isfile(sourceFilepath): destinationPath = None if self.dataPath: destinationPath = self.dataPath + "/" else: destinationPath = "./" destinationFilename = QtCore.QString(sourceFilepath).replace(QtCore.QRegExp(".*/"), "") print("DestinationPath: %s" % destinationPath) print("DestinationFilename: %s" % destinationFilename) ToPickle.parse( str(sourceFilepath), str(destinationPath + destinationFilename.replace(".txt", ".pkl")) ) ToColmat.parse( str(destinationPath + destinationFilename), str(destinationPath + destinationFilename.replace(".pkl", "_colmat.pkl")) ) self.ui.dataSet.addItem(destinationFilename) self.ui.trainingSet.addItem(destinationFilename)
def main(): cli = argparse.ArgumentParser('') cli.add_argument( '-v', '--verbose', dest="verbose", help="Enable verbose output", default=False, action="store_true" ) cli.add_argument( 'operations', metavar="N", type=str, nargs="+", help="Operation to be performed" ) options = cli.parse_args() logger = logging.getLogger("calculator") fh = logging.FileHandler("calculator.log", mode="w") if options.verbose: logger.setLevel(logging.DEBUG) else: logger.setLevel(logging.INFO) ch = logging.StreamHandler() logger.addHandler(ch) logger.addHandler(fh) result = parse_input.parse(options.operations) logger.info("the result of %s is %s" % (" ".join(options.operations), result))
def repl(): ex = False while not ex: print("command> ", end="") cmd = input() tasks = parse(cmd) for t in tasks: if t == "exit": ex = True else: implement(t) print("Done")
print("solcast is the only forecast provider supported") print("") print("electricity meters supported :") print("----------------------------") for meter in meter_types: print("{} ({})".format(meter, meter_types[meter])) print("") print("inverters supported :") print("----------------------------") for inverter in invertor_types: print(inverter) sys.exit(0) if args.verbose: debug = True config = parse(args.config_yaml, debug=debug) if not config: print("error in config yaml file") sys.exit(1) if 'influxdb' in config: config_influxdb = config['influxdb'] solar_db = config_influxdb['db'] print("Influxdb client enabled") if args.pretest: calc_daily_self_consumption() sys.exit(0) if 'electricity_meter' in config: config_electricity_meter = config['electricity_meter'] if args.dryrun: print("Start dryrun electricity meter") if not periodic_get_meter_value():
# else: # next_row += '.' next_seats_layout[y] = next_row for row in seats_layout: print(row) print() # if rounds > 10: # return # if change == False: # return occupied if seats_layout != next_seats_layout: seats_layout = next_seats_layout simultate_round() rounds = 0 seats_layout = parse('21input.txt') print(simultate_round()) print(rounds) occupied = 0 for row in seats_layout: for seat in row: if seat == '#': occupied += 1 print(occupied)
from parse_input import parse tree_map = parse('05input.txt') coordinates = {'x': 0, 'y': 0} def make_move(tree_map, coordinates, tree_count=0): row = tree_map[coordinates['y']] if row[coordinates['x'] % len(row)] == '#': tree_count += 1 coordinates['x'] += 3 coordinates['y'] += 1 if coordinates['y'] == len(tree_map): return tree_count return (make_move(tree_map, coordinates, tree_count)) # line = tree_map[coordinates['y']] # print(line, len(line)) print(make_move(tree_map, coordinates))
from parse_input import parse def check_line(line): line = line.split() count_range = line[0].split('-') letter = line[1].strip(':') password = line[2] letter_count = 0 for char in password: if letter == char: letter_count += 1 if letter_count >= int(count_range[0]) and letter_count <= int( count_range[1]): return True input_list = parse('03input.txt') count = 0 for line in input_list: if check_line(line): count += 1 print(count)
from parse_input import parse raw_input = parse('41input.txt') def check_ingredients_len(allergens_dict): for ingredients in allergens_dict.values(): if len(ingredients) > 1: return True return False def remove_ingredient_from_other_allergen_ingredient_lists( allergen, ingredient, allergens_dict): for allergen_key in allergens_dict.keys(): if allergen_key != allergen and ingredient in allergens_dict[ allergen_key]: allergens_dict[allergen_key].remove(ingredient) return allergens_dict foods = [] for line in raw_input: ingredients = line.split(' (contains ')[0] allergens = line.split(' (contains ')[1].strip(')') ingredients = ingredients.split() allergens = allergens.split(', ') food_dict = {'ingredients': ingredients, 'allergens': allergens} foods.append(food_dict) ingredients_list = []
from parse_input import parse raw_code = parse('27input.txt') code = [line.split(' = ') for line in raw_code] bits = [1] for i in range(1, 36): bits.append(bits[i - 1] * 2) bits.reverse() def to_bits(integer): bit_num = '' for bit in bits: if integer >= bit: integer -= bit bit_num += '1' else: bit_num += '0' return bit_num def from_bits(bit_num): integer = 0 for i, bit in enumerate(bit_num): if bit == '1': integer += bits[i] return integer def use_mask(mask, bit_num):
from parse_input import parse import numpy import re directions = parse('47input.txt') # for direction in directions: # print(direction) all_dirs = r'(n|ne|e|se|s|sw|w|nw)*' one_dir = r'(n|ne|e|se|s|sw|w|nw){1}' test = 'sesenwnenenewseeswwswswwnenewsewsw' test_list = re.findall(one_dir, test) print(test_list) print(test) print(''.join(test_list))
from parse_input import parse evasive_actions = parse('23input.txt') starting_position = (0, 0) waypoint = (10, -1) current_pos = starting_position dir_dict = {'N': (0, -1), 'S': (0, 1), 'E': (1, 0), 'W': (-1, 0)} for evasive_action in evasive_actions: action = evasive_action[0] value = int(evasive_action[1:]) if action in ['N', 'S', 'E', 'W']: next_pos_x = waypoint[0] + dir_dict[action][0] * value next_pos_y = waypoint[1] + dir_dict[action][1] * value waypoint = (next_pos_x, next_pos_y) elif action in ['L', 'R']: if value == 180: waypoint = (-waypoint[0], -waypoint[1]) elif (action == 'L' and value == 90) or (action == 'R' and value == 270): waypoint = (waypoint[1], -waypoint[0]) elif (action == 'R' and value == 90) or (action == 'L' and value == 270): waypoint = (-waypoint[1], waypoint[0])
def main(): scores = parse() print('DCG: %f' % dcg(scores)) print('NDCG: %f' % ndcg(scores)) print('pFound: %f' % pfound(scores))
from parse_input import parse boot_code = parse('15input.txt') acc = 0 line_no = 0 lines_visited = [] def boot(line_no): global boot_code global acc if line_no in lines_visited: return False if line_no == len(boot_code) - 1: return True lines_visited.append(line_no) line = boot_code[line_no] cmd = line.split(' ')[0] val = int(line.split(' ')[1])#[1:]) if cmd == 'acc': acc += val line_no += 1 elif cmd == 'jmp': line_no += val elif cmd == 'nop': line_no += 1 return boot(line_no)
print() print('count: ', bag_counter) inside = in_rule['in'] if inside == []: mult_stack.pop() for bag in inside: previous_mult = mult # print(bag) for out_rule in rules: if out_rule['out'] == bag['description']: # mult *= bag['num'] mult_stack.append(mult * bag['num']) print(bag) print(out_rule) print(mult_stack) bag_count(out_rule, rules, mult_stack) rules_list = parse('13input.txt') rules = [] for rule in rules_list: rule_dict = make_rule_dict(rule) rules.append(rule_dict) bag_counter = 0 for rule in rules: if rule['out'] == 'shiny gold': bag_count(rule, rules) print(bag_counter)
from parse_input import parse import re expressions = parse('35input.txt') parens_match = r'\(([0-9]|\*|\+|\s)*\)' test = '2 * 3 + (4 * 5)' test = '1 + (2 * 3) + (4 * (5 + 6))' def linear_math(expression): expression = expression.split() num = 0 operator = '' operators = ['*', '+'] for i, char in enumerate(expression): if i == 0: num = char elif char in operators: operator = char else: num = eval(str(num) + operator + char) return num def evaluate(expression): match = re.search(parens_match, expression) if match: sub_expression = match.group().strip('()') sub_range = match.span()
from parse_input import parse def get_2020_mult(input_list): for number1 in input_list: for number2 in input_list: if number1 + number2 == 2020: return number1 * number2 print(get_2020_mult(parse('01input.txt')))
from parse_input import parse notes = parse('25input.txt') # print(notes) timestamp = int(notes[0]) bus_ids = [int(bus_id) for bus_id in notes[1].split(',') if bus_id != 'x'] # print(timestamp) # print(bus_ids) next_bus_tups = [] for bus_id in bus_ids: time = 0 while time <= timestamp: time += bus_id next_bus_tups.append((time, bus_id)) earliest_time = min([next_bus_tup[0] for next_bus_tup in next_bus_tups]) for next_bus_tup in next_bus_tups: if next_bus_tup[0] == earliest_time: next_bus_id = next_bus_tup[1] print(next_bus_id * (earliest_time - timestamp))
# test_column = 'RLR' def decode_column(bsp_column, column_range=(0, 7)): l_or_r = bsp_column[0] bsp_column = bsp_column[1:] low = column_range[0] high = column_range[1] middle = low + (high - low) / 2 column_range = (low, floor(middle)) if l_or_r == 'L' else (ceil(middle), high) if bsp_column: return decode_column(bsp_column, column_range) return column_range[0] # print(decode_column(test_column)) boarding_passes = parse('09input.txt') seat_ids = list(range(1024)) for boarding_pass in boarding_passes: # bsp = binary space partitioning bsp_row = boarding_pass[:7] bsp_column = boarding_pass[7:] row = decode_row(bsp_row) column = decode_column(bsp_column) seat_id = row * 8 + column seat_ids.remove(seat_id) for seat_id in seat_ids: print(seat_id)