def ui_menu(): cmd = ui_read_command() cmd = validate_cmd(cmd) if(cmd[0] == "add"): ui_add(storage, cmd) add_stack(stack, storage) ui_menu() if(cmd[0] == "insert"): ui_insert(storage, cmd) add_stack(stack, storage) ui_menu() if(cmd[0] == "remove"): if(len(cmd) == 4): remove_to(storage, int(cmd[1]), int(cmd[3])) elif(cmd[1] == "in" or cmd[1] == "out"): remove_type(storage, cmd[1]) else: remove(storage, int(cmd[1])) add_stack(stack, storage) ui_menu() if(cmd[0] == "replace"): replace(storage, cmd) add_stack(stack, storage) ui_menu() if(cmd[0] == "default"): create_df_storage(storage) add_stack(stack, storage) ui_menu() if(cmd[0] == "list"): if(len(cmd)==1): ui_list(storage) elif(len(cmd) == 2): ui_list_type(storage, cmd[1]) elif(cmd[1] == "balance"): ui_list_balance(storage, int(cmd[2])) else: ui_list_value(storage, cmd[1], int(cmd[2])) ui_menu() if(cmd[0] == "exit"): exit() if(cmd[0] == "sum"): sum_type(storage, cmd[1]) ui_menu() if(cmd[0] == "max"): max_tr(storage, cmd[1], int(cmd[2])) ui_menu() if(cmd[0] == "filter"): l = len(cmd) if(l == 2): filter_type(storage, cmd[1]) ui_list(storage) if(l == 3): filter(storage, cmd[1], int(cmd[2])) ui_list(storage) add_stack(stack, storage) ui_menu() if(cmd[0] == "undo"): storage.clear() storage.update(undo(stack,storage)) ui_menu()
def ui_menu1(): print("\nTo exit the application input 9\n" "To add a new transaction in the current day input 0\n" "To insert a new transaction in a certain day input 1\n" "To remove transactions input 2\n" "To replace a transaction input 3\n" "To list the transactions input 4\n" "To sum the transaction considering their type input 5\n" "To get the maximum value of a transaction considering its type input 6\n" "To undo an operation input 7\n" "To get a default account input 8\n") menu = int(input()) cmd = ui_read_comm(menu) cmd = validate_cmd(cmd) if(cmd[0] == "add"): ui_add(storage, cmd) add_stack(stack, storage) ui_menu1() if(cmd[0] == "insert"): ui_insert(storage, cmd) add_stack(stack, storage) ui_menu1() if(cmd[0] == "remove"): if(len(cmd) == 4): remove_to(storage, int(cmd[1]), int(cmd[3])) elif(cmd[1] == "in" or cmd[1] == "out"): remove_type(storage, cmd[1]) else: remove(storage, int(cmd[1])) add_stack(stack, storage) ui_menu1() if(cmd[0] == "replace"): replace(storage, cmd) add_stack(stack, storage) ui_menu() if(cmd[0] == "default"): create_df_storage(storage) add_stack(stack, storage) ui_menu1() if(cmd[0] == "list"): if(len(cmd)==1): ui_list(storage) elif(len(cmd) == 2): ui_list_type(storage, cmd[1]) elif(cmd[1] == "balance"): ui_list_balance(storage, int(cmd[2])) else: ui_list_value(storage, cmd[1], int(cmd[2])) ui_menu1() if(cmd[0] == "exit"): exit() if(cmd[0] == "sum"): sum_type(storage, cmd[1]) ui_menu1() if(cmd[0] == "max"): max_tr(storage, cmd[1], int(cmd[2])) ui_menu() if(cmd[0] == "filter"): l = len(cmd) if(l == 2): filter_type(storage, cmd[1]) ui_list(storage) if(l == 3): filter(storage, cmd[1], int(cmd[2])) ui_list(storage) add_stack(stack, storage) ui_menu1() if(cmd[0] == "undo"): storage.clear() storage.update(undo(stack,storage)) ui_menu1()
def test_filter(mocker): yes = mocker.Mock(return_value=True) no = mocker.Mock(return_value=False) assert functions.filter(yes, [1, 2, 3]) == [1, 2, 3] assert functions.filter(no, [1, 2, 3]) == []
# filtering nodes that don't have edges??? (like a vin with no vout or a vout with no vin) result = result.filter(lambda (key, value): len(value) == 4) # wallets contains # key: transactionID # value: [walletID] - list because of me for loop later wallets = result.map(lambda (key, value): (value[1], [value[3]])) wallets = wallets.reduceByKey(lambda x, y: x + y) # making sure wallets has only one value wallets = wallets.map(lambda (key, value): (key, [value[0]])) # key: (transactionID) (from) # value: [(n, txid(to), value, reciever)] this is a list of the 4-tuple for each out (n) result2 = result.reduceByKey(lambda x, y: [x] + [y]) # key is transactionID # Value is list of 4-tuple and [WalletID] result3 = result2.union(wallets) result3 = result3.reduceByKey(lambda x, y: [x] + [y]) # drop item if there are no transactions for the walletID result3 = result3.filter(lambda (key, value): len(value) != 1) result3 = result3.filter(lambda x: f.filter(x)) # does not work right now. Trying to remove walletID from value and put it in key result4 = result3.map(lambda x: f.coolStory(x)) result4.saveAsTextFile("pleaseHelp") # [res2.pop()[0] for thing in res2 if len(thing) == 1][0] - ignore