def rtask_avg_proc(threshold, trend_task, window_size, task=None):
import numpy as np
data = np.empty(window_size, dtype=float)
data.fill(0.0)
cumsum = 0.0
while True:
i, n = yield task.receive()
if n is None:
break
cumsum += (n - data[0])
avg = cumsum / window_size
if avg > threshold:
trend_task.send((i, 'high', float(avg)))
elif avg < -threshold:
trend_task.send((i, 'low', float(avg)))
data = np.roll(data, -1)
data[-1] = n
raise StopIteration(0)
# This generator function is sent to remote dispycos process to save the
# received data in a file (on the remote peer).
评论列表
文章目录