thelou1s commited on
Commit
f1f2090
1 Parent(s): ad858b9
Files changed (7) hide show
  1. .gitignore +2 -0
  2. analysis_db.py +74 -0
  3. date_util.py +16 -0
  4. debug.py +7 -0
  5. draw_db.py +22 -0
  6. main.py +16 -0
  7. sample.wll.202311.db +0 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ /.idea
2
+ /__pycache__
analysis_db.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_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
+
13
+ if not tb_name:
14
+ table_cursor = conn.cursor()
15
+ table_cursor.execute(' SELECT name FROM sqlite_master WHERE type=\'table\'; ')
16
+ table_names = table_cursor.fetchall()
17
+ print('table_names = ', str(table_names))
18
+ return
19
+
20
+ if not section_id:
21
+ section_cursor = conn.execute(' SELECT section_id, section_date, section_end_date FROM ' + tb_name)
22
+ for section_row in section_cursor:
23
+ section_id = section_row[0]
24
+ section_date = section_row[1]
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
+ 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
+
61
+
62
+ if __name__ == '__main__':
63
+ argv = sys.argv[1:]
64
+ argc = len(sys.argv[1:])
65
+ # print('sys.argv[1:] = ', argv, ', ', str(len(argv)))
66
+
67
+ if argc < 1:
68
+ print('USAGE: python analysis_db.py xxx.db')
69
+ exit(1)
70
+
71
+ db_uri = argv[0] if argc >= 1 else ''
72
+ tb_name = argv[1] if argc >= 2 else ''
73
+ section_id = argv[2] if argc >= 3 else ''
74
+ read_db(db_uri, tb_name, section_id)
date_util.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ DEBUG = True
2
+ # DEBUG = False
3
+
4
+
5
+ def debug_print(self, *args, sep=' ', end='\n', file=None):
6
+ if DEBUG:
7
+ print(self, *args, sep, end, file)
draw_db.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+
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()
main.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This is a sample Python script.
2
+
3
+ # Press ⇧F10 to execute it or replace it with your code.
4
+ # Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.
5
+
6
+
7
+ def print_hi(name):
8
+ # Use a breakpoint in the code line below to debug your script.
9
+ print(f'Hi, {name}') # Press ⌘F8 to toggle the breakpoint.
10
+
11
+
12
+ # Press the green button in the gutter to run the script.
13
+ if __name__ == '__main__':
14
+ print_hi('PyCharm')
15
+
16
+ # See PyCharm help at https://www.jetbrains.com/help/pycharm/
sample.wll.202311.db ADDED
Binary file (193 kB). View file