-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_processing.py
93 lines (85 loc) · 3.39 KB
/
data_processing.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
import numpy as np
modes = [['24C', '27C', '30C'], \
['50perc', '75perc', '100perc'], \
['rack1', 'rack2']]
racks = [[10, 20, 22, 24, 28, 30, 34, 36], \
[13, 18, 22, 24, 28, 30]]
wf = None
nonzeros = 0
dimensions = [0, 0, 0, 0]
entries = {}
def readAirCon(i, j, k, filename):
global wf, nonzeros, dimensions, entries
with open(filename, mode='r') as rf:
for _, line in enumerate(rf):
if line[0] == '#':
continue
time, T = [float(t) for t in line.split(' ')]
time = int(time + 0.5)
idx = (i+1, j+1, k+1, time)
entry = '{0[0]}\t{0[1]}\t{0[2]}\t{0[3]}\t{1}\n'.format(idx, T)
# wf.write(entry)
entries[idx] = entry
nonzeros = nonzeros + 1
dimensions = np.maximum(dimensions, idx)
print(filename, '...done!')
rf.close()
def readProbe(i, j, filename):
global wf, nonzeros, dimensions, entries
with open(filename, mode='r') as rf:
for _, line in enumerate(rf):
if line[0] == '#':
continue
T = [float(t) for t in line.split()]
time = int(T[0] + 0.5)
for k in range(4):
idx = (i+1, j+1, k+3, time)
entry = '{0[0]}\t{0[1]}\t{0[2]}\t{0[3]}\t{1}\n'.format(idx, T[k+1])
# wf.write(entry)
entries[idx] = entry
nonzeros = nonzeros + 1
dimensions = np.maximum(dimensions, idx)
print(filename, '...done!')
rf.close()
def readRack(i, j, k, filename):
global wf, nonzeros, dimensions, entries
with open(filename, mode='r') as rf:
for _, line in enumerate(rf):
if line[0] == '#':
continue
time, T = [float(t) for t in line.split('\t')]
time = int(time + 0.5)
idx = (i+1, j+1, k+1, time)
entry = '{0[0]}\t{0[1]}\t{0[2]}\t{0[3]}\t{1}\n'.format(idx, T)
# wf.write(entry)
entries[idx] = entry
nonzeros = nonzeros + 1
dimensions = np.maximum(dimensions, idx)
print(filename, '...done!')
rf.close()
if __name__ == '__main__':
wf = open('ServerRoomCFD.tensor', mode='w')
for i in range(len(modes[0])):
for j in range(len(modes[1])):
filename = 'original/' + modes[0][i] + '/' + modes[1][j] + '/aircon_Inlet.dat'
readAirCon(i, j, 0, filename)
filename = 'original/' + modes[0][i] + '/' + modes[1][j] + '/aircon_Outlet.dat'
readAirCon(i, j, 1, filename)
filename = 'original/' + modes[0][i] + '/' + modes[1][j] + '/probes.dat'
readProbe(i, j, filename)
for k in range(len(modes[2])):
filename = 'original/' + modes[0][i] + '/' + modes[1][j] + '/' + modes[2][k]
for l in range(len(racks[k])):
filename1 = filename + '/' + str(racks[k][l]) + '_Inlet_0.dat'
readRack(i, j, 6+(k*len(racks[0])+l)*2, filename1)
filename2 = filename + '/' + str(racks[k][l]) + '_Outlet_0.dat'
readRack(i, j, 6+(k*len(racks[0])+l)*2 + 1, filename2)
print()
print()
print('dimensions', dimensions)
print('nonzeros:', nonzeros)
print()
for idx in entries:
wf.write(entries[idx])
print('Created ServerRoomCFD.tensor', '...done!\n')
wf.close()