Esempio n. 1
0
def xl_max(*args):
    """
    Returns the largest value in a set of values.

    :param args: items to find the largest number in.
    :return: largest number.

    .. remarks::

        * Arguments can either be numbers or names, arrays, or references that contain numbers.
        * Logical values and text representations of numbers that you type directly into the list
        of arguments are counted.
        * If an argument is an array or reference, only numbers in that array or reference are used.
        Empty cells, logical values, or text in the array or reference are ignored.
        * If the arguments contain no numbers, MAX returns 0 (zero).
        * Arguments that are error values or text that cannot be translated into numbers cause errors.
        * If you want to include logical values and text representations of numbers in a reference as
        part of the calculation, use the MAXA function.

    """

    # ignore non-numeric cells
    data = [x for x in flatten(args) if is_number(x)]
    # data = [x for x in flatten(args) if is_number(x, number_types)]

    # however, if no non numeric cells, return zero (is what excel does)
    if len(data) < 1:
        return 0
    else:
        return max(data)
Esempio n. 2
0
def xl_sum(*args):
    # ignore non numeric cells
    data = [x for x in flatten(args) if isinstance(x, number_types)]

    # however, if no non numeric cells, return zero (is what excel does)
    if len(data) < 1:
        return 0
    else:
        return sum(data)
Esempio n. 3
0
def xl_log(number, base=10):
    """
    Returns the logarithm of a number to the base you specify.

    :param number: Required. The positive real number for which you want the logarithm.
    :param base: Optional. The base of the logarithm. If base is omitted, it is assumed to be 10.
    :return: the logarithm of the number.

    """

    if isinstance(number, list_types):
        return [math.log(item, base) for item in flatten(number)]
    else:
        return math.log(number, base)
Esempio n. 4
0
def ln(number):
    """
    Returns the natural logarithm of a number.
    Natural logarithms are based on the constant e (2.71828182845904).

    :param number: Required. The positive real number for which you want the natural logarithm.
    :return: the natural logarithm of the number.

    """

    if isinstance(number, list_types):
        return [math.log(x) for x in flatten(number)]
    else:
        return math.log(number)
Esempio n. 5
0
def average(*args):
    l = list(flatten(*args))
    return sum(l) / len(l)