def get_biggest_revenue_transaction():
    transactions = sales.read_data_from_file()
    price_index = sales.HEADERS.index("Price")
    transaction_price = [
        float(transaction[price_index]) for transaction in transactions
    ]
    transaction_index = transaction_price.index(max(transaction_price))
    view.print_general_results(transactions[transaction_index],
                               "Biggest revenue transaction")
def sum_transactions_between():
    start_date, end_date = view.get_inputs(["start date", "end date"])
    transactions = sales.read_data_from_file()
    price_index = sales.HEADERS.index("Price")
    transactions_price = [
        float(element[price_index]) for element in transactions_between_dates(
            start_date, end_date, transactions)
    ]
    prices_sum = sum(transactions_price)
    view.print_general_results(
        prices_sum, f"Sum of transactions between {start_date} and {end_date}")
def count_transactions_between():
    try:
        start_date, end_date = view.get_inputs(["start date", "end date"])
        if date_correct_input(start_date) or date_correct_input(end_date):
            transactions = sales.read_data_from_file()
            view.print_general_results(
                len(
                    transactions_between_dates(start_date, end_date,
                                               transactions)),
                f"Number of transactions between {start_date} and {end_date}")
    except ValueError:
        view.print_error_message("Date in invalid format")
def get_biggest_revenue_product():
    transactions = sales.read_data_from_file()
    price_index = sales.HEADERS.index("Price")
    product_index = sales.HEADERS.index("Product")
    products_revenue = {}
    best_seller = 0

    for transaction in transactions:
        if transaction[product_index] not in products_revenue.keys():
            products_revenue[transaction[product_index]] = float(
                transaction[price_index])
        else:
            products_revenue[transaction[product_index]] += float(
                transaction[price_index])
        if best_seller < products_revenue[transaction[product_index]]:
            best_seller = products_revenue[transaction[product_index]]
            product_key = transaction[product_index]
    view.print_message(f"Product with the highest revenue: {product_key}")
def transaction_index_valid(number):
    if int(number) == 0 or int(number) > len(sales.read_data_from_file()):
        raise IndexError
    return True