-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate_timeseries.py
42 lines (32 loc) · 1.23 KB
/
create_timeseries.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
import json
import os
from analysis.util import mean, tosec
from glob import glob
folder_path = './data/jmh'
root_folder = './data/timeseries'
timeseries_folder = '{}/all'.format(root_folder)
for dir_ in [root_folder, timeseries_folder]:
if not os.path.exists(dir_):
os.mkdir(dir_)
def toseries(fork, scoreUnit):
series = map(mean, fork)
series = map(lambda x: tosec(x, scoreUnit), series)
return list(series)
def create_timeseries():
for path in glob("{}/*.json".format(folder_path)):
out_path = "{}/{}".format(timeseries_folder, path.split('/')[-1])
if os.path.exists(out_path):
print('Skipped:', out_path, 'already exists')
continue
try:
with open(path) as f:
data = json.load(f)
rawDataHistogram = data[0]['primaryMetric']['rawDataHistogram']
scoreUnit = data[0]['primaryMetric']['scoreUnit']
timeseries = [toseries(fork, scoreUnit) for fork in rawDataHistogram]
with open(out_path, mode='w') as f:
json.dump(timeseries, f)
except json.JSONDecodeError:
print('Skipped', path, 'for JSONDecodeError')
if __name__ == '__main__':
create_timeseries()