Correct an subsampling issue on Python 3

This commit is contained in:
nicolargo 2018-04-02 14:18:19 +02:00
parent 376ce7a8e9
commit 982054becd
2 changed files with 6 additions and 6 deletions

View File

@ -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))

View File

@ -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])