예제 #1
0
def remove_to(storage, day, end_day):
    #input: dict storage, integer day, integer end_day
    #spec: removes all the transactions from day day to day end_day
    #return: -
    for i in range(
            day,
            end_day + 1,
    ):
        get_day(storage, i).clear()
예제 #2
0
def add(storage, value, tr_type, description):
    #input: dict storage, integer value, string tr_type, string description
    #output: adds a transaction in the current day
    #return: -
    lst = []
    lst.append(value)
    lst.append(tr_type)
    lst.append(description)
    get_day(storage, datetime.date.today().day).append(lst) # add to the other entries in that day
예제 #3
0
def insert(storage, day, value, tr_type, description):
    #input: dict storage, integer value, string tr_type, string description
    #spec: inserts a transaction in day day
    #return: -
    lst = []
    lst.append(value)
    lst.append(tr_type)
    lst.append(description)
    index = 0
    get_day(storage, day).append(lst)
예제 #4
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
예제 #5
0
def filter(storage, tr_type, value):
    #function that keeps only tr_type tranzactions with values smaller than value
    #input: dict storage, str tr_type, int value
    #output: -
    filter_type(storage, tr_type)
    for i in range(31):
        length = len(get_day(storage, i))
        j = 0
        while (j < length):
            if (get_value(storage, i, j) >= value):
                get_day(storage, i).remove(get_trans(storage, i, j))
                length -= 1
            else:
                j += 1
예제 #6
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))
예제 #7
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
예제 #8
0
def ui_list(storage):
    for i in range(31):
        ok = 1
        for j in range(len(get_day(storage, i))):
              if(ok):
                   print("\nday ", i, "\n---------------------------------------------------")
                   ok = 0
              print(write(storage, i, j))
        if(not ok):
            print("\n")
예제 #9
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)
예제 #10
0
def remove(storage, day):
    #input: dict storage, integer day
    #spec: removes all the transactions in day day
    #return: -
    get_day(storage, day).clear()
예제 #11
0
def create_df_storage(storage):
    #input: dict storage
    #spec: creates a default storage
    #return: -
    storage.clear()
    create_storage(storage)
    for i in range(datetime.date.today().day + 1):
        get_day(storage, i).append([10, "out", "piggy_bank"])
    get_day(storage, 1).append([100, "out", "pizza"])
    get_day(storage, 2).append([300, "out", "donut"])
    get_day(storage, 12).append([2080, "in", "salary"])
    get_day(storage, 12).append([150, "out", "cinema"])
    get_day(storage, 19).append([100, "in", "grandma"])
    get_day(storage, 20).append([70, "out", "book"])
    get_day(storage, 20).append([300, "out", "shopping"])
    get_day(storage, 20).append([50, "out", "bus ticket"])
    get_day(storage, 20).append([50, "out", "bus ticket"])
def test_get_day():
    storage = {23: [[100, "out", "pizza"], [1000, "in", "salary"]]}
    assert get_day(storage, 23) == [
        [100, "out", "pizza"], [1000, "in", "salary"]
    ], 'should get [[100, "out", "pizza"],[1000, "in", "salary"]]'