| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
import sys |
| 4 |
import argparse |
| 5 |
import json |
| 6 |
|
| 7 |
def extract_field(j,path): |
| 8 |
for elem in path: |
| 9 |
j = j[elem] |
| 10 |
return j |
| 11 |
|
| 12 |
parser = argparse.ArgumentParser(description="Average piecewise-constant function") |
| 13 |
parser.add_argument("filename",type=str,help="File containing JSON log") |
| 14 |
parser.add_argument("path",type=str,help="Maximum percentags of Ns allowed") |
| 15 |
|
| 16 |
args = parser.parse_args() |
| 17 |
|
| 18 |
filename = args.filename |
| 19 |
|
| 20 |
path = args.path.split('/') |
| 21 |
for i in range(0,len(path)): |
| 22 |
if i < len(path)-1: |
| 23 |
path[i] = path[i]+'/' |
| 24 |
|
| 25 |
with open(filename,'r',encoding='utf8') as file: |
| 26 |
next(file,None) |
| 27 |
for line in file: |
| 28 |
j = json.loads(line) |
| 29 |
print(json.dumps(extract_field(j,path))) |
| 30 |
|
| 31 |
|