提交 982054be 编写于 作者: N nicolargo

Correct an subsampling issue on Python 3

上级 376ce7a8
......@@ -192,7 +192,7 @@ def subsample(data, sampling):
if len(data) <= sampling:
return data
sampling_length = int(round(len(data) / float(sampling)))
return [mean(data[s * sampling_length:(s + 1) * sampling_length]) for s in xrange(0, sampling)]
return [mean(data[s * sampling_length:(s + 1) * sampling_length]) for s in range(0, sampling)]
def time_serie_subsample(data, sampling):
......@@ -207,6 +207,6 @@ def time_serie_subsample(data, sampling):
t = [t[0] for t in data]
v = [t[1] for t in data]
sampling_length = int(round(len(data) / float(sampling)))
t_subsampled = [t[s * sampling_length:(s + 1) * sampling_length][0] for s in xrange(0, sampling)]
v_subsampled = [mean(v[s * sampling_length:(s + 1) * sampling_length]) for s in xrange(0, sampling)]
t_subsampled = [t[s * sampling_length:(s + 1) * sampling_length][0] for s in range(0, sampling)]
v_subsampled = [mean(v[s * sampling_length:(s + 1) * sampling_length]) for s in range(0, sampling)]
return list(zip(t_subsampled, v_subsampled))
......@@ -34,7 +34,7 @@ from glances.thresholds import GlancesThresholdWarning
from glances.thresholds import GlancesThresholdCritical
from glances.thresholds import GlancesThresholds
from glances.plugins.glances_plugin import GlancesPlugin
from glances.compat import subsample
from glances.compat import subsample, range
# Global variables
# =================
......@@ -249,8 +249,8 @@ class TestGlances(unittest.TestCase):
([1, 2, 3, 4], 4),
([1, 2, 3, 4, 5, 6, 7], 4),
([1, 2, 3, 4, 5, 6, 7, 8], 4),
(list(xrange(1, 800)), 4),
(list(xrange(1, 8000)), 800)]:
(list(range(1, 800)), 4),
(list(range(1, 8000)), 800)]:
l_subsample = subsample(l[0], l[1])
self.assertLessEqual(len(l_subsample), l[1])
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册