File size: 3,303 Bytes
2d3ff87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
92
93
94
95
96
97
98
import numpy as np
import pickle
import copy

def get_time(s):
    s=s.split()[-1]
    s=s.split(":")
    h=float(s[0])
    m=float(s[1])
    t=float(s[2])
    total=h*3600+m*60+t
    return h,m,t,total

gap=1
length=gap*100
pad=[-1000]*52
action_list=[]
people_list=[]
timestamp=[]
magnitudes=[]
phases=[]
loacl_gap=10000


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['volunteer_id']
    action=data['action_id']
    start_time=None
    last_local=None
    current_magnitude=[]
    current_phase=[]
    current_timestamp=[]
    for i in range(len(csi_time)):
        _, _, _, current_time = get_time(csi_time[i])
        if start_time is None or current_time-start_time>gap:
            if start_time is not None:
                if len(current_magnitude)>=length:
                    current_magnitude=current_magnitude[:length]
                    current_phase=current_phase[:length]
                    current_timestamp=current_timestamp[:length]
                else:
                    add=length-len(current_magnitude)
                    delta=(current_timestamp[0]+length*loacl_gap-current_timestamp[-1])/add
                    for j in range(add):
                        current_magnitude.append(pad)
                        current_phase.append(pad)
                        current_timestamp.append(current_timestamp[-1]+delta)
                magnitudes.append(copy.deepcopy(current_magnitude))
                phases.append(copy.deepcopy(current_phase))
                timestamp.append(copy.deepcopy(current_timestamp))
                action_list.append(action)
                people_list.append(people)
                current_magnitude = []
                current_phase = []
                current_timestamp = []
            start_time=current_time
            last_local=local_time[i]
            current_magnitude.append(magnitude[i])
            current_phase.append(phase[i])
            current_timestamp.append(local_time[i])
        else:
            local = local_time[i]
            num=round((local-last_local-loacl_gap)/loacl_gap)
            if num>0:
                delta=(local-last_local)/(num+1)
                for j in range(num):
                    current_magnitude.append(pad)
                    current_phase.append(pad)
                    current_timestamp.append(current_timestamp[-1] + delta)
            current_magnitude.append(magnitude[i])
            current_phase.append(phase[i])
            current_timestamp.append(local_time[i])
            last_local=local


action_list=np.array(action_list)
people_list=np.array(people_list)
timestamp=np.array(timestamp)
magnitudes=np.array(magnitudes)
phases=np.array(phases)
print(action_list.shape)
print(people_list.shape)
print(timestamp.shape)
print(magnitudes.shape)
print(phases.shape)
np.save("./magnitude.npy", np.array(magnitudes))
np.save("./phase.npy", np.array(phases))
np.save("./action.npy", np.array(action_list))
np.save("./people.npy", np.array(people_list))
np.save("./timestamp.npy", np.array(timestamp))