-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterm_plot.py
More file actions
72 lines (55 loc) · 2.12 KB
/
Copy pathterm_plot.py
File metadata and controls
72 lines (55 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import math
class BarChart:
char_tl = "╒"
char_bl = "╘"
char_tr = "╕"
char_br = "╛"
char_top_cross = "╤" # cross
char_cross = "┼"
char_bottom_cross = "╧"
char_horizontal_double = "═"
char_horizontal_single = "─"
char_vetrtical = "│"
char_cross_left = "├"
char_cross_right = "┤"
def __init__(self, values, header=None, name=None, width_bar=80):
self._values = values
self._header = header
self._name = name
self._width_bar = width_bar
def _add_separator_line(self, arr_width, first=False, last=False):
# they can't be true together
assert((first and last) == False)
if first:
b = BarChart.char_tl
m = BarChart.char_top_cross
e = BarChart.char_tr
hor = BarChart.char_horizontal_double
elif last:
b = BarChart.char_bl
m = BarChart.char_bottom_cross
e = BarChart.char_br
hor = BarChart.char_horizontal_double
else:
b = BarChart.char_cross_left
m = BarChart.char_cross
e = BarChart.char_cross_right
hor = BarChart.char_horizontal_single
line = b
for i in range(len(arr_width)):
line += hor * arr_width[i] + (m if i != len(arr_width) - 1 else e)
return line + "\n"
def plot(self):
k = max(self._values)
leng_header = max([len(s) for s in self._header])
result = self._name + "\n"
result += self._add_separator_line([leng_header, self._width_bar], first=True)
for i in range(len(self._header)):
result += BarChart.char_vetrtical
result += ("{:" + str(leng_header) + "}").format(self._header[i])
result += BarChart.char_vetrtical
result += ("{:" + str(self._width_bar) + "}").format("\u25AE" * math.ceil(self._values[i] / k * 80))
result += BarChart.char_vetrtical
result += "\n"
result += self._add_separator_line([leng_header, self._width_bar], last=(i == len(self._header) - 1))
return result