summaryrefslogtreecommitdiff
path: root/histogram.py
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2022-02-10 08:13:08 -0800
committerScott Gasch <[email protected]>2022-02-10 08:13:08 -0800
commita4b50bb62e2653d3d084c6c7e0574abb9277b8d7 (patch)
treef9c8d2c33adae7b52cea42b63d47018d134e9e5f /histogram.py
parentc974b8cde11f133df7680967b759772c624007e9 (diff)
Add some useful stats to histogram.
Diffstat (limited to 'histogram.py')
-rw-r--r--histogram.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/histogram.py b/histogram.py
index 2657c0b..9c07df9 100644
--- a/histogram.py
+++ b/histogram.py
@@ -40,7 +40,7 @@ class SimpleHistogram(Generic[T]):
raise Exception("Buckets overlap?!")
self.buckets[start_end] = 0
self.sigma: float = 0.0
- self.median: RunningMedian = RunningMedian()
+ self.stats: RunningMedian = RunningMedian()
self.maximum: Optional[T] = None
self.minimum: Optional[T] = None
self.count: Count = 0
@@ -74,7 +74,7 @@ class SimpleHistogram(Generic[T]):
self.count += 1
self.buckets[bucket] += 1
self.sigma += item
- self.median.add_number(item)
+ self.stats.add_number(item)
if self.maximum is None or item > self.maximum:
self.maximum = item
if self.minimum is None or item < self.minimum:
@@ -142,4 +142,11 @@ class SimpleHistogram(Generic[T]):
txt += sigma_label.rjust(details.max_label_width)
txt += ' ' * (bar_width - 2)
txt += f'Σ=(100.00% n={self.count})\n'
+ txt += ' ' * (bar_width + details.max_label_width - 2)
+ txt += f'mean(μ)={self.stats.get_mean():.3f}\n'
+ txt += ' ' * (bar_width + details.max_label_width - 2)
+ txt += f'p50(η)={self.stats.get_median():.3f}\n'
+ txt += ' ' * (bar_width + details.max_label_width - 2)
+ txt += f'stdev(σ)={self.stats.get_stdev():.3f}\n'
+ txt += '\n'
return txt