From 86a2c4db0e6f37da7d7e8ffcc2d06f4ea1ca67fd Mon Sep 17 00:00:00 2001 From: Mohsen Yousefian Date: Wed, 20 Nov 2024 00:51:54 -0600 Subject: [PATCH] Refactor data flattening in BenchmarkStats Add __flatten_to_array method Simplify data handling logic Update version to 0.1.22 Ensure newline consistency --- cmdbench/utils.py | 18 +++++++++++++++--- pyproject.toml | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cmdbench/utils.py b/cmdbench/utils.py index 68e8047..9cabec9 100644 --- a/cmdbench/utils.py +++ b/cmdbench/utils.py @@ -63,9 +63,9 @@ def get_dict_value_converted(value): class BenchmarkStats: def __init__(self, data): mean_val = sd_val = min_val = max_val = None - + # Convert to numpy array and flatten - data = np.array(data).flatten() + data = self.__flatten_to_array(data) if type(data) is np.ndarray: if len(data) > 0: @@ -76,6 +76,18 @@ def __init__(self, data): self.data = data self.mean, self.stdev, self.min, self.max = mean_val, sd_val, min_val, max_val + + def __flatten_to_array(self, items): + flat_list = [] + for item in items: + if isinstance(item, np.ndarray): + flat_list.extend(item.flatten()) + elif isinstance(item, (list, tuple)): + flat_list.extend(self.__flatten_to_array(item)) + else: + flat_list.append(item) + return np.array(flat_list) + def __repr__(self): return "(mean: %(mean)s, stdev: %(stdev)s, min: %(min)s, max: %(max)s)" % { "mean": self.mean, "stdev": self.stdev, @@ -128,4 +140,4 @@ def get_sec(time_str): time_tokens.reverse() for token_ind, time_token in enumerate(time_tokens): secs += int(time_token) * 60 ** token_ind - return secs + time_decimal \ No newline at end of file + return secs + time_decimal diff --git a/pyproject.toml b/pyproject.toml index ee49185..8afd58c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cmdbench" -version = "0.1.21" +version = "0.1.22" description = "Quick and easy benchmarking for any command's CPU, memory, disk usage and runtime." authors = ["Mohsen Yousefian "] license = "MIT"