Exemple #1
0
def max_tr(storage, tr_type, day):
    maximum = 0
    for i in range(len(get_day(storage, day))):
        if (get_type(storage, day, i) == tr_type):
            if (get_value(storage, day, i) > maximum):
                maximum = get_value(storage, day, i)
    print("The maximum " + tr_type + " tranzaction in day " + str(day) +
          " is " + str(maximum))
Exemple #2
0
def type_sum(storage, day, tr_type):
    #input: dict storage, integer day, string tr_type
    #spec: sums up all the transactions values in day day of type tr_type
    #return: integer s
    s = 0
    for i in range(len(get_day(storage, day))):
        if (get_type(storage, day, i) == tr_type):
            s += get_value(storage, day, i)
    return s
Exemple #3
0
def replace(storage, cmd):
    #input: dict storage, string cmd
    #spec: replaces the value of transaction in day day with type tr_type and description description with value value
    day = int(cmd[1])
    value = int(cmd[5])
    tr_type = cmd[2]
    description = cmd[3]
    for i in range(len(get_day(storage, day))):
        if (get_descr(storage, day, i) == description):
            if (get_type(storage, day, i) == tr_type):
                set_value(storage, day, i, value)
Exemple #4
0
def ui_list_type(storage, tr_type):
    for i in range(31):
        ok = 1
        for j in range(len(get_day(storage, i))):
               if(get_type(storage, i ,j) == tr_type):
                   if(ok):
                       print("\nday ", i, "\n---------------------------------------------------")
                       ok = 0
                   print(write(storage, i, j))
        if(not ok):
            print("\n")
Exemple #5
0
def remove_type(storage, tr_type):
    #input: dict storage, string tr_type
    #spec: removes all the transactions of type tr_type
    #return: -
    for i in range(31):
        length = len(get_day(storage, i))
        j = 0
        while (j < length):
            if (get_type(storage, i, j) == tr_type):
                get_day(storage, i).remove(get_trans(storage, i, j))
                length -= 1
            else:
                j += 1
Exemple #6
0
def write(storage, i, j):
    #input: dict storage, integer index
    #output: string string containing the elements of the list(index key) from the storage all put together
    string = str(get_value(storage, i, j)) + " "
    string += get_type(storage, i, j) + " " + get_descr(storage, i, j)
    return string
def test_get_type():
    storage = {23: [[100, "out", "pizza"], [1000, "in", "salary"]]}
    assert get_type(storage, 23, 0) == "out", 'should get "out"'
    assert get_type(storage, 23, 1) == "in", 'should get "in"'