-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
106 lines (74 loc) · 2.42 KB
/
main.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import os
import time
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
#local files:
import messparser
import painter
now_chat_id = 0
smooth_id = -1
main_plot_mode = 1
my_name = str()
def print_time_label(text, start=None):
t = time.process_time()
if start != None:
pass
print(text, f"{t:0}")
return 0
def build_plot_grid():
global main_plot,pie_plot,list_chats_plot,fig
#layout, ax = plt.subplots(figsize=(16, 12))
layout, ax = plt.subplots()
ax.axis('off')
layout.canvas.mpl_connect('key_press_event', press)
layout.canvas.set_window_title('TgStat')
#layout = plt.figure(constrained_layout=True)
gs = layout.add_gridspec(4, 4)
main_plot = layout.add_subplot(gs[:, :-1])
main_plot.set_title('main')
pie_plot = layout.add_subplot(gs[0:2, -1:])
pie_plot.set_title('right-top')
list_chats_plot = layout.add_subplot(gs[2:, -1:])
list_chats_plot.set_title('right')
list_chats_plot.set_frame_on(False)
#layout.canvas.show(False)
#list_chats_plot.axis('on')
#list_chats_plot.axis('off')
def press(event):
global now_chat_id,smooth_id,main_plot_mode
#print('press', event.key)
#sys.stdout.flush()
key = str(event.key)
ev = 0
if key == "left" or key == "up": now_chat_id -= 1; ev = 1
if key == "right" or key == "down": now_chat_id += 1; ev = 1
if key == "[": smooth_id -= 1; ev = 2
if key == "]": smooth_id += 1; ev = 2
if key == " ":
main_plot_mode ^= 1
ev = 3
if ev != 0:
last_press_event_time = time.process_time()
draw_chat(now_chat_id, smooth_id, main_plot_mode)
print(time.process_time() - last_press_event_time)
def draw_chat(id, smooth_id, main_mode):
painter.draw_chat(
id, smooth_id, main_mode,
my_name, chat_day_data,
main_plot,pie_plot,list_chats_plot
)
def main(debug = False):
global my_name,chat_day_data
os.system('clear')
print_time_label("Time, start reading")
input_file = "result.json"
if debug:
input_file = "result_short.json"
my_name, chat_day_data = \
messparser.prepare_data(input_file, summary=False, privacy_mode=False)
print_time_label("Time, end prepare:")
build_plot_grid()
print_time_label("Time, build grid:")
draw_chat(now_chat_id, smooth_id, main_plot_mode)
plt.show()
main(debug = 0)