-
Notifications
You must be signed in to change notification settings - Fork 2
/
sample_table.py
executable file
·46 lines (31 loc) · 1.42 KB
/
sample_table.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
#!/usr/bin/env python
import sys, argparse, json
# prints a line to standard error
def print_err(data):
sys.stderr.write(str(data)+'\n')
def main(args):
print_err('loading: {}'.format(args.sample_data))
with open(args.sample_data) as file:
data = json.load(file)
if not args.raw_data:
header = ['num_occurrences'] + data['variable_ids']
print(', '.join([str(x) for x in header]))
for solution_data in data['solutions']:
row = [solution_data['num_occurrences']] + solution_data['solution']
print(', '.join([str(x) for x in row]))
else:
header = ['batch'] + data['variable_ids']
print(', '.join([str(x) for x in header]))
for solution_data in data['solutions']:
row = [solution_data['batch']] + solution_data['solution']
print(', '.join([str(x) for x in row]))
if solution_data['num_occurrences'] > 1:
print_err('printing raw data but num_occurrences of {} found'.format(solution_data['num_occurrences']))
def build_cli_parser():
parser = argparse.ArgumentParser()
parser.add_argument('sample_data', help='a data file to operate on (.json)')
parser.add_argument('-raw', '--raw-data', help='collect sample streams rather than histograms', action='store_true', default=False)
return parser
if __name__ == '__main__':
parser = build_cli_parser()
main(parser.parse_args())