-
Notifications
You must be signed in to change notification settings - Fork 4
/
data_loader.py
137 lines (127 loc) · 4.15 KB
/
data_loader.py
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import h5py
from Analysis import *
import os
#For deep learning
class Database_processing:
def __init__(self,Database_Name,Database_Label,Dir_List):
self.Database_Name = Database_Name #string
self.Database_Label = Database_Label #list
self.Dir_List = Dir_List #list
self.DataBox = [] #list
def Create_New_Database(self):
count = 0
f = h5py.File(self.Database_Name + ".h5", "w")
for dirname_dir in self.Dir_List:
data = self.Load_CSI(dirname_dir)
f.create_dataset(self.Database_Label[count],data=data)
count = count + 1
f.flush
f.close
f.close
def Create_New_Database_CSI_phase(self):
count = 0
f = h5py.File(self.Database_Name + ".h5", "w")
for dirname_dir in self.Dir_List:
data = self.Load_CSI_phase(dirname_dir)
f.create_dataset(self.Database_Label[count],data=data)
count = count + 1
f.flush
f.close
f.close
def Create_New_Database_RSSI(self):
count = 0
f = h5py.File(self.Database_Name + ".h5", "w")
for dirname_dir in self.Dir_List:
data = self.Load_RSSI(dirname_dir)
f.create_dataset(self.Database_Label[count],data=data)
count = count + 1
f.flush
f.close
f.close
def Load_CSI(self,Dir_name):
file_list = os.listdir(Dir_name)
Box = []
#Muilt file
for filename in file_list:
#Check direction
if(os.path.isfile==False):
continue
CSI = CSI_get(Dir_name+'\\'+filename)
#Check quantity
Packet_quan = CSI.Check_Effection_Packet()
print(Dir_name+'\\'+filename)
for CSI_number in Packet_quan:
try:
result = CSI.Get_CSI_Q(CSI_number)
if(type(result)==type(1)):
continue
Box.append(result)
except:
continue
return Box
def Load_CSI_phase(self,Dir_name):
file_list = os.listdir(Dir_name)
Box = []
#Muilt file
for filename in file_list:
#Check direction
if(os.path.isfile==False):
continue
CSI = CSI_get(Dir_name+'\\'+filename)
#Check quantity
Packet_quan = CSI.Check_Effection_Packet()
print(Dir_name+'\\'+filename)
for CSI_number in Packet_quan:
try:
result = CSI.Get_CSI_Ang(CSI_number)
if(type(result)==type(1)):
continue
Box.append(result)
except:
continue
return Box
def Load_RSSI(self,Dir_name):
file_list = os.listdir(Dir_name)
Box = []
print("Initial..")
#Muilt file
for filename in file_list:
#Check direction
if(os.path.isfile==False):
continue
RSSI = CSI_get(Dir_name+'\\'+filename)
#Check quantity
Packet_quan = RSSI.Check_Effection_Packet()
print(Dir_name+'\\'+filename)
for CSI_number in Packet_quan:
try:
result = RSSI.Get_RSSI(CSI_number)
if(type(result)==type(1)):
continue
Box.append(result)
except:
continue
return Box
if __name__ == '__main__':
'''
Create Database_processing object
Argumnet:
Database_Name: Database's name->string,
Database_Label: Every h5's name->list,
Dir_List: where is dat file->list,
File structure example:
root dirname
-1
-- one.dat
-- two.dat
-2
-- one.dat
-- two.dat
'''
label = []
dirlist = []
for label_index in range(1,2):
label.append(str(label_index))
dirlist.append("Z:\\root dirname\\"+str(label_index))
DP = Database_processing("CSI",label,dirlist)
DP.Create_New_Database()