Exemplo n.º 1
0
def filterCommandController(listOfApartments, command):
    '''
    Function that controls the command based fileter part
    :return: none
    '''
    if len(command) == 1 and convertFromRoToEng(command[0]) in typeOfCosts:
        filterAp(listOfApartments, convertFromRoToEng(command[0]))
    elif len(command) == 1 and int(command[0]):
        filterApSum(listOfApartments, int(command[0]))
Exemplo n.º 2
0
def readStr(text):
    while True:
        try:
            string = str(input(text))
            if string.isalpha() and convertFromRoToEng(string) != 'invalid':
                return convertFromRoToEng(string)
            raise ValueError
        except ValueError:
            print("Valoare invalida, incercati din nou... ")
Exemplo n.º 3
0
def testConvertFromRoToEn():
    '''
    Function to test the function convertFromRoToEng
    Takes no arguments
    Doesn't return anythinh
    '''
    assert convertFromRoToEng('Apa') == 'water'
    assert convertFromRoToEng('INCALZIRE') == 'heating'
    assert convertFromRoToEng('AlTeLe') == 'others'
    assert convertFromRoToEng('') == 'invalid'
    assert convertFromRoToEng('CANALIZARE') == 'sewerage'
Exemplo n.º 4
0
def deleteCommandController(listOfApartments, command, newBackUpList):
    '''
    Function that controls the delete part of the aplication
    :param listOfApartments:
    :param command:
    :return:
    '''
    makeBackUp(listOfApartments, newBackUpList)
    if len(command) > 1 and command[1] == ',':
        try:
            if len(command) != 3:
                raise ValueError("Comanda trebuie sa fie valida!")
            startIndex = int(command[0])
            endIndex = int(command[2])
            if startIndex > endIndex:
                startIndex, endIndex = endIndex, startIndex
            deleteFromAtoB(listOfApartments, startIndex - 1, endIndex)
        except IndexError:
            print("startIndex si stopIndex trebuie sa fie numere intregi pozitive!!")
        except ValueError:
            print("startIndex si stopIndex trebuie sa fie numere intregi pozitive!!")

    elif len(command) > 1 and command[0] == 'de' and command[1] == 'la':
        try:
            if len(command) != 4:
                raise ValueError("Comanda trebuie sa fie Valida!")
            index = int(command[2])
            day = int(command[3])
            deleteApartmentCost(listOfApartments, index - 1, day)
        except ValueError:
            print("Indexul trebuie sa fie un numar intreg pozitiv")
        except IndexError:
            print("Indexul este prea mare sau negativ!")
    elif len(command) != 0 and convertFromRoToEng(command[0]) in typeOfCosts:
        try:
            if not convertFromRoToEng(command[0]) in typeOfCosts:
                raise KeyError("Tip de cost invalid")
            type = convertFromRoToEng(command[0])
            day = int(command[1])
            deleteCostFromAll(listOfApartments, type, day)
        except KeyError as msg:
            print(msg)
    else:
        print("Comanda invalida!!!")
Exemplo n.º 5
0
def viewCommandController(listOfApartments, command):
    '''
    Function for views
    :param listOfApartments:
    :param command:
    :return:
    '''
    if len(command) == 1 and convertFromRoToEng(command[0]) in typeOfCosts:
        type = convertFromRoToEng(command[0])
        totalSum = totalSumForCost(listOfApartments, type)
        print("Suma totala pentru ", convertFromEnToRo(totalSum[0]), " este ", totalSum[1])
    elif len(command) == 1:
        try:
            index = int(command[0])
            printCost(listOfApartments, index - 1)
        except ValueError:
            print("Indexul trebuie sa fie un numar intreg pozitiv!!")
        except IndexError:
            print("Indexul trebuie sa fie un numar intreg pozitiv!!")

    else:
        print("Comanda invalida!!!")
Exemplo n.º 6
0
def listCommandController(listOfApartments, command):
    '''
    Function that prints the sorted list of apartments
    :param listOfApartments:
    :param command:
    :return:
    '''
    try:
        if len(command) != 2:
            raise IndexError("Comanda nu este valida!!")
        costType = convertFromRoToEng(command[1])
        if not costType in typeOfCosts: raise KeyError("Tipul Costului trebuie sa fie valid")
        printSortedAfterType(listOfApartments, costType)
    except KeyError as msg:
        print(msg)
    except IndexError as ex:
        print(ex)
Exemplo n.º 7
0
def printsCommandController(listOfApartments, command):
    '''
    Function that controls the user prints
    :param listOfApartments:
    :param command:
    :return:
    '''

    if command[0] == '>':
        try:
            if len(command) != 2:
                raise ValueError("Comanda trebuie sa fie valida!")
            sum = int(command[1])
            printCostLargerThanSum(costsLargerThanSum(listOfApartments, sum), sum)
        except ValueError as msg:
            print(msg)
    elif command[0] == 'toate':
        try:
            if len(command) != 2:
                raise ValueError("Comanda trebuie sa fie valida!!")
            type = convertFromRoToEng(command[1])
            if not type in typeOfCosts:
                raise KeyError("Tipul costului trebuie sa fie valid!")
            printCostTypeFromAll(costTypeFromAll(listOfApartments, type), type)
        except KeyError as msg:
            print(msg)
        except ValueError as ex:
            print(ex)
    elif len(command) > 2 and command[0] == '<' and command[2] == '>':
        try:
            if len(command) != 4:
                raise ValueError("Comanda trebuie sa fie valida!")
            day = int(command[1])
            sum = int(command[3])
            costBeforDay(listOfApartments, day, sum)
        except ValueError as msg:
            print(msg)
    else:
        print("Comanda invalida!!!")
Exemplo n.º 8
0
def modifyCommandController(listOfApartments, command):
    '''
    Function that modifies costs
    :param listOfApartments:
    :param command:
    :return:
    '''
    try:
        if len(command) != 4:
            raise ValueError("Comanda gresita!!!")
        index = int(command[0])
        sumCost = int(command[1])
        costType = convertFromRoToEng(command[2])
        if not costType in typeOfCosts:
            raise KeyError("Tipul costului trebuie sa fie valid!")
        day = int(command[3])
        modifyApartmentCost(listOfApartments, index - 1, sumCost, costType, day)
    except ValueError as msg:
        print(msg)
    except IndexError:
        print("Indexul trebuie sa fie numar intreg pozitiv")
    except KeyError as ex:
        print(ex)
Exemplo n.º 9
0
def addCommandController(listOfApartments, command, newBackUpList):
    '''
    Function that controls adding cost part
    :param listOfApartments:
    :param command:
    :return:
    '''
    makeBackUp(listOfApartments, newBackUpList)
    try:
        if len(command) != 4: raise ValueError("Indexul trebuie sa fie un numar intreg pozitiv!!!")
        index = int(command[0])
        sumCost = int(command[1])
        costType = convertFromRoToEng(command[2])
        if costType not in typeOfCosts:
            raise KeyError("Tipul costului trebuie sa fie valid!!")
        day = int(command[3])
        addToCost(listOfApartments, index - 1, sumCost, costType, day)
    except ValueError as msg:
        print(msg)
    except IndexError:
        print("Indexul trebuie sa fie un numar intreg pozitiv!!")
    except KeyError as ex:
        print(ex)