File size: 2,792 Bytes
ee32bf3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import numpy as np
import pickle
import pandas as pd


result=[]
pad=[-1000]*52
loacl_gap=10000

def process_time(timestamp):
    t = timestamp.split()
    t = t[-1].split(":")
    h = float(t[0])
    m = float(t[1])
    t = t[-1].split(".")
    s = float(t[0])
    ms = float(t[1])
    return h * 60 * 60 * 100 + m * 60 * 100 + s * 100 + ms

def interpolate_data(original_data):
    data_interpolate = np.copy(original_data)

    # 对数据进行插值处理
    for j in range(original_data.shape[1]):
        series = pd.Series(original_data[:, j])
        series.interpolate(method='linear', inplace=True)
        data_interpolate[:, j] = series.values

    return data_interpolate


with open("./csi_data.pkl", 'rb') as f:
    csi = pickle.load(f)

for data in csi:
    csi_time=data['csi_time']
    local_time=data['csi_local_time']
    magnitude=data['magnitude']
    phase=data['phase']
    people=data['people']

    last_local=None
    last_glob=None
    current_magnitude=[]
    current_phase=[]
    current_timestamp=[]
    global_timestamp=[]
    for i in range(len(csi_time)):
        if last_local is None:
            last_local=local_time[i]
            last_glob=process_time(csi_time[i])
            current_magnitude.append(magnitude[i])
            current_phase.append(phase[i])
            current_timestamp.append(local_time[i])
        else:
            local = local_time[i]
            glob = process_time(csi_time[i])
            num=round((local-last_local-loacl_gap)/loacl_gap)
            if num>0:
                delta=(local-last_local)/(num+1)
                delta_glob=(glob-last_glob)/(num+1)
                for j in range(num):
                    current_magnitude.append(pad)
                    current_phase.append(pad)
                    current_timestamp.append(current_timestamp[-1] + delta)
                    global_timestamp.append(global_timestamp[-1]+delta_glob)
            current_magnitude.append(magnitude[i])
            current_phase.append(phase[i])
            current_timestamp.append(local)
            global_timestamp.append(glob)
            last_local = local
            last_glob = glob


    current_magnitude = np.array(current_magnitude)
    current_magnitude[current_magnitude == -1000] = np.nan
    current_magnitude = interpolate_data(current_magnitude)
    print(len(current_magnitude))


    result.append({
        'time': np.array(current_timestamp),
        'global_time': np.array(global_timestamp),
        'people': people,
        'magnitude': current_magnitude,
        'phase': np.array(current_phase)
    })

output_file = './data_sequence_linear.pkl'
with open(output_file, 'wb') as f:
    pickle.dump(result, f)