scan_collection.py
1.5 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
import numpy as np
import re
import time
import timeit
import functools
# from app.induction_test import config_dict,convert_dict
s_detail = {}
test_state = False
def logtime(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
start = time.perf_counter()
res = func(*args, **kwargs)
end = time.perf_counter()
print(f'函数 {func.__name__} 耗时 {(end - start) * 1000} ms')
return res
return wrapper
@logtime
def first_filter(origin_value):
cur_dict = transfer(origin_value)
return cur_dict,s_detail
def production_filter(origin_value):
cur_dict = transfer(origin_value)
return cur_dict
def transfer(origin_value):
cur_dict = {}
if origin_value:
# receive_data=origin_value.split("\n")
receive_data=origin_value.decode().split("\r\n")
for item in receive_data[::-1]:
if not (item.startswith("A") and item.endswith("]")):
receive_data.remove(item)
print (item)
print("筛选后的数据:", receive_data)
if receive_data:
for line in receive_data:
# print ("-----------------line",line)
addr = re.search("(?<=A)\d+",line)
led = re.search("\[.*?\]", line)
c_list = list(led.group())
# print ("-------------------c_list",c_list)
c_list.pop(0)
c_list.pop(-1)
keyword = 'A' + addr.group()
cur_dict[keyword] = c_list
return cur_dict
def change_deatil(old_dict):
global s_detail
if old_dict:
s_detail = old_dict
# print ('------------------------',s_detail)
def reset_value():
s_detail = {}
print (s_detail)