def decimate_custom(seq,cmp=None,pops=None,keeptime=3600*1.1):
"""
@NOTE: Although faster, filter_array does a better decimation for trends
It will remove all values from a list that doesn't provide information.
In a set of X consecutive identical values it will remove all except
the first and the last.
A custom compare method can be passed as argument
:param seq: a list of (timestamp,value) values
"""
if len(seq)<3: return seq
if len(seq[0])<2: return seq
import __builtin__
cmp = cmp or __builtin__.cmp
pops = pops if pops is not None else []
while pops: pops.pop()
x0,x1,x2 = seq[0],seq[1],seq[2]
for i in range(len(seq)-2):
if not cmp(x0[1],seq[i+1][1]) and not cmp(seq[i+1][1],seq[i+2][1]):
pops.append(i+1)
else:
x0 = seq[i+1]
for i in reversed(pops):
seq.pop(i)
return seq
评论列表
文章目录