-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnormalizer.py
More file actions
34 lines (28 loc) · 898 Bytes
/
normalizer.py
File metadata and controls
34 lines (28 loc) · 898 Bytes
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
import fileinput
import argparse
import json
import os
parser = argparse.ArgumentParser()
parser.add_argument("input_filename")
args = parser.parse_args()
a = {}
t = {}
fout = open("%s_NORMALIZED.json" % os.path.splitext(args.input_filename)[0],"wb")
with open(args.input_filename) as data_file:
data = json.load(data_file)
for idx,val in enumerate(data):
if idx==0:
fout.write('[')
if val['name'] not in t:
t[val['name']] = val['timestamp']
if idx==0:
fout.write(json.dumps(val))
else:
fout.write(','+json.dumps(val))
if val['name'] not in a:
a[val['name']] = val['timestamp']
else:
if val['timestamp'] - a[val['name']] > 1:
fout.write(','+json.dumps(val))
a[val['name']] = val['timestamp']
fout.write(']')