-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathm_dense.py
125 lines (109 loc) · 4.15 KB
/
m_dense.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
# link: https://github.com/rdemedrano/crann_traffic
import pandas as pd
import json
import util
outputdir = 'output/M_DENSE'
util.ensure_dir(outputdir)
dataurl = 'input/M_DENSE/'
dataname = outputdir+'/M_DENSE'
month_to_day_num = [
31, 59, 90, 120,
151, 181, 212, 243,
273, 304, 334, 365
]
def id_to_time(id):
global month_to_day_num
year_index = int(id / (365 * 24))
year = 2018 + year_index
year_day_index = int((id - 365 * 24 * year_index) / 24)
month_index = 0
for i in range(12):
if month_to_day_num[i] > year_day_index:
month_index = i
break
month = 1 + month_index
day_index = year_day_index - month_to_day_num[month_index-1] if month_index > 0 else year_day_index
day = 1 + day_index
hour = int(id - 365 * 24 * year_index - 24 * year_day_index)
min = 0
sec = 0
return str(year).zfill(4) + "-" + str(month).zfill(2) + "-" + str(day).zfill(2) + \
"T" + str(hour).zfill(2) + ":" + str(min).zfill(2) + ":" + str(sec).zfill(2) + "Z"
old_dataset = pd.read_csv(dataurl+'data/dense_data.csv', header=None)
sensor_num = 30
timeid_num = old_dataset.shape[0]
dataset = []
for i in range(timeid_num):
datas = old_dataset[0][i].split(' ')
datas = [eval(data) for data in datas]
dataset.append(datas)
geo = []
for i in range(sensor_num):
id = i
geo.append([id, 'Point', '[]'])
geo = pd.DataFrame(geo, columns=['geo_id', 'type', 'coordinates'])
geo.to_csv(dataname + '.geo', index=False)
dyna_id = 0
dyna_file = open(dataname+'.dyna', 'w')
dyna_file.write('dyna_id' + ',' + 'type' + ',' + 'time' + ',' + 'entity_id' + ',' + 'traffic_intensity' + '\n')
for j in range(sensor_num):
entity_id = j
for i in range(timeid_num):
time = id_to_time(i)
dyna_file.write(str(dyna_id) + ',' + 'state' + ',' + str(time)
+ ',' + str(entity_id) + ',' + str(dataset[i][j]) + '\n')
dyna_id = dyna_id + 1
if dyna_id % 10000 == 0:
print(str(dyna_id) + '/' + str(sensor_num * timeid_num))
dyna_file.close()
ext_id = 0
ext_file = open(dataname + '.ext', 'w')
ext_file.write('ext_id' + ',' + 'time' + ',' +
'mean' + ',' + 'wind_speed' + ',' +
'temperature' + ',' + 'humidity' + ',' +
'pressure' + ',' + 'radiation' + ',' +
'precipitation' + '\n')
for i in range(timeid_num):
time = id_to_time(i)
mean = dataset[i][sensor_num + 0]
wind_speed = dataset[i][sensor_num + 1]
temperature = dataset[i][sensor_num + 2]
humidity = dataset[i][sensor_num + 3]
pressure = dataset[i][sensor_num + 4]
radiation = dataset[i][sensor_num + 5]
precipitation = dataset[i][sensor_num + 6]
ext_file.write(str(ext_id) + ',' + str(time) + ',' +
str(mean) + ',' + str(wind_speed) + ',' +
str(temperature) + ',' + str(humidity) + ',' +
str(pressure) + ',' + str(radiation) + ',' +
str(precipitation) + '\n')
ext_id += 1
ext_file.close()
config = dict()
config['geo'] = dict()
config['geo']['including_types'] = ['Point']
config['geo']['Point'] = {}
config['dyna'] = dict()
config['dyna']['including_types'] = ['state']
config['dyna']['state'] = {'entity_id': 'geo_id', 'traffic_intensity': 'num'}
config['ext'] = {
'ext_id': 'num', 'time': 'other',
'mean': 'num', 'wind_speed': 'num',
'temperature': 'num', 'humidity': 'num',
'pressure': 'num', 'radiation': 'num',
'precipitation': 'num'
}
config['info'] = dict()
config['info']['data_col'] = 'traffic_intensity'
config['info']['ext_col'] = ['mean', 'wind_speed', 'temperature', 'humidity',
'pressure', 'radiation', 'precipitation']
config['info']['data_files'] = ['M_DENSE']
config['info']['geo_file'] = 'M_DENSE'
config['info']['ext_file'] = 'M_DENSE'
config['info']['output_dim'] = 1
config['info']['time_intervals'] = 3600
config['info']['init_weight_inf_or_zero'] = 'inf'
config['info']['set_weight_link_or_dist'] = 'dist'
config['info']['calculate_weight_adj'] = False
config['info']['weight_adj_epsilon'] = 0.1
json.dump(config, open(outputdir+'/config.json', 'w', encoding='utf-8'), ensure_ascii=False)