Skip to content

Commit e9eb640

Browse files
committed
update
1 parent a734366 commit e9eb640

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+788
-323
lines changed

config/config.yaml

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
1-
source:
2-
video_path: ./video_data/dayroad.mp4
3-
rtsp:
4-
label: False
5-
account: your account
6-
password: your password
7-
ip_address: you camera ip
8-
channel: 1
9-
101
client:
2+
# the source video
3+
source:
4+
video_path: ./video_data/dayroad.mp4
5+
max_count: 120
6+
rtsp:
7+
flag: False
8+
account: your account
9+
password: your password
10+
ip_address: you camera ip
11+
channel: 1
1112
#the frame interval
1213
interval: 2
1314
#the difference feature (pixel, edge, area, corner).
1415
feature: edge
15-
#the difference threshold
16-
diff_lable: True
16+
#the difference flag and thresh
17+
diff_flag: True
1718
diff_thresh: 0.01
18-
#timeout drop frame
19-
timeout_drop: 4
2019
#the queue maxsize
2120
local_queue_maxsize: 10
2221
#the queue threshold for offloading
2322
queue_thresh: 5
2423
#Number of worker threads to offloading thread pool
2524
offloading_max_worker: 1
2625
frame_cache_maxsize: 100
27-
#regularly update queue info (second)
28-
regular: 3
2926
small_model_name: fasterrcnn_mobilenet_v3_large_fpn
3027
#select the offloading policy
31-
policy: Edge-Cloud-Assisted
28+
policy: Edge-Cloud-Threshold
3229
#change frame resolution using frame new height
3330
new_height:
3431
#offload to another edge node [1080, 720], default 720
@@ -44,33 +41,26 @@ client:
4441
#offload to another edge node [90, 85], default 85
4542
another: 90
4643
#Option to offload directly to the cloud [85, 95], default 85
47-
directly_cloud: 85
44+
directly_cloud: 90
4845
#offload to the cloud after local inference [85, 95], default 95
49-
local_cloud: 95
46+
local_cloud: 90
5047
#The task from another edge node is offloaded to the cloud after local inference, default 85.
5148
another_cloud: 90
5249
#server_ip
53-
server_ip: 'server ip'
50+
server_ip: '127.0.0.1'
5451
#edge nodes
5552
edge_id: 1
56-
edge_num: 1
57-
edges: ['127.0.0.1:50051',]
53+
destinations: {'id': [], 'ip':[]}
54+
#database config
55+
database:
56+
connection: { 'user': 'root', 'password': 'root', 'host': '127.0.0.1', 'raise_on_warnings': True }
57+
database_name: 'mydatabase'
5858

5959
server:
6060
server_id: 0
6161
large_model_name: fasterrcnn_resnet50_fpn
62-
#timeout drop frame
63-
timeout_drop: 4
6462
#the queue maxsize
6563
local_queue_maxsize: 10
6664
data_queue_maxsize: 10
6765

68-
#database config
69-
database:
70-
connection: {'user': 'root', 'password': 'root', 'host': 'database ip', 'raise_on_warnings': True}
71-
database_name: 'mydatabase'
72-
tables: [edge1]
73-
table_description: "CREATE TABLE `{}` (`index` int NOT NULL, `start_time` timestamp(6) NOT NULL,`end_time` timestamp(6) NOT NULL, `result` text, `mark` text , PRIMARY KEY(`index`)) ENGINE=InnoDB"
74-
insert_description: "INSERT INTO `{}` (`index`, `start_time`, `end_time`, `result`, `mark`) VALUES (%s ,%s, %s, %s, %s);"
75-
select_description: "SELECT `index`, `start_time`, `end_time`, `result`, `mark` FROM `{}`;"
7666

136 Bytes
Binary file not shown.
3.35 KB
Binary file not shown.

database/database.py

Lines changed: 75 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import time
2+
import munch
23
import mysql.connector
34
from datetime import datetime
45
from mysql.connector import errorcode
@@ -10,11 +11,27 @@ class DataBase:
1011
def __init__(self, config):
1112
self.cnx = mysql.connector.connect(**config.connection)
1213
self.database_name = config.database_name
13-
self.tables = config.tables
14-
self.table_description = config.table_description
15-
self.insert_description = config.insert_description
16-
self.select_description = config.select_description
14+
self.table_desc = "CREATE TABLE `{}` " \
15+
"(`index` int NOT NULL, " \
16+
"`start_time` timestamp(6) NOT NULL," \
17+
"`end_time` timestamp(6) NOT NULL, " \
18+
"`result` TEXT, " \
19+
"`log` VARCHAR(255)," \
20+
"PRIMARY KEY(`index`)) ENGINE=InnoDB"
1721

22+
self.insert_desc = "INSERT INTO `{}` " \
23+
"(`index`, `start_time`, `end_time`, `result`, `log`) " \
24+
"VALUES (%s ,%s, %s, %s, %s);"
25+
26+
self.select_desc= "SELECT `index`, `start_time`, `end_time`, `result`, `log` FROM `{}`;"
27+
28+
self.select_one_desc = "SELECT `index`, `start_time`, `end_time`, `result`, `log` FROM `{}`" \
29+
"where `index` = %s"
30+
31+
self.update_desc = "UPDATE {} SET `end_time` = %s, " \
32+
"`result` = %s, " \
33+
"`log` = %s " \
34+
"WHERE `index` = %s"
1835

1936
def _create_database(self, cursor):
2037
try:
@@ -38,29 +55,27 @@ def use_database(self):
3855
exit(1)
3956
cursor.close()
4057

41-
def create_tables(self):
58+
def create_table(self, edge_id):
4259
cursor = self.cnx.cursor()
43-
table_description = self.table_description
44-
for table_name in self.tables:
45-
try:
46-
logger.info("Creating table {}: ".format(table_name))
47-
cursor.execute(table_description.format(table_name))
48-
except mysql.connector.Error as err:
49-
if err.errno == errorcode.ER_TABLE_EXISTS_ERROR:
50-
cursor.execute("drop table {}".format(table_name))
51-
logger.info("already exists, drop it.")
52-
cursor.execute(table_description.format(table_name))
53-
else:
54-
logger.error(err.msg)
60+
table_sql = self.table_desc
61+
try:
62+
logger.info("Creating table {}: ".format(edge_id))
63+
cursor.execute(table_sql.format(edge_id))
64+
except mysql.connector.Error as err:
65+
if err.errno == errorcode.ER_TABLE_EXISTS_ERROR:
66+
cursor.execute("drop table {}".format(edge_id))
67+
logger.info("already exists, drop it.")
68+
cursor.execute(table_sql.format(edge_id))
5569
else:
56-
logger.success("create successfully")
70+
logger.error(err.msg)
71+
else:
72+
logger.success("create successfully")
5773
cursor.close()
5874

5975
def clear_table(self, edge_id):
6076
cursor = self.cnx.cursor()
61-
table_name = self.tables[edge_id - 1]
6277
try:
63-
cursor.execute("truncate table {}".format(table_name))
78+
cursor.execute("truncate table {}".format(edge_id))
6479
except mysql.connector.Error as err:
6580
cursor.close()
6681
logger.error(err.msg)
@@ -71,10 +86,9 @@ def clear_table(self, edge_id):
7186

7287
def select_result(self, edge_id):
7388
cursor = self.cnx.cursor()
74-
select_description = self.select_description
75-
table_name = self.tables[edge_id-1]
89+
select_sql = self.select_desc
7690
try:
77-
cursor.execute(select_description.format(table_name))
91+
cursor.execute(select_sql.format(edge_id))
7892
results = cursor.fetchall()
7993
except Exception as e:
8094
logger.error('Query failed {}'.format(e))
@@ -85,9 +99,24 @@ def select_result(self, edge_id):
8599
logger.success('query successfully')
86100
return results
87101

102+
def select_one_result(self, edge_id, index):
103+
cursor = self.cnx.cursor()
104+
select_sql = self.select_one_desc
105+
try:
106+
cursor.execute(select_sql.format(edge_id), index)
107+
result = cursor.fetchone()
108+
except Exception as e:
109+
logger.error('Query failed {}'.format(e))
110+
cursor.close()
111+
return None
112+
else:
113+
cursor.close()
114+
logger.success('query successfully')
115+
return result
116+
88117
def insert_data(self, table_name, data):
89118
cursor = self.cnx.cursor()
90-
insert_sql = self.insert_description.format(table_name)
119+
insert_sql = self.insert_desc.format(table_name)
91120
try:
92121
cursor.execute(insert_sql, data)
93122
# Make sure data is committed to the database
@@ -101,6 +130,27 @@ def insert_data(self, table_name, data):
101130
logger.success('insert successfully')
102131

103132

133+
def update_data(self, table_name, data):
134+
cursor = self.cnx.cursor()
135+
update_sql = self.update_desc.format(table_name)
136+
try:
137+
cursor.execute(update_sql, data)
138+
# Make sure data is committed to the database
139+
self.cnx.commit()
140+
141+
except Exception as e:
142+
cursor.close()
143+
logger.error("update error {}".format(e))
144+
else:
145+
cursor.close()
146+
logger.success('update successfully')
147+
148+
104149

105150
if __name__ == '__main__':
106-
pass
151+
config = {
152+
"connection": {'user': 'root', 'password': 'root', 'host': '127.0.0.1', 'raise_on_warnings': True},
153+
"database_name": 'mydatabase',
154+
}
155+
config = munch.munchify(config)
156+
mydb = DataBase(config)
138 Bytes
Binary file not shown.
3.83 KB
Binary file not shown.
132 Bytes
Binary file not shown.
8.77 KB
Binary file not shown.

edge/__pycache__/task.cpython-38.pyc

1.47 KB
Binary file not shown.

0 commit comments

Comments
 (0)