summaryrefslogtreecommitdiff
path: root/histogram.py
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2021-07-28 22:13:43 -0700
committerScott Gasch <[email protected]>2021-07-28 22:13:43 -0700
commit4faa994d32223c8d560d9dad0ca90a3f7eb10d6a (patch)
tree1200e5615d94247a120b98a4ddceb2cd6674e0af /histogram.py
parentc79ecbf708a63a54a9c3e8d189b65d4794930082 (diff)
Money, Rate, CentCount and a bunch of bugfixes.
Diffstat (limited to 'histogram.py')
-rw-r--r--histogram.py15
1 files changed, 5 insertions, 10 deletions
diff --git a/histogram.py b/histogram.py
index b98e848..0368376 100644
--- a/histogram.py
+++ b/histogram.py
@@ -66,7 +66,8 @@ class SimpleHistogram(Generic[T]):
all_true = all_true and self.add_item(item)
return all_true
- def __repr__(self) -> str:
+ def __repr__(self,
+ label_formatter='%10s') -> str:
from text_utils import bar_graph
max_population: Optional[int] = None
for bucket in self.buckets:
@@ -86,17 +87,11 @@ class SimpleHistogram(Generic[T]):
bar = bar_graph(
(pop / max_population),
include_text = False,
- width = 70,
+ width = 58,
left_end = "",
right_end = "")
- label = f'{start}..{end}'
- txt += f'{label:12}: ' + bar + f"({pop}) ({len(bar)})\n"
+ label = f'{label_formatter}..{label_formatter}' % (start, end)
+ txt += f'{label:20}: ' + bar + f"({pop/self.count*100.0:5.2f}% n={pop})\n"
if start == last_bucket_start:
break
-
- txt = txt + f'''{self.count} item(s)
-{self.maximum} max
-{self.minimum} min
-{self.sigma/self.count:.3f} mean
-{self.median.get_median()} median'''
return txt