thelou1s commited on
Commit
6b4e7c6
1 Parent(s): f1f2090
Files changed (3) hide show
  1. analysis_db.py +18 -13
  2. draw_db.py +12 -3
  3. util/date_util.py +11 -0
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 read_db(db_name, tb_name='', 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
 
@@ -27,34 +27,39 @@ def read_db(db_name, tb_name='', section_id=''):
27
  format_date(section_end_date))
28
  return
29
 
30
- sql_str = ' SELECT * FROM ' + tb_name + ' WHERE section_id == ' + section_id
31
  section_cursor = conn.execute(sql_str)
32
  for section_row in section_cursor:
33
  section_id = section_row[0]
34
- _sample_id = section_row[3]
35
- _sample_end_id = section_row[6]
 
 
36
  debug_print('section_id = ', section_id, ', _sample_id = ', _sample_id, ', _sample_end_id = ',
37
  _sample_end_id)
38
 
39
  max_list = []
40
  min_list = []
41
- delta_list = []
42
- sample_sql = "SELECT max, min FROM sample_table WHERE _id >= " + str(_sample_id) + ' AND ' + ' _id <= ' + str(_sample_end_id)
43
  sample_cursor = conn.execute(sample_sql)
44
  for sample_row in sample_cursor:
45
- max = sample_row[0]
46
- min = sample_row[1]
47
- delta = max - min
 
 
48
  max_list.append(max)
49
  min_list.append(min)
50
- delta_list.append(delta)
51
 
52
  # debug_print('max_list = ', str(max_list))
53
  # debug_print('min_list = ', str(min_list))
54
- # debug_print('delta_list = ', str(delta_list))
55
  # draw(max_list)
56
- draw_two(max_list, min_list)
57
- # draw_three(max_list, min_list, delta_list)
 
58
 
59
  conn.close()
60
 
 
6
  from date_util import format_date
7
 
8
 
9
+ def read_db(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
 
 
27
  format_date(section_end_date))
28
  return
29
 
30
+ sql_str = ' SELECT section_id, _sample_id, _sample_end_id, section_date, section_end_date FROM ' + tb_name + ' WHERE section_id == ' + section_id
31
  section_cursor = conn.execute(sql_str)
32
  for section_row in section_cursor:
33
  section_id = section_row[0]
34
+ _sample_id = section_row[1]
35
+ _sample_end_id = section_row[2]
36
+ section_date = section_row[3]
37
+ section_end_date = section_row[4]
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
 
draw_db.py CHANGED
@@ -3,20 +3,29 @@ import matplotlib.pyplot as plt
3
 
4
  def draw(x_points=None, y_points=None):
5
  plt.plot(x_points)
 
 
6
  plt.show()
7
 
8
 
9
- def draw_two(x_list1=None, x_list2=None):
10
  fig, ax = plt.subplots()
11
  ax.plot(x_list1)
12
  ax.plot(x_list2)
13
  ax.legend()
 
 
 
14
  plt.show()
15
 
16
- def draw_three(x_list1=None, x_list2=None, x_list3=None):
 
17
  fig, ax = plt.subplots()
18
  ax.plot(x_list1)
19
  ax.plot(x_list2)
20
  ax.plot(x_list3)
21
  ax.legend()
22
- plt.show()
 
 
 
 
3
 
4
  def draw(x_points=None, y_points=None):
5
  plt.plot(x_points)
6
+
7
+ plt.ylim(ymin=0, ymax=120)
8
  plt.show()
9
 
10
 
11
+ def draw_two(title='', x_list1=None, x_list2=None):
12
  fig, ax = plt.subplots()
13
  ax.plot(x_list1)
14
  ax.plot(x_list2)
15
  ax.legend()
16
+
17
+ plt.ylim(ymin=0, ymax=120)
18
+ plt.title(title)
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()
util/date_util.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+
3
+
4
+ def format_date(section_date):
5
+ # 使用datetime.strptime解析原始日期字符串
6
+ date_obj = datetime.strptime(section_date, "%Y%m%d%H%M")
7
+
8
+ # 使用strftime将日期对象格式化为新的格式
9
+ formatted_date = date_obj.strftime("%Y%m%d %H:%M")
10
+
11
+ return formatted_date