コード例 #1
0
def UI_list_total_expense(building, condition, ammount):
    '''
        Lists all the apartments which obey the specified condition
    '''
    ap_ids = []
    if condition == "=":
        for ap in building:
            if apartment_total_expense(building,
                                       get_apartment_id(ap)) == ammount:
                if not get_apartment_id(ap) in ap_ids:
                    ap_ids.append(get_apartment_id(ap))
    elif condition == "<":
        for ap in building:
            if apartment_total_expense(building,
                                       get_apartment_id(ap)) < ammount:
                if not get_apartment_id(ap) in ap_ids:
                    ap_ids.append(get_apartment_id(ap))
    else:
        for ap in building:
            if apartment_total_expense(building,
                                       get_apartment_id(ap)) > ammount:
                if not get_apartment_id(ap) in ap_ids:
                    ap_ids.append(get_apartment_id(ap))
    if len(ap_ids) == 0:
        print("There are no apartments coresponding to this condition.")
    else:
        print("The apartments that are coresponding to the given condition:")
        print(ap_ids)
コード例 #2
0
def replace_expense(building, apartment):
    '''
        Replaces an existing expense ammount for one apartment
        Input: building - list of expenses, apartment - dictionary entry
        Output: Replaces the requested expense of the specified apartment with the new value
    '''
    for ap in building:
        if get_apartment_id(ap) == get_apartment_id(apartment):
            if get_expense_type(ap) == get_expense_type(apartment):
                set_ammount(ap, get_ammount(apartment))
                break
コード例 #3
0
def apartment_exists(building, apartment_id):
    '''
        Check if a specific aparment has expenses registered in the list
    '''
    ap_is = False
    for ap in building:
        if get_apartment_id(ap) == apartment_id:
            ap_is = True
    return ap_is
コード例 #4
0
def remove_apartment(building, apartment_id):
    '''
        Removes a specified apartment from the list
        Input: building - list of expenses, apartment_id - integer
        Output: removes all the entries having the given ID
    '''
    building[:] = [
        ap for ap in building if get_apartment_id(ap) != apartment_id
    ]
コード例 #5
0
def find_by_id(building, apartment_id):
    '''
        Returns a list of expenses for a given aparment id or returns none if the id is not found
        Input: building - list of expenses, apartment_id - integer
        Output: list of expenses for the given apartment id
                None - if the id is not found
    '''
    l = [ap for ap in building if get_apartment_id(ap) == apartment_id]
    return None if len(l) == 0 else l[0]
コード例 #6
0
def remove_apartments_inrange(building, start_ap, end_ap):
    '''
        Removes apartments which id's are in between start_ap and end_ap
        Input: building - list of expenses, start and end apartments - integers
        Output: Removes apartments in range start-end
    '''
    building[:] = [
        ap for ap in building
        if not get_apartment_id(ap) in range(start_ap + 1, end_ap)
    ]
コード例 #7
0
def apartment_total_expense(building, apartment_id):
    '''
        Returns the total expenses for a given apartment
        Input: building - list of expenses, aparment_id - integer
        Output: Sum of expenses for the given apartment
    '''
    total_expense = 0
    for ap in building:
        if get_apartment_id(ap) == apartment_id:
            total_expense += get_ammount(ap)
    return total_expense
コード例 #8
0
def UI_list_apartment_all(building, apartment_id):
    '''
        Lists all the expenses for a specified apartment
    '''
    id_not_found = True
    for ap in building:
        if get_apartment_id(ap) == apartment_id:
            UI_print_apartment(ap)
            id_not_found = False
    if id_not_found:
        print("There are no expenses for this apartment")
コード例 #9
0
def validate_apartment(apartment):
    """Validate an apartment entity.
    
    Arguments:
        student - which has an apartment_id:int, expense_type:string, ammount:int
    Returns: -
    Exceptions:
        Exception - if the apartment is not valid, i.e., ammount has to be greater than 0
    """
    if get_apartment_id(apartment) < 1:
        raise Exception("Apartment id has to be greater or equal to 1")
    if get_ammount(apartment) < 1:
        raise Exception("The ammount of expense has to be greater than 0")
コード例 #10
0
def total_apartment_expense_list(building, apartment_id):
    '''
        Returns the total for each expense type for a given apartment
        Input: building - list of expense, apartment_id - integer
        Output: a list of total costs of each expense
    '''
    l = [0, 0, 0, 0, 0]
    for ap in building:
        if get_apartment_id(ap) == apartment_id:
            if get_expense_type(ap) == "gas":
                l[0] += get_ammount(ap)
            if get_expense_type(ap) == "water":
                l[1] += get_ammount(ap)
            if get_expense_type(ap) == "heating":
                l[2] += get_ammount(ap)
            if get_expense_type(ap) == "electricity":
                l[3] += get_ammount(ap)
            if get_expense_type(ap) == "other":
                l[4] = +get_ammount(ap)
    return l
コード例 #11
0
def test_set_apartment_id():
    apartment = create_apartment(1, "gas", 200)
    set_apartment_id(apartment, 3)
    assert (get_apartment_id(apartment) == 3)
コード例 #12
0
def test_get_apartment_id():
    apartment = create_apartment(1, "gas", 200)
    assert (get_apartment_id(apartment) == 1)