projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add LICENSE and NOTICE.
[python_utils.git]
/
histogram.py
diff --git
a/histogram.py
b/histogram.py
index 9c07df9b588aef626ecf8217a70ac4fd9676eb9d..52a0d1fad558a493c6e303abdd07a6933053a045 100644
(file)
--- a/
histogram.py
+++ b/
histogram.py
@@
-1,6
+1,8
@@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
+# © Copyright 2021-2022, Scott Gasch
+
"""A text-based simple histogram helper class."""
import math
"""A text-based simple histogram helper class."""
import math
@@
-32,7
+34,7
@@
class SimpleHistogram(Generic[T]):
NEGATIVE_INFINITY = -math.inf
def __init__(self, buckets: List[Tuple[Bound, Bound]]):
NEGATIVE_INFINITY = -math.inf
def __init__(self, buckets: List[Tuple[Bound, Bound]]):
- from math_utils import
RunningMedia
n
+ from math_utils import
NumericPopulatio
n
self.buckets: Dict[Tuple[Bound, Bound], Count] = {}
for start_end in buckets:
self.buckets: Dict[Tuple[Bound, Bound], Count] = {}
for start_end in buckets:
@@
-40,7
+42,7
@@
class SimpleHistogram(Generic[T]):
raise Exception("Buckets overlap?!")
self.buckets[start_end] = 0
self.sigma: float = 0.0
raise Exception("Buckets overlap?!")
self.buckets[start_end] = 0
self.sigma: float = 0.0
- self.stats:
RunningMedian = RunningMedia
n()
+ self.stats:
NumericPopulation = NumericPopulatio
n()
self.maximum: Optional[T] = None
self.minimum: Optional[T] = None
self.count: Count = 0
self.maximum: Optional[T] = None
self.minimum: Optional[T] = None
self.count: Count = 0
@@
-122,9
+124,11
@@
class SimpleHistogram(Generic[T]):
)
if len(sigma_label) > details.max_label_width:
details.max_label_width = len(sigma_label)
)
if len(sigma_label) > details.max_label_width:
details.max_label_width = len(sigma_label)
- bar_width = width - (details.max_label_width + 1
6
)
+ bar_width = width - (details.max_label_width + 1
7
)
for (start, end), pop in sorted(self.buckets.items(), key=lambda x: x[0]):
for (start, end), pop in sorted(self.buckets.items(), key=lambda x: x[0]):
+ if start < details.lowest_start:
+ continue
label = f'[{label_formatter}..{label_formatter}): ' % (start, end)
bar = bar_graph(
(pop / details.max_population),
label = f'[{label_formatter}..{label_formatter}): ' % (start, end)
bar = bar_graph(
(pop / details.max_population),
@@
-141,12
+145,14
@@
class SimpleHistogram(Generic[T]):
txt += '-' * width + '\n'
txt += sigma_label.rjust(details.max_label_width)
txt += ' ' * (bar_width - 2)
txt += '-' * width + '\n'
txt += sigma_label.rjust(details.max_label_width)
txt += ' ' * (bar_width - 2)
- txt += f'Σ=(100.00% n={self.count})\n'
+ txt += f' pop(Σn)={self.count}\n'
+ txt += ' ' * (bar_width + details.max_label_width - 2)
+ txt += f' mean(x̄)={self.stats.get_mean():.3f}\n'
txt += ' ' * (bar_width + details.max_label_width - 2)
txt += ' ' * (bar_width + details.max_label_width - 2)
- txt += f'
mean(μ)={self.stats.get_me
an():.3f}\n'
+ txt += f'
median(p50)={self.stats.get_medi
an():.3f}\n'
txt += ' ' * (bar_width + details.max_label_width - 2)
txt += ' ' * (bar_width + details.max_label_width - 2)
- txt += f'
p50(η)={self.stats.get_median()
:.3f}\n'
+ txt += f'
mode(Mo)={self.stats.get_mode()[0]
:.3f}\n'
txt += ' ' * (bar_width + details.max_label_width - 2)
txt += ' ' * (bar_width + details.max_label_width - 2)
- txt += f'stdev(σ)={self.stats.get_stdev():.3f}\n'
+ txt += f'
stdev(σ)={self.stats.get_stdev():.3f}\n'
txt += '\n'
return txt
txt += '\n'
return txt