-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadMetrics.py
48 lines (37 loc) · 1007 Bytes
/
loadMetrics.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
import os
import json
from uncertainties import ufloat
def main():
filesToProcess = set()
paths = os.listdir('.')
for p in paths:
if os.path.isfile(p) and p.endswith('.json'):
filesToProcess.add(p)
for file in filesToProcess:
# Open input file
inputFile = open(file, 'r')
# Copy lines of input file to variable
lines = inputFile.readlines()
# Close input file
inputFile.close()
# Output data
output = {}
for line in lines:
data = json.loads(line)
for key in data:
if type(data[key]) is dict:
output[key] = {}
for measurementKey in list(data[key].keys()):
value = data[key][measurementKey]
if len(value) > 1:
output[key][measurementKey] = ufloat(value[0], value[1])
else:
output[key][measurementKey] = ufloat(value[0])
else:
output[key] = data[key]
# dataName = input('Data name (identifer): ')
# output = {dataName: output}
print(file.rstrip('json'))
print(output)
if __name__ == '__main__':
main()