Skip to content

Commit

Permalink
Revert "fix: Do not sort data and add new 'change' field into stats"
Browse files Browse the repository at this point in the history
This reverts commit ad1a9dd11875f4b799f3682f4d20d53a80b8d86d.

Actually not needed. If data are always raising, 'range' is enough
  • Loading branch information
jhutar committed Feb 15, 2024
1 parent 8e4ec9e commit 6cbe664
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 16 deletions.
4 changes: 1 addition & 3 deletions core/opl/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def percentile(data, percent):
if not data:
return None

data = sorted(data)
data.sort()
k = (len(data) - 1) * percent / 100
# Python 2.x returns float for floor an ceil, so cast to int
f = int(math.floor(k))
Expand Down Expand Up @@ -226,7 +226,6 @@ def data_stats(data):
else 0.0,
"stdev": statistics.stdev(data) if len(data) > 1 else 0.0,
"range": max(data) - min(data),
"change": data[-1] - data[0],
"percentile25": q25,
"percentile75": q75,
"percentile90": q90,
Expand All @@ -241,7 +240,6 @@ def data_stats(data):
"max": max(data),
"mean": (max(data) - min(data)) / len(data),
"range": max(data) - min(data),
"change": data[-1] - data[0],
}
else:
raise Exception(f"Do not know how to get stats for list of {type(data[0])}")
Expand Down
4 changes: 1 addition & 3 deletions opl/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def percentile(data, percent):
if not data:
return None

data = sorted(data)
data.sort()
k = (len(data) - 1) * percent / 100
# Python 2.x returns float for floor an ceil, so cast to int
f = int(math.floor(k))
Expand Down Expand Up @@ -226,7 +226,6 @@ def data_stats(data):
else 0.0,
"stdev": statistics.stdev(data) if len(data) > 1 else 0.0,
"range": max(data) - min(data),
"change": data[-1] - data[0],
"percentile25": q25,
"percentile75": q75,
"percentile90": q90,
Expand All @@ -241,7 +240,6 @@ def data_stats(data):
"max": max(data),
"mean": (max(data) - min(data)) / len(data),
"range": max(data) - min(data),
"change": data[-1] - data[0],
}
else:
raise Exception(f"Do not know how to get stats for list of {type(data[0])}")
Expand Down
10 changes: 0 additions & 10 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def test_data_stats(self):
self.assertEqual(stats["mean"], 1)
self.assertEqual(stats["max"], 2)
self.assertEqual(stats["range"], 2)
self.assertEqual(stats["change"], 0)
self.assertEqual(stats["percentile25"], 0.75)
self.assertEqual(stats["percentile75"], 1.25)
self.assertEqual(stats["iqr"], 0.5)
Expand Down Expand Up @@ -47,7 +46,6 @@ def test_data_stats_datetime(self):
datetime.datetime.fromisoformat("2021-03-22T11:00:00.000000+00:00"),
)
self.assertEqual(stats["range"].total_seconds(), 3600)
self.assertEqual(stats["change"].total_seconds(), -3600)

def test_data_stats_strange(self):
data = [
Expand Down Expand Up @@ -101,11 +99,3 @@ def test_get_rps(self):
rps_vals = opl.data.get_rps([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
self.assertEqual(len(rps_vals), 5)
self.assertEqual(sum(rps_vals) / len(rps_vals), 1.0)

def test_percentile(self):
data = [0, 1, 1, 2, 2, 1, 1, 0]
perc25 = opl.data.percentile(data, 25)
perc75 = opl.data.percentile(data, 75)
self.assertEqual(data, [0, 1, 1, 2, 2, 1, 1, 0]) # make sure data is not reordered
self.assertEqual(perc25, 0.75)
self.assertEqual(perc75, 1.25)

0 comments on commit 6cbe664

Please sign in to comment.