thelou1s commited on
Commit
5dedebd
1 Parent(s): 1d5a710

clean code

Browse files
analysis_db.py CHANGED
@@ -1,9 +1,9 @@
1
  import sqlite3
2
  import sys
3
 
4
- from debug import debug_print
5
- from draw_db import draw, draw_two, draw_three
6
- from date_util import format_date
7
 
8
 
9
  def read_section(db_name, tb_name='tb_section', section_id=''):
@@ -33,7 +33,8 @@ def read_section(db_name, tb_name='tb_section', section_id=''):
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]
@@ -56,27 +57,26 @@ def read_sample(conn, section_id, tb_name):
56
  for sample_row in sample_cursor:
57
  _id = sample_row[0]
58
  date = sample_row[1]
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))
75
- # debug_print('acc_list = ', str(acc_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__':
 
1
  import sqlite3
2
  import sys
3
 
4
+ from util.debug import debug_print
5
+ from draw_db import draw_lists, min_max_list, up_down_list
6
+ from util.date_util import format_date
7
 
8
 
9
  def read_section(db_name, tb_name='tb_section', section_id=''):
 
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(
37
+ tb_name) + ' WHERE section_id == ' + str(section_id)
38
  section_cursor = conn.execute(sql_str)
39
  for section_row in section_cursor:
40
  section_id = section_row[0]
 
57
  for sample_row in sample_cursor:
58
  _id = sample_row[0]
59
  date = sample_row[1]
60
+ _max = sample_row[2]
61
+ _min = sample_row[3]
62
  acc_max = sample_row[4] + sample_row[5] + sample_row[6]
63
  light = sample_row[7]
64
  screen = sample_row[8]
65
  debug_print('_id = ', _id, 'date = ', format_date(date))
66
 
67
  date_list.append(format_date(date))
68
+ max_list.append(_max)
69
+ min_list.append(_min)
70
  acc_list.append(acc_max)
71
  light_list.append(light)
72
  screen_list.append(screen)
73
 
 
 
 
 
74
  title_str = str(section_id) + ', ' + str(format_date(section_date)) + ', ' + str(format_date(section_end_date))
75
+ light_min = min(light_list)
76
+ light_max = max(light_list)
77
+ screen_list = min_max_list(screen_list, light_min, light_max)
78
+ screen_list = up_down_list(screen_list)
79
+ draw_lists(title_str, date_list, max=max_list, min=min_list, acc=acc_list, screen=screen_list, light=light_list)
80
 
81
 
82
  if __name__ == '__main__':
date_util.py DELETED
@@ -1,16 +0,0 @@
1
- from datetime import datetime
2
-
3
- from numpy.compat import long
4
-
5
-
6
- def format_date(section_date):
7
- # formatted_date = datetime.fromtimestamp(section_date).strftime('%Y-%m-%d %H:%M:%S')
8
- return datetime.fromtimestamp(section_date / 1000)
9
-
10
- # # 使用datetime.strptime解析原始日期字符串
11
- # date_obj = datetime.strptime(section_date, "%Y%m%d%H%M")
12
- #
13
- # # 使用strftime将日期对象格式化为新的格式
14
- # formatted_date = date_obj.strftime("%Y%m%d %H:%M")
15
- #
16
- # return formatted_date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
draw_db.py CHANGED
@@ -1,25 +1,8 @@
1
- import matplotlib.pyplot as plt
2
-
3
- import debug
4
- from debug import debug_print
5
-
6
-
7
- def draw(x_points=None, y_points=None):
8
- plt.plot(x_points)
9
-
10
- plt.ylim(ymin=0, ymax=120)
11
- plt.show()
12
-
13
 
14
- def draw_two(title='', x_list1=None, x_list2=None):
15
- fig, ax = plt.subplots()
16
- ax.plot(x_list1)
17
- ax.plot(x_list2)
18
- ax.legend()
19
 
20
- plt.ylim(ymin=0, ymax=120)
21
- plt.title(title)
22
- plt.show()
23
 
24
 
25
  def up_down_list(_list):
@@ -33,46 +16,30 @@ def min_max_list(src_list, tar_min, tar_max):
33
  src_max = max(src_list)
34
  src_range = abs(src_max - src_min)
35
  tar_range = abs(tar_max - tar_min)
36
- scale_ratio = tar_range / src_range
37
  floor_up = [v - src_min for v in src_list]
38
  scale_to = [v * scale_ratio for v in floor_up]
39
  floor_down = [v + tar_min for v in scale_to]
40
  return floor_down
41
 
42
 
43
- def draw_three(title='', date_list=None, x_list1=None, x_list2=None, x_list3=None, light_list=None, screen_list=None):
44
  debug_print('draw_three, date_list = ', str(date_list))
45
- debug_print('draw_three, light_list = ', str(light_list))
46
-
47
- if screen_list is not None:
48
- screen_list = [(x - 2) * 4 for x in screen_list]
49
- screen_list = up_down_list(screen_list)
50
- # screen_list = map(lambda x: (x - 2) * 4, screen_list)
51
-
52
- if light_list is not None:
53
- light_list2 = min_max_list(light_list, -20, -10)
54
-
55
- fig, axs = plt.subplots(2, 1, sharex=True)
56
- # axs[0].axes.get_xaxis().set_visible(False)
57
- if date_list is None:
58
- axs[0].plot(x_list1, label='max', color='blue')
59
- axs[0].plot(x_list2, label='min', color='orange')
60
- axs[0].plot(x_list3, label='acc', color='green')
61
- axs[1].plot(screen_list, label='screen')
62
- axs[1].plot(light_list, label='light')
63
- else:
64
- axs[0].plot(date_list, x_list1, label='max', color='blue')
65
- axs[0].plot(date_list, x_list2, label='min', color='orange')
66
- axs[0].plot(date_list, x_list3, label='acc', color='green')
67
- axs[1].plot(date_list, screen_list, label='screen')
68
- axs[1].plot(date_list, light_list, label='light')
69
-
70
- plt.gcf().autofmt_xdate()
71
- # plt.ylim(ymin=-30, ymax=20000)
72
- # plt.title(title)
73
 
74
  if debug.DEBUG:
75
  plt.show()
76
  else:
77
  file_uri = '.doc/' + title + '.png'
78
- plt.savefig(file_uri)
 
1
+ import math
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ import matplotlib.pyplot as plt
 
 
 
 
4
 
5
+ from util.debug import debug_print
 
 
6
 
7
 
8
  def up_down_list(_list):
 
16
  src_max = max(src_list)
17
  src_range = abs(src_max - src_min)
18
  tar_range = abs(tar_max - tar_min)
19
+ scale_ratio = 0 if src_range == 0 else tar_range / src_range
20
  floor_up = [v - src_min for v in src_list]
21
  scale_to = [v * scale_ratio for v in floor_up]
22
  floor_down = [v + tar_min for v in scale_to]
23
  return floor_down
24
 
25
 
26
+ def draw_lists(title='', date_list=None, **kv_list):
27
  debug_print('draw_three, date_list = ', str(date_list))
28
+ # debug_print('draw_three, light_list = ', str(light_list))
29
+
30
+ idx_list = 0
31
+ idx_axs = 0
32
+ rows = math.ceil(len(kv_list.items()) / 3)
33
+ fig, axs = plt.subplots(rows, 1, sharex=True)
34
+ for key, value in kv_list.items():
35
+ if type(key) is str and type(value) is list:
36
+ axs[idx_axs].plot(date_list, value, label=key)
37
+ axs[idx_axs].legend()
38
+ idx_list = idx_list + 1
39
+ idx_axs = int(idx_list / 3)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  if debug.DEBUG:
42
  plt.show()
43
  else:
44
  file_uri = '.doc/' + title + '.png'
45
+ fig.savefig(file_uri)
sample.wll.202311.db DELETED
Binary file (193 kB)
 
util/date_util.py CHANGED
@@ -1,11 +1,16 @@
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
 
 
 
 
 
 
 
1
  from datetime import datetime
2
 
3
+ from numpy.compat import long
4
 
 
 
 
5
 
6
+ def format_date(section_date):
7
+ # formatted_date = datetime.fromtimestamp(section_date).strftime('%Y-%m-%d %H:%M:%S')
8
+ return datetime.fromtimestamp(section_date / 1000)
9
 
10
+ # # 使用datetime.strptime解析原始日期字符串
11
+ # date_obj = datetime.strptime(section_date, "%Y%m%d%H%M")
12
+ #
13
+ # # 使用strftime将日期对象格式化为新的格式
14
+ # formatted_date = date_obj.strftime("%Y%m%d %H:%M")
15
+ #
16
+ # return formatted_date
debug.py → util/debug.py RENAMED
File without changes