Ejemplo n.º 1
0
def insert(userInput, categoryList, undo_steps, undo, step_count):

    day, categ, sum, remainder = getDayCategAndValue(userInput)

    try:
        day = int(day)  # Verifing that the user input is correct
        if day > 31 or day < 1 or len(
                remainder
        ) > 0:  # Imposing that the day must be a number between 1 and 31 ( [1, 31] )
            return "   Invalid syntax"
    except ValueError:
        return "   Invalid day value or syntax"  # day

    try:
        sum = int(sum)  # sum
        if undo == 1 and sum < 0 or categ not in categoryList:
            return "   Invalid syntax"
    except ValueError:
        return "   Invalid sum value"

    categoryDictionary = files.initializeDictionary(
        day, categoryList)  # Today's date (day)
    categoryDictionary[
        categ] += sum  # updating the sum of the selected category
    files.fileUpdate(
        day, categoryDictionary
    )  # updating the file for this day with the new information

    if undo:
        stepCountUpdate(undo_steps, sum, categ, day, step_count)
        return "   Inserted successfully!"
Ejemplo n.º 2
0
def removeExpenses(a, b, undo_steps, step_count, categoryList):
    '''
            This function removes all the expenses for days in the interval [a, b] passed in by parameters (updates the files with the
        default dictionary)
        input: a, b - start day and end day
    '''
    default_dict = {
        "housekeeping": 0,
        "food": 0,
        "transport": 0,
        "clothing": 0,
        "internet": 0,
        "others": 0
    }

    for i in range(a, b + 1):
        aux_dict = files.initializeDictionary(i, categoryList)
        for key in aux_dict:
            if aux_dict[key] != 0:
                undo_steps.append([
                    step_count, "insert " + str(i) + " " + str(aux_dict[key]) +
                    " " + str(key)
                ])  # updating the undo list

        files.fileUpdate(i, default_dict)
Ejemplo n.º 3
0
def deleteAllExcept(category, symbol, value, undo_steps, step_count,
                    categoryList):
    '''
        This function formats all the categories except the one that was passed through the parameter
        input: the category that we would like to filter

            This function will filter all of the categories leaving the category from the parameters
        intact if and only if the condition regarding the symbol is fulfilled
        input: the category, symbol and value

    '''
    for i in range(1, 32):
        dictForDayI = files.initializeDictionary(i, categoryList)

        for key in dictForDayI:
            if key != category or (
                    symbol == ">" and dictForDayI[key] <= value) or (
                        symbol == "<" and dictForDayI[key] >= value) or (
                            symbol == "=" and dictForDayI[key] != value):
                if dictForDayI[key] != 0:
                    undo_steps.append([
                        step_count, "insert " + str(i) + " " +
                        str(dictForDayI[key]) + " " + str(key)
                    ])  # updating the undo list
                dictForDayI[key] = "0"

        files.fileUpdate(i, dictForDayI)
Ejemplo n.º 4
0
def add(userInput, categoryList, undo_steps, step_count):
    categ, sum, remainder = getCategAndValue(
        userInput)  # getting the category and the sum from the user input
    day = int(time.strftime("%d"))

    try:  # In case that the user has entered an invalid number that may contain
        sum = int(
            sum
        )  # strings and other characters other than digits and or '-', '+', etc.
        if len(
                remainder
        ) > 0 or sum < 0 or categ not in categoryList:  # In case the user has entered additional characters after the valid syntax
            return "   Invalid syntax, check sum or category"

    except ValueError:  # the program doesn't crash
        return "   Invalid sum or syntax"

    categoryDictionary = files.initializeDictionary(
        day, categoryList)  # Today's date (day)
    categoryDictionary[
        categ] += sum  # updating the sum of the selected category
    files.fileUpdate(
        int(time.strftime("%d")), categoryDictionary
    )  # updating the file for this day with the new information

    stepCountUpdate(undo_steps, sum, categ, day,
                    step_count)  #updating the undo list

    return "   Added successfully!"
Ejemplo n.º 5
0
def getSum(category, categoryList):
    '''
        This function returns the sum of all the values corresponding to each day's category
    '''
    s = 0
    for i in range(1, 32):
        auxDict = files.initializeDictionary(i, categoryList)
        s += auxDict[category]
    return s
Ejemplo n.º 6
0
def maximumExpenses(categoryList):
    '''
        This function iterates thorugh all of the files, checks the expenses and memorizes the day with the most expenses
        It returns the the maximum expense + the day of the maximum expense
    '''
    maxExp, day = 0, 0

    for i in range(1, 32):
        auxExp = getExpensesForDay(files.initializeDictionary(i, categoryList))
        maxExp, day = updateMax(maxExp, auxExp, i, day)

    return maxExp, day
Ejemplo n.º 7
0
def removeExpensesByCategory(categ, undo_steps, step_count, categoryList):
    '''
            The function removes all the expenses for a certain category from day 1 to day 31 (updates all the files with the
        default dictionary)
        input: the category
    '''
    for i in range(1, 32):
        aux_dict = files.initializeDictionary(i, categoryList)

        if aux_dict[categ] != 0:
            undo_steps.append([
                step_count, "insert " + str(i) + " " + str(aux_dict[categ]) +
                " " + str(categ)
            ])  # updating the undo list

        aux_dict[categ] = 0
        files.fileUpdate(i, aux_dict)
Ejemplo n.º 8
0
def buildListOfExpenses(categ, op, categoryList):
    '''
        This function allows for the iteration from 1 to 31
        OP1. For each day, the program calculates the expenses for that day and stores it into a list
        OP2. Calculates the expenses for each day for a specific category
        This list is sorted at the end of the function and returned
        output: The sorted list of values
    '''

    valuesDictionary = {}

    for i in range(1, 32):
        sumOfValues = 0

        dictForDay = files.initializeDictionary(i, categoryList)

        if op == 1:
            sumOfValues = getSumForDay(dictForDay)
        else:
            sumOfValues += dictForDay[categ]

        valuesDictionary[i] = sumOfValues

    return valuesDictionary