-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_data.py
More file actions
71 lines (54 loc) · 2.53 KB
/
process_data.py
File metadata and controls
71 lines (54 loc) · 2.53 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
65
66
67
68
69
70
71
import re
def parse_dataset_file(filepath):
data = {}
round_index = None
with open(filepath, "r", encoding="utf-8") as f:
for line in f:
line = line.strip()
if not line:
continue
# -------- Round index --------
if line.startswith("Round_index"):
round_index = int(line.split()[-1])
data[round_index] = {
"anchors": {},
"cluster": None
}
# -------- Anchor line --------
elif line.startswith("Anchor"):
# Anchor 1: Ddoa=0.13 tof_delta=-2.26 rssi=-63.31 Kurt=17.69, RMS=52.73, energy=-3.03 dB
anchor_match = re.match(r"Anchor\s+(\d+):", line)
anchor_id = int(anchor_match.group(1))
features = {}
features["Ddoa"] = float(re.search(r"Ddoa=([-.\d]+)", line).group(1))
features["tof_delta"] = float(re.search(r"tof_delta=([-.\d]+)", line).group(1))
features["rssi"] = float(re.search(r"rssi=([-.\d]+)", line).group(1))
features["kurt"] = float(re.search(r"Kurt=([-.\d]+)", line).group(1))
features["rms"] = float(re.search(r"RMS=([-.\d]+)", line).group(1))
features["energy_db"] = float(re.search(r"energy=([-.\d]+)", line).group(1))
data[round_index]["anchors"][anchor_id] = features
# -------- Cluster line --------
elif line.startswith("Unfiltered Cluster"):
m_id = re.search(r"ID=(\d+)", line)
m_x = re.search(r"X=([-.\d]+)", line)
m_y = re.search(r"Y=([-.\d]+)", line)
# 防御式编程(关键)
if not (m_id and m_x and m_y):
# 可以选择 continue 或打印调试
# print("Skip malformed cluster line:", line)
continue
cluster_id = int(m_id.group(1))
x = float(m_x.group(1))
y = float(m_y.group(1))
data[round_index]["cluster"] = {
"id": cluster_id,
"x": x,
"y": y
}
return data
# data = parse_dataset_file("dataset/chest_4HZ.txt")
# # 访问示例
# round_2771 = data[2771]
# anchor_3 = data[2771]["anchors"][3]
# print(anchor_3["tof_delta"])
# print(round_2771["cluster"]["x"])