Merge pull request #35974 from techhat/calcminmax

Add thresholds to calc module
This commit is contained in:
Mike Place 2016-09-01 23:51:26 +09:00 committed by GitHub
commit 9ebb405a53

View File

@ -25,7 +25,7 @@ def __virtual__():
return HAS_STATS
def calc(name, num, oper, ref=None):
def calc(name, num, oper, minimum=0, maximum=0, ref=None):
'''
Perform a calculation on the ``num`` most recent values. Requires a list.
Valid values for ``oper`` are:
@ -95,6 +95,12 @@ def calc(name, num, oper, ref=None):
answer = ops[oper](vals)
if minimum > 0 and answer < minimum:
ret['result'] = False
if maximum > 0 and answer > maximum:
ret['result'] = False
ret['changes'] = {
'Number of values': len(vals),
'Operator': oper,
@ -103,7 +109,7 @@ def calc(name, num, oper, ref=None):
return ret
def add(name, num, ref=None):
def add(name, num, minimum=0, maximum=0, ref=None):
'''
Adds together the ``num`` most recent values. Requires a list.
@ -119,7 +125,7 @@ def add(name, num, ref=None):
return calc(name, num, 'add', ref)
def mul(name, num, ref=None):
def mul(name, num, minimum=0, maximum=0, ref=None):
'''
Multiplies together the ``num`` most recent values. Requires a list.
@ -135,7 +141,7 @@ def mul(name, num, ref=None):
return calc(name, num, 'mul', ref)
def mean(name, num, ref=None):
def mean(name, num, minimum=0, maximum=0, ref=None):
'''
Calculates the mean of the ``num`` most recent values. Requires a list.
@ -151,7 +157,7 @@ def mean(name, num, ref=None):
return calc(name, num, 'mean', ref)
def median(name, num, ref=None):
def median(name, num, minimum=0, maximum=0, ref=None):
'''
Calculates the mean of the ``num`` most recent values. Requires a list.
@ -167,7 +173,7 @@ def median(name, num, ref=None):
return calc(name, num, 'median', ref)
def median_low(name, num, ref=None):
def median_low(name, num, minimum=0, maximum=0, ref=None):
'''
Calculates the low mean of the ``num`` most recent values. Requires a list.
@ -183,7 +189,7 @@ def median_low(name, num, ref=None):
return calc(name, num, 'median_low', ref)
def median_high(name, num, ref=None):
def median_high(name, num, minimum=0, maximum=0, ref=None):
'''
Calculates the high mean of the ``num`` most recent values. Requires a list.
@ -199,7 +205,7 @@ def median_high(name, num, ref=None):
return calc(name, num, 'median_high', ref)
def median_grouped(name, num, ref=None):
def median_grouped(name, num, minimum=0, maximum=0, ref=None):
'''
Calculates the grouped mean of the ``num`` most recent values. Requires a
list.
@ -216,7 +222,7 @@ def median_grouped(name, num, ref=None):
return calc(name, num, 'median_grouped', ref)
def mode(name, num, ref=None):
def mode(name, num, minimum=0, maximum=0, ref=None):
'''
Calculates the mode of the ``num`` most recent values. Requires a list.