thelou1s commited on
Commit
f13c4bb
1 Parent(s): 6b4e7c6

save plt to file

Browse files
.doc/1171154525034119168, 2023-11-06 18:29:00, 2023-11-07 09:33:00.png ADDED
analysis_db.py CHANGED
@@ -38,28 +38,32 @@ def read_db(db_name, tb_name='tb_section', section_id=''):
38
  debug_print('section_id = ', section_id, ', _sample_id = ', _sample_id, ', _sample_end_id = ',
39
  _sample_end_id)
40
 
 
41
  max_list = []
42
  min_list = []
43
  acc_list = []
44
- sample_sql = "SELECT _id, max, min, acc_max_dx, acc_max_dy, acc_max_dz FROM sample_table WHERE _id >= " + str(_sample_id) + ' AND ' + ' _id <= ' + str(_sample_end_id)
45
  sample_cursor = conn.execute(sample_sql)
46
  for sample_row in sample_cursor:
47
  _id = sample_row[0]
48
- max = sample_row[1]
49
- min = sample_row[2]
50
- acc_max = sample_row[3] + sample_row[4] + sample_row[5]
51
- debug_print('_id = ', _id, 'sample_row[3] = ', str(sample_row[3]))
 
 
 
52
  max_list.append(max)
53
  min_list.append(min)
54
  acc_list.append(acc_max)
55
 
56
  # debug_print('max_list = ', str(max_list))
57
  # debug_print('min_list = ', str(min_list))
58
- debug_print('acc_list = ', str(acc_list))
59
  # draw(max_list)
60
  title_str = str(section_id) + ', ' + str(format_date(section_date)) + ', ' + str(format_date(section_end_date))
61
  # draw_two(title_str, max_list, min_list)
62
- draw_three(title_str, max_list, min_list, acc_list)
63
 
64
  conn.close()
65
 
 
38
  debug_print('section_id = ', section_id, ', _sample_id = ', _sample_id, ', _sample_end_id = ',
39
  _sample_end_id)
40
 
41
+ date_list = []
42
  max_list = []
43
  min_list = []
44
  acc_list = []
45
+ sample_sql = "SELECT _id, date, max, min, acc_max_dx, acc_max_dy, acc_max_dz FROM sample_table WHERE _id >= " + str(_sample_id) + ' AND ' + ' _id <= ' + str(_sample_end_id)
46
  sample_cursor = conn.execute(sample_sql)
47
  for sample_row in sample_cursor:
48
  _id = sample_row[0]
49
+ date = sample_row[1]
50
+ max = sample_row[2]
51
+ min = sample_row[3]
52
+ acc_max = sample_row[4] + sample_row[5] + sample_row[6]
53
+ debug_print('_id = ', _id, 'date = ', format_date(date))
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))
62
+ # debug_print('acc_list = ', str(acc_list))
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
 
debug.py CHANGED
@@ -1,5 +1,5 @@
1
- DEBUG = True
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,5 @@
1
  import matplotlib.pyplot as plt
 
2
 
3
 
4
  def draw(x_points=None, y_points=None):
@@ -19,13 +20,24 @@ def draw_two(title='', x_list1=None, x_list2=None):
19
  plt.show()
20
 
21
 
22
- def draw_three(title='', x_list1=None, x_list2=None, x_list3=None):
 
 
23
  fig, ax = plt.subplots()
24
- ax.plot(x_list1)
25
- ax.plot(x_list2)
26
- ax.plot(x_list3)
 
 
 
 
 
27
  ax.legend()
 
28
 
29
  plt.ylim(ymin=0, ymax=120)
30
  plt.title(title)
31
- plt.show()
 
 
 
 
1
  import matplotlib.pyplot as plt
2
+ from debug import debug_print
3
 
4
 
5
  def draw(x_points=None, y_points=None):
 
20
  plt.show()
21
 
22
 
23
+ def draw_three(title='', date_list=None, x_list1=None, x_list2=None, x_list3=None):
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(x_list1)
29
+ ax.plot(x_list2)
30
+ ax.plot(x_list3)
31
+ else:
32
+ ax.plot(date_list, x_list1)
33
+ ax.plot(date_list, x_list2)
34
+ ax.plot(date_list, x_list3)
35
  ax.legend()
36
+ plt.gcf().autofmt_xdate()
37
 
38
  plt.ylim(ymin=0, ymax=120)
39
  plt.title(title)
40
+ # plt.show()
41
+
42
+ file_uri = '.doc/' + title + '.png'
43
+ plt.savefig(file_uri)