-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjson_export.py
executable file
·47 lines (38 loc) · 1.51 KB
/
json_export.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Convert NavigaTor measurements to JSON format.
"""
# Author: Robert Annessi <robert.annessi@nt.tuwien.ac.at>
# License: GPLv2 (2015-2016)
from cPickle import load
from json import dumps
from argparse import ArgumentParser
from os.path import exists
from r9 import Probestat
def _main():
parser = ArgumentParser(description="")
parser.add_argument("--input", type=str, required=True, help="Input file.")
parser.add_argument("--output", type=str, required=True,
help="Output file.")
args = parser.parse_args()
assert exists(args.input), 'Non-existing input file.'
assert not exists(args.output), 'Existing output file.'
with open(args.input, 'r') as f:
with open(args.output, 'w') as g:
try:
while True:
probe = load(f)
date = str(probe.date)
bw = None
if len(probe.bws) > 0 and isinstance(probe.bws[0], int):
bw = 5242880/(probe.bws[0]/1000.0)*8/1024/1024
g.write(dumps((date, probe.entry, probe.middle, probe.exit,
probe.cbt, probe.cbtp, probe.cbtb,
probe.rtts, probe.rttp, probe.rttb,
probe.ttfbs, bw, probe.cong, probe.congp,
probe.congb))+'\n')
except EOFError:
pass
if __name__ == '__main__':
_main()