Upload 6 files
Browse files
WiCount.zip
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d578ba4ec4d64ef7089e0fa5c8b47498a76fce5f7d32fb7c7f7f994235915ae1
|
3 |
+
size 9389189
|
data_process_example/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# How to Run
|
2 |
+
|
3 |
+
1. Execute `process1.py` to convert the `csv` file into a `pkl` file.
|
4 |
+
|
5 |
+
2. Run one of the `process2` scripts based on your requirements:
|
6 |
+
|
7 |
+
|
8 |
+
|
9 |
+
**Note:** We use `-1000` to represent the position of package loss. You can apply various interpolation methods to fill these gaps. We highly encourage you to try our CSI-BERT model to recover the lost packages. ([CSI-BERT](https://github.com/RS2002/CSI-BERT), [CSI-BERT2](https://github.com/RS2002/CSI-BERT2))
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
(1) If you want to process each record into a long sequence, run `process2.py`. You can refer to `dataset.py` in [CSI-BERT2](https://github.com/RS2002/CSI-BERT2) for guidance.
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
(2) If you prefer to split each record into multiple fixed-length samples, run `process2-split.py` and modify the `length` parameter in the code to your desired length. You can refer to `dataset.py` in [CSI-BERT](https://github.com/RS2002/CSI-BERT), [CrossFi](https://github.com/RS2002/CrossFi), [KNN-MMD](https://github.com/RS2002/CrossFi), and [LoFi](https://github.com/RS2002/LoFi/tree/main/network_examples) for usage instructions.
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
(3) `process2-squeeze-split.py` functions similarly to `process2-split.py`, but it excludes all lost packages.
|
data_process_example/process1.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import pickle
|
3 |
+
import os
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
root="./data/"
|
7 |
+
data=[]
|
8 |
+
csi_vaid_subcarrier_index = range(0, 52)
|
9 |
+
|
10 |
+
def handle_complex_data(x, valid_indices):
|
11 |
+
real_parts = []
|
12 |
+
imag_parts = []
|
13 |
+
for i in valid_indices:
|
14 |
+
real_parts.append(x[i * 2])
|
15 |
+
imag_parts.append(x[i * 2 - 1])
|
16 |
+
return np.array(real_parts) + 1j * np.array(imag_parts)
|
17 |
+
|
18 |
+
|
19 |
+
for people_num in os.listdir(root):
|
20 |
+
if len(people_num)>1:
|
21 |
+
continue
|
22 |
+
print(people_num)
|
23 |
+
path=os.path.join(root,people_num)
|
24 |
+
|
25 |
+
for file in os.listdir(path):
|
26 |
+
if file[-3:] != "csv":
|
27 |
+
continue
|
28 |
+
print(file)
|
29 |
+
df = pd.read_csv(os.path.join(path,file))
|
30 |
+
df.dropna(inplace=True)
|
31 |
+
df['data'] = df['data'].apply(lambda x: eval(x))
|
32 |
+
complex_data = df['data'].apply(lambda x: handle_complex_data(x, csi_vaid_subcarrier_index))
|
33 |
+
magnitude = complex_data.apply(lambda x: np.abs(x))
|
34 |
+
phase = complex_data.apply(lambda x: np.angle(x, deg=True))
|
35 |
+
time = np.array(df['timestamp'])
|
36 |
+
local_time = np.array(df['local_timestamp'])
|
37 |
+
|
38 |
+
data.append({
|
39 |
+
'csi_time':time,
|
40 |
+
'csi_local_time':local_time,
|
41 |
+
'people_num': eval(people_num),
|
42 |
+
'magnitude': np.array([np.array(a) for a in magnitude]),
|
43 |
+
'phase': np.array([np.array(a) for a in phase]),
|
44 |
+
'CSI': np.array([np.array(a) for a in complex_data])
|
45 |
+
})
|
46 |
+
|
47 |
+
# 保存全局字典为一个pickle文件
|
48 |
+
output_file = './csi_data.pkl'
|
49 |
+
with open(output_file, 'wb') as f:
|
50 |
+
pickle.dump(data, f)
|
data_process_example/process2-split.py
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import pickle
|
3 |
+
import copy
|
4 |
+
|
5 |
+
def get_time(s):
|
6 |
+
s=s.split()[-1]
|
7 |
+
s=s.split(":")
|
8 |
+
h=float(s[0])
|
9 |
+
m=float(s[1])
|
10 |
+
t=float(s[2])
|
11 |
+
total=h*3600+m*60+t
|
12 |
+
return h,m,t,total
|
13 |
+
|
14 |
+
gap=1
|
15 |
+
length=gap*100
|
16 |
+
pad=[-1000]*52
|
17 |
+
action_list=[]
|
18 |
+
people_list=[]
|
19 |
+
timestamp=[]
|
20 |
+
magnitudes=[]
|
21 |
+
phases=[]
|
22 |
+
loacl_gap=10000
|
23 |
+
|
24 |
+
|
25 |
+
with open("./csi_data.pkl", 'rb') as f:
|
26 |
+
csi = pickle.load(f)
|
27 |
+
|
28 |
+
for data in csi:
|
29 |
+
csi_time=data['csi_time']
|
30 |
+
local_time=data['csi_local_time']
|
31 |
+
magnitude=data['magnitude']
|
32 |
+
phase=data['phase']
|
33 |
+
people=data['people_num']
|
34 |
+
action=people
|
35 |
+
start_time=None
|
36 |
+
last_local=None
|
37 |
+
current_magnitude=[]
|
38 |
+
current_phase=[]
|
39 |
+
current_timestamp=[]
|
40 |
+
for i in range(len(csi_time)):
|
41 |
+
_, _, _, current_time = get_time(csi_time[i])
|
42 |
+
if start_time is None or current_time-start_time>gap:
|
43 |
+
if start_time is not None:
|
44 |
+
if len(current_magnitude)>=length:
|
45 |
+
current_magnitude=current_magnitude[:length]
|
46 |
+
current_phase=current_phase[:length]
|
47 |
+
current_timestamp=current_timestamp[:length]
|
48 |
+
else:
|
49 |
+
add=length-len(current_magnitude)
|
50 |
+
delta=(current_timestamp[0]+length*loacl_gap-current_timestamp[-1])/add
|
51 |
+
for j in range(add):
|
52 |
+
current_magnitude.append(pad)
|
53 |
+
current_phase.append(pad)
|
54 |
+
current_timestamp.append(current_timestamp[-1]+delta)
|
55 |
+
magnitudes.append(copy.deepcopy(current_magnitude))
|
56 |
+
phases.append(copy.deepcopy(current_phase))
|
57 |
+
timestamp.append(copy.deepcopy(current_timestamp))
|
58 |
+
action_list.append(action)
|
59 |
+
people_list.append(people)
|
60 |
+
current_magnitude = []
|
61 |
+
current_phase = []
|
62 |
+
current_timestamp = []
|
63 |
+
start_time=current_time
|
64 |
+
last_local=local_time[i]
|
65 |
+
current_magnitude.append(magnitude[i])
|
66 |
+
current_phase.append(phase[i])
|
67 |
+
current_timestamp.append(local_time[i])
|
68 |
+
else:
|
69 |
+
local = local_time[i]
|
70 |
+
num=round((local-last_local-loacl_gap)/loacl_gap)
|
71 |
+
if num>0:
|
72 |
+
delta=(local-last_local)/(num+1)
|
73 |
+
for j in range(num):
|
74 |
+
current_magnitude.append(pad)
|
75 |
+
current_phase.append(pad)
|
76 |
+
current_timestamp.append(current_timestamp[-1] + delta)
|
77 |
+
current_magnitude.append(magnitude[i])
|
78 |
+
current_phase.append(phase[i])
|
79 |
+
current_timestamp.append(local_time[i])
|
80 |
+
last_local=local
|
81 |
+
|
82 |
+
|
83 |
+
action_list=np.array(action_list)
|
84 |
+
people_list=np.array(people_list)
|
85 |
+
timestamp=np.array(timestamp)
|
86 |
+
magnitudes=np.array(magnitudes)
|
87 |
+
phases=np.array(phases)
|
88 |
+
print(action_list.shape)
|
89 |
+
print(people_list.shape)
|
90 |
+
print(timestamp.shape)
|
91 |
+
print(magnitudes.shape)
|
92 |
+
print(phases.shape)
|
93 |
+
np.save("./magnitude.npy", np.array(magnitudes))
|
94 |
+
np.save("./phase.npy", np.array(phases))
|
95 |
+
np.save("./action.npy", np.array(action_list))
|
96 |
+
np.save("./people.npy", np.array(people_list))
|
97 |
+
np.save("./timestamp.npy", np.array(timestamp))
|
data_process_example/process2-squeeze-split.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import pickle
|
3 |
+
import copy
|
4 |
+
|
5 |
+
|
6 |
+
gap=1
|
7 |
+
length=gap*100
|
8 |
+
pad=[-1000]*52
|
9 |
+
action_list=[]
|
10 |
+
people_list=[]
|
11 |
+
timestamp=[]
|
12 |
+
magnitudes=[]
|
13 |
+
phases=[]
|
14 |
+
loacl_gap=10000
|
15 |
+
|
16 |
+
|
17 |
+
with open("./csi_data.pkl", 'rb') as f:
|
18 |
+
csi = pickle.load(f)
|
19 |
+
|
20 |
+
for data in csi:
|
21 |
+
csi_time=data['csi_time']
|
22 |
+
local_time=data['csi_local_time']
|
23 |
+
magnitude=data['magnitude']
|
24 |
+
phase=data['phase']
|
25 |
+
people=data['people_num']
|
26 |
+
action=people
|
27 |
+
|
28 |
+
index=0
|
29 |
+
while index<len(magnitude)-length:
|
30 |
+
current_magnitude=magnitude[index:index+length]
|
31 |
+
current_phase=phase[index:index+length]
|
32 |
+
current_timestamp=local_time[index:index+length]
|
33 |
+
index+=(length+gap-1)
|
34 |
+
magnitudes.append(copy.deepcopy(current_magnitude))
|
35 |
+
phases.append(copy.deepcopy(current_phase))
|
36 |
+
timestamp.append(copy.deepcopy(current_timestamp))
|
37 |
+
action_list.append(action)
|
38 |
+
people_list.append(people)
|
39 |
+
|
40 |
+
action_list=np.array(action_list)
|
41 |
+
people_list=np.array(people_list)
|
42 |
+
timestamp=np.array(timestamp)
|
43 |
+
magnitudes=np.array(magnitudes)
|
44 |
+
phases=np.array(phases)
|
45 |
+
print(action_list.shape)
|
46 |
+
print(people_list.shape)
|
47 |
+
print(timestamp.shape)
|
48 |
+
print(magnitudes.shape)
|
49 |
+
print(phases.shape)
|
50 |
+
np.save("./squeeze_data/magnitude.npy", np.array(magnitudes))
|
51 |
+
np.save("./squeeze_data/phase.npy", np.array(phases))
|
52 |
+
np.save("./squeeze_data/action.npy", np.array(action_list))
|
53 |
+
np.save("./squeeze_data/people.npy", np.array(people_list))
|
54 |
+
np.save("./squeeze_data/timestamp.npy", np.array(timestamp))
|
data_process_example/process2.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import pickle
|
3 |
+
|
4 |
+
|
5 |
+
result=[]
|
6 |
+
|
7 |
+
pad=[-1000]*52
|
8 |
+
loacl_gap=10000
|
9 |
+
|
10 |
+
|
11 |
+
with open("./csi_data.pkl", 'rb') as f:
|
12 |
+
csi = pickle.load(f)
|
13 |
+
|
14 |
+
for data in csi:
|
15 |
+
csi_time=data['csi_time']
|
16 |
+
local_time=data['csi_local_time']
|
17 |
+
magnitude=data['magnitude']
|
18 |
+
phase=data['phase']
|
19 |
+
people_num=data['people_num']
|
20 |
+
|
21 |
+
last_local=None
|
22 |
+
current_magnitude=[]
|
23 |
+
current_phase=[]
|
24 |
+
current_timestamp=[]
|
25 |
+
for i in range(len(csi_time)):
|
26 |
+
if last_local is None:
|
27 |
+
last_local=local_time[i]
|
28 |
+
current_magnitude.append(magnitude[i])
|
29 |
+
current_phase.append(phase[i])
|
30 |
+
current_timestamp.append(local_time[i])
|
31 |
+
else:
|
32 |
+
local = local_time[i]
|
33 |
+
num=round((local-last_local-loacl_gap)/loacl_gap)
|
34 |
+
if num>0:
|
35 |
+
delta=(local-last_local)/(num+1)
|
36 |
+
for j in range(num):
|
37 |
+
current_magnitude.append(pad)
|
38 |
+
current_phase.append(pad)
|
39 |
+
current_timestamp.append(current_timestamp[-1] + delta)
|
40 |
+
current_magnitude.append(magnitude[i])
|
41 |
+
current_phase.append(phase[i])
|
42 |
+
current_timestamp.append(local_time[i])
|
43 |
+
last_local=local
|
44 |
+
|
45 |
+
print(len(current_magnitude))
|
46 |
+
result.append({
|
47 |
+
'time': np.array(current_timestamp),
|
48 |
+
'action': people_num,
|
49 |
+
'people': people_num,
|
50 |
+
'magnitude': np.array(current_magnitude),
|
51 |
+
'phase': np.array(current_phase)
|
52 |
+
})
|
53 |
+
|
54 |
+
output_file = './data_sequence.pkl'
|
55 |
+
with open(output_file, 'wb') as f:
|
56 |
+
pickle.dump(result, f)
|
57 |
+
|