-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest.py
More file actions
64 lines (60 loc) · 1.95 KB
/
test.py
File metadata and controls
64 lines (60 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
局部代码测试
@Author: JK_Wang
@Time: 20-May-19
"""
# import pymysql
#
# connection = pymysql.connect(host='localhost', user='root', password='123456', db='detection', charset='utf8')
# print(connection)
# cursor = connection.cursor()
# sql = "INSERT INTO detection_log(detect_class, path) VALUES(%s, %s)"
# cursor.execute(sql, ('1', '2'))
# connection.commit()
# import cv2
#
# img = cv2.imread('D:/test.jpg')
# print(img.shape)
# _, im = cv2.imencode('.jpg', img)
# res = cv2.imdecode(im, -1)
# print(res)
# # cv2.imshow('1', im)
# print(im.shape)
# cv2.imwrite('D:/test.jpg', im)
#
# cv2.waitKey()
import pymysql
import time
import random as rd
connection = pymysql.connect(host='localhost', user='root', password='123456',
db='detection', charset='utf8')
cursor = connection.cursor()
class_name_dic = {0: 'normal', 1: 'nothing', 2: 'lack_cotton', 3: 'lack_piece', 4: 'wire_fail'}
defect_num = 0
t_sum = [0.0, 0.0, 0.0, 0.0]
for i in range(1, 1000):
print(i)
time.sleep(rd.randint(15, 25)/10)
a = rd.randint(0, 100)
t1 = rd.randint(19, 23)/10
t2 = rd.randint(25, 29) / 10
t3 = rd.randint(18, 22) / 10
t4 = rd.randint(24, 26) / 10
t_sum[0] += t1
t_sum[1] += t2
t_sum[2] += t3
t_sum[3] += t4
avg1 = round(t_sum[0] / i, 1)
avg2 = round(t_sum[1] / i, 1)
avg3 = round(t_sum[2] / i, 1)
avg4 = round(t_sum[3] / i, 1)
if a < 2:
defect_num += 1
sql_1 = "UPDATE running_state set uph = %s, detection_num = %s, defect_num = %s where id = 1"
sql_2 = "UPDATE chart_data set step_1 = %s, step_2 = %s, step_3 = %s, step_4 = %s where id = 1"
sql_3 = "UPDATE chart_data set step_1 = %s, step_2 = %s, step_3 = %s, step_4 = %s where id = 2"
cursor.execute(sql_1, (str(i), str(1536 + i), str(defect_num)))
cursor.execute(sql_2, (str(t1), str(t2), str(t3), str(t4)))
cursor.execute(sql_3, (str(avg1), str(avg2), str(avg3), str(avg4)))
# 提交事务
connection.commit()