Exemple #1
0
def avg_amount(table, year):
    """
    Calculate average (per item) profit in a given year.
    :param table: list of lists with data form account department
    :param year: find the biggest profit by year
    :return: profit = (income - outflow)/(items count)
    """
    year_by_income = [(record[4], int(record[5])) for record in table
                      if int(record[3]) == year]
    income = [wages[1] for wages in year_by_income if wages[0] == "in"]
    outflow = [wages[1] for wages in year_by_income if wages[0] == "out"]
    profit = (common.sum_values(income) -
              common.sum_values(outflow)) / len(year_by_income)

    return profit
def get_average_durability_by_manufacturers(table):
    """
    Display average durability by manufacturers
    :param table: list of all items in database
    :return: dictionary with average of durability
    """
    list_of_manufacturer = []
    companies_durability = [(record[2], record[4]) for record in table]

    for records in table:
        if records[2] not in list_of_manufacturer:
            list_of_manufacturer.append(records[2])

    list_of_durability = [[
        int(company_dur[1]) for company_dur in companies_durability
        if company == company_dur[0]
    ] for company in list_of_manufacturer]

    average_durability = [
        str(common.sum_values(num_list) / len(num_list))
        for num_list in list_of_durability
    ]

    convert_avg_dur = [
        int(float(num)) if ".0" in num else float(num)
        for num in average_durability
    ]

    dict_avg_dur = dict(zip(list_of_manufacturer, convert_avg_dur))
    return dict_avg_dur
Exemple #3
0
def get_persons_closest_to_average(table):
    """
    Find the person, which is closest to average age
    :param table: list of lists with data form hr department
    :return: list with persons, which is closet to average age
    """
    years = [int(year[2]) for year in table]
    years_avg = common.sum_values(years) / len(years)
    similar_years = min(years, key=lambda x: abs(x - years_avg))
    closest_person = [
        record[1] for record in table if int(record[2]) == similar_years
    ]
    return closest_person
Exemple #4
0
def get_total_sum_of_width_columns(table, title_list):
    """
    Calcualte total sum of width in each column.
    :param table: table: table to display - text file where are included some information.
    :param title_list: title_list: list containing table headers
    :return: Sum of width
    """
    width_columns = get_width_columns(table, title_list)
    total_column_lenght = common.sum_values(
        width_columns) + 1  # due to end in var:string "|"
    number_of_columns = len(width_columns)
    PADDINGS = 3

    total_width_sum = total_column_lenght + (number_of_columns * PADDINGS)
    return total_width_sum
Exemple #5
0
def get_average_by_manufacturer(table, manufacturer):
    """
    Display calculated average of games amount in stock for given manufacturer
    :param table: list of all items in database
    :param manufacturer: Name of manufacturer
    :return: Average of games amount in stock
    """
    ui.print_table(table, title_list)
    manufacturer_and_stock = [(record[2], record[4]) for record in table
                              if record[2] == manufacturer]
    list_of_amount_in_stock = [
        int(games[1]) for games in manufacturer_and_stock
        if games[0] == manufacturer
    ]
    avg_count = [
        common.sum_values(list_of_amount_in_stock) /
        len(list_of_amount_in_stock)
    ]
    return avg_count[0]