projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Ran black code formatter on everything.
[python_utils.git]
/
histogram.py
diff --git
a/histogram.py
b/histogram.py
index 3391b0b3c51d33164b6d173d59a7b4a1b3c9788b..4aa47490122481852ae03e264795509a8794e54e 100644
(file)
--- a/
histogram.py
+++ b/
histogram.py
@@
-15,6
+15,7
@@
class SimpleHistogram(Generic[T]):
def __init__(self, buckets: List[Tuple[T, T]]):
from math_utils import RunningMedian
def __init__(self, buckets: List[Tuple[T, T]]):
from math_utils import RunningMedian
+
self.buckets = {}
for start_end in buckets:
if self._get_bucket(start_end[0]) is not None:
self.buckets = {}
for start_end in buckets:
if self._get_bucket(start_end[0]) is not None:
@@
-28,9
+29,9
@@
class SimpleHistogram(Generic[T]):
@staticmethod
def n_evenly_spaced_buckets(
@staticmethod
def n_evenly_spaced_buckets(
-
min_bound: T,
-
max_bound: T,
-
n: int,
+ min_bound: T,
+ max_bound: T,
+ n: int,
) -> List[Tuple[T, T]]:
ret = []
stride = int((max_bound - min_bound) / n)
) -> List[Tuple[T, T]]:
ret = []
stride = int((max_bound - min_bound) / n)
@@
-66,8
+67,7
@@
class SimpleHistogram(Generic[T]):
all_true = all_true and self.add_item(item)
return all_true
all_true = all_true and self.add_item(item)
return all_true
- def __repr__(self,
- label_formatter='%10s') -> str:
+ def __repr__(self, label_formatter='%10s') -> str:
from text_utils import bar_graph
max_population: Optional[int] = None
from text_utils import bar_graph
max_population: Optional[int] = None
@@
-82,18
+82,23
@@
class SimpleHistogram(Generic[T]):
if max_population is None:
return txt
if max_population is None:
return txt
- for bucket in sorted(self.buckets, key=lambda x
: x[0]):
+ for bucket in sorted(self.buckets, key=lambda x: x[0]):
pop = self.buckets[bucket]
start = bucket[0]
end = bucket[1]
bar = bar_graph(
(pop / max_population),
pop = self.buckets[bucket]
start = bucket[0]
end = bucket[1]
bar = bar_graph(
(pop / max_population),
- include_text = False,
- width = 58,
- left_end = "",
- right_end = "")
+ include_text=False,
+ width=58,
+ left_end="",
+ right_end="",
+ )
label = f'{label_formatter}..{label_formatter}' % (start, end)
label = f'{label_formatter}..{label_formatter}' % (start, end)
- txt += f'{label:20}: ' + bar + f"({pop/self.count*100.0:5.2f}% n={pop})\n"
+ txt += (
+ f'{label:20}: '
+ + bar
+ + f"({pop/self.count*100.0:5.2f}% n={pop})\n"
+ )
if start == last_bucket_start:
break
return txt
if start == last_bucket_start:
break
return txt