Spaces:
Sleeping
Sleeping
draw screen_list with up_down_list
Browse files
.doc/{1171154525034119168, 2023-11-06 18:29:00, 2023-11-07 09:33:00.png → wll-11-06/1171154525034119168, 2023-11-06 18:29:00, 2023-11-07 09:33:00.png}
RENAMED
File without changes
|
.gitignore
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
/.idea
|
|
|
2 |
/__pycache__
|
|
|
1 |
/.idea
|
2 |
+
/.doc
|
3 |
/__pycache__
|
analysis_db.py
CHANGED
@@ -6,7 +6,7 @@ from draw_db import draw, draw_two, draw_three
|
|
6 |
from date_util import format_date
|
7 |
|
8 |
|
9 |
-
def
|
10 |
debug_print('read_db, db_name = ', db_name, ', tb_name = ', tb_name, ', section_id = ', section_id)
|
11 |
conn = sqlite3.connect(db_name)
|
12 |
|
@@ -25,9 +25,15 @@ def read_db(db_name, tb_name='tb_section', section_id=''):
|
|
25 |
section_end_date = section_row[2]
|
26 |
print('section_id = ', section_id, ', section_date = ', format_date(section_date), ', section_end_date = ',
|
27 |
format_date(section_end_date))
|
28 |
-
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
|
|
|
|
|
31 |
section_cursor = conn.execute(sql_str)
|
32 |
for section_row in section_cursor:
|
33 |
section_id = section_row[0]
|
@@ -42,7 +48,10 @@ def read_db(db_name, tb_name='tb_section', section_id=''):
|
|
42 |
max_list = []
|
43 |
min_list = []
|
44 |
acc_list = []
|
45 |
-
|
|
|
|
|
|
|
46 |
sample_cursor = conn.execute(sample_sql)
|
47 |
for sample_row in sample_cursor:
|
48 |
_id = sample_row[0]
|
@@ -50,12 +59,16 @@ def read_db(db_name, tb_name='tb_section', section_id=''):
|
|
50 |
max = sample_row[2]
|
51 |
min = sample_row[3]
|
52 |
acc_max = sample_row[4] + sample_row[5] + sample_row[6]
|
53 |
-
|
|
|
|
|
54 |
|
55 |
date_list.append(format_date(date))
|
56 |
max_list.append(max)
|
57 |
min_list.append(min)
|
58 |
acc_list.append(acc_max)
|
|
|
|
|
59 |
|
60 |
# debug_print('max_list = ', str(max_list))
|
61 |
# debug_print('min_list = ', str(min_list))
|
@@ -63,9 +76,7 @@ def read_db(db_name, tb_name='tb_section', section_id=''):
|
|
63 |
# draw(max_list)
|
64 |
title_str = str(section_id) + ', ' + str(format_date(section_date)) + ', ' + str(format_date(section_end_date))
|
65 |
# draw_two(title_str, max_list, min_list)
|
66 |
-
draw_three(title_str, date_list, max_list, min_list, acc_list)
|
67 |
-
|
68 |
-
conn.close()
|
69 |
|
70 |
|
71 |
if __name__ == '__main__':
|
@@ -80,4 +91,4 @@ if __name__ == '__main__':
|
|
80 |
db_uri = argv[0] if argc >= 1 else ''
|
81 |
tb_name = argv[1] if argc >= 2 else ''
|
82 |
section_id = argv[2] if argc >= 3 else ''
|
83 |
-
|
|
|
6 |
from date_util import format_date
|
7 |
|
8 |
|
9 |
+
def read_section(db_name, tb_name='tb_section', section_id=''):
|
10 |
debug_print('read_db, db_name = ', db_name, ', tb_name = ', tb_name, ', section_id = ', section_id)
|
11 |
conn = sqlite3.connect(db_name)
|
12 |
|
|
|
25 |
section_end_date = section_row[2]
|
26 |
print('section_id = ', section_id, ', section_date = ', format_date(section_date), ', section_end_date = ',
|
27 |
format_date(section_end_date))
|
28 |
+
read_sample(conn, section_id, tb_name)
|
29 |
+
else:
|
30 |
+
read_sample(conn, section_id, tb_name)
|
31 |
+
|
32 |
+
conn.close()
|
33 |
|
34 |
+
|
35 |
+
def read_sample(conn, section_id, tb_name):
|
36 |
+
sql_str = ' SELECT section_id, _sample_id, _sample_end_id, section_date, section_end_date FROM ' + str(tb_name) + ' WHERE section_id == ' + str(section_id)
|
37 |
section_cursor = conn.execute(sql_str)
|
38 |
for section_row in section_cursor:
|
39 |
section_id = section_row[0]
|
|
|
48 |
max_list = []
|
49 |
min_list = []
|
50 |
acc_list = []
|
51 |
+
light_list = []
|
52 |
+
screen_list = []
|
53 |
+
sample_sql = "SELECT _id, date, max, min, acc_max_dx, acc_max_dy, acc_max_dz, avg, max_snoring FROM sample_table WHERE _id >= " + str(
|
54 |
+
_sample_id) + ' AND ' + ' _id <= ' + str(_sample_end_id)
|
55 |
sample_cursor = conn.execute(sample_sql)
|
56 |
for sample_row in sample_cursor:
|
57 |
_id = sample_row[0]
|
|
|
59 |
max = sample_row[2]
|
60 |
min = sample_row[3]
|
61 |
acc_max = sample_row[4] + sample_row[5] + sample_row[6]
|
62 |
+
light = sample_row[7]
|
63 |
+
screen = sample_row[8]
|
64 |
+
debug_print('_id = ', _id, 'date = ', format_date(date))
|
65 |
|
66 |
date_list.append(format_date(date))
|
67 |
max_list.append(max)
|
68 |
min_list.append(min)
|
69 |
acc_list.append(acc_max)
|
70 |
+
light_list.append(light)
|
71 |
+
screen_list.append(screen)
|
72 |
|
73 |
# debug_print('max_list = ', str(max_list))
|
74 |
# debug_print('min_list = ', str(min_list))
|
|
|
76 |
# draw(max_list)
|
77 |
title_str = str(section_id) + ', ' + str(format_date(section_date)) + ', ' + str(format_date(section_end_date))
|
78 |
# draw_two(title_str, max_list, min_list)
|
79 |
+
draw_three(title_str, date_list, max_list, min_list, acc_list, light_list, screen_list)
|
|
|
|
|
80 |
|
81 |
|
82 |
if __name__ == '__main__':
|
|
|
91 |
db_uri = argv[0] if argc >= 1 else ''
|
92 |
tb_name = argv[1] if argc >= 2 else ''
|
93 |
section_id = argv[2] if argc >= 3 else ''
|
94 |
+
read_section(db_uri, tb_name, section_id)
|
debug.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
|
2 |
-
DEBUG = False
|
3 |
|
4 |
|
5 |
def debug_print(self, *args, sep=' ', end='\n', file=None):
|
|
|
1 |
+
DEBUG = True
|
2 |
+
# DEBUG = False
|
3 |
|
4 |
|
5 |
def debug_print(self, *args, sep=' ', end='\n', file=None):
|
draw_db.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
import matplotlib.pyplot as plt
|
|
|
|
|
2 |
from debug import debug_print
|
3 |
|
4 |
|
@@ -20,24 +22,41 @@ def draw_two(title='', x_list1=None, x_list2=None):
|
|
20 |
plt.show()
|
21 |
|
22 |
|
23 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
debug_print('draw_three, date_list = ', str(date_list))
|
25 |
|
|
|
|
|
|
|
|
|
|
|
26 |
fig, ax = plt.subplots()
|
27 |
if date_list is None:
|
28 |
-
ax.plot(
|
29 |
-
ax.plot(
|
30 |
-
ax.plot(
|
|
|
|
|
31 |
else:
|
32 |
-
ax.plot(date_list,
|
33 |
-
ax.plot(date_list,
|
34 |
-
ax.plot(date_list,
|
|
|
|
|
35 |
ax.legend()
|
36 |
plt.gcf().autofmt_xdate()
|
37 |
|
38 |
-
plt.ylim(ymin
|
39 |
plt.title(title)
|
40 |
-
# plt.show()
|
41 |
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
1 |
import matplotlib.pyplot as plt
|
2 |
+
|
3 |
+
import debug
|
4 |
from debug import debug_print
|
5 |
|
6 |
|
|
|
22 |
plt.show()
|
23 |
|
24 |
|
25 |
+
def up_down_list(list):
|
26 |
+
min_value = min(list)
|
27 |
+
max_value = max(list)
|
28 |
+
return [-(x - min_value) + max_value for x in list]
|
29 |
+
|
30 |
+
|
31 |
+
def draw_three(title='', date_list=None, x_list1=None, x_list2=None, x_list3=None, light_list=None, screen_list=None):
|
32 |
debug_print('draw_three, date_list = ', str(date_list))
|
33 |
|
34 |
+
if screen_list is not None:
|
35 |
+
screen_list = [(x - 2) * 4 for x in screen_list]
|
36 |
+
screen_list = up_down_list(screen_list)
|
37 |
+
# screen_list = map(lambda x: (x - 2) * 4, screen_list)
|
38 |
+
|
39 |
fig, ax = plt.subplots()
|
40 |
if date_list is None:
|
41 |
+
ax.plot(screen_list, label='screen', color='darkgrey')
|
42 |
+
ax.plot(light_list, label='light', color='lightgrey')
|
43 |
+
ax.plot(x_list1, label='max', color='blue')
|
44 |
+
ax.plot(x_list2, label='min', color='orange')
|
45 |
+
ax.plot(x_list3, label='acc', color='green')
|
46 |
else:
|
47 |
+
ax.plot(date_list, screen_list, label='screen', color='darkgrey')
|
48 |
+
ax.plot(date_list, light_list, label='light', color='lightgrey')
|
49 |
+
ax.plot(date_list, x_list1, label='max', color='blue')
|
50 |
+
ax.plot(date_list, x_list2, label='min', color='orange')
|
51 |
+
ax.plot(date_list, x_list3, label='acc', color='green')
|
52 |
ax.legend()
|
53 |
plt.gcf().autofmt_xdate()
|
54 |
|
55 |
+
plt.ylim(ymin=-10, ymax=130)
|
56 |
plt.title(title)
|
|
|
57 |
|
58 |
+
if debug.DEBUG:
|
59 |
+
plt.show()
|
60 |
+
else:
|
61 |
+
file_uri = '.doc/' + title + '.png'
|
62 |
+
plt.savefig(file_uri)
|