From 37882ddb65ba010c060afb799b31f39684da9b1f Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sun, 16 Apr 2017 12:40:32 +0200 Subject: Export rules in a JSON file for CodeQ --- test-rules.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test-rules.py b/test-rules.py index 8762cdd..d129eef 100755 --- a/test-rules.py +++ b/test-rules.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 import collections +import json import os.path import pickle import re @@ -47,6 +48,7 @@ attributes_file = os.path.join(data_dir, 'attributes.tab') rules_file = os.path.join(data_dir, 'rules.txt') users_file = os.path.join(data_dir, 'users-test.txt') programs_file = os.path.join(data_dir, 'programs.pickle') +json_file = os.path.join(data_dir, 'bugs.json') pid = int(open(pid_file, 'r').read().strip()) # read test results for known programs @@ -71,10 +73,23 @@ for line in open(rules_file, 'r').readlines(): m = tuple(match.groups()) condition = tuple(attributes[field[:-3]] for field in m[0].split(' AND ')) rules.append(Rule(m[-4], condition, (int(m[-3]), int(m[-2])), float(m[-1]))) - #print(rules[-1]) else: print('Did not understand rule:', line.strip()) +json_data = { + 'patterns': attributes_ordered, + 'rules': [{ + 'condition': r.condition, + 'class': r.klass == 'T', + 'distribution': r.distribution, + 'quality': r.quality, + } for r in rules], +} + +# export rules for tutor +with open(json_file, 'w') as f: + json.dump(json_data, f, sort_keys=True, indent=2) + def color_print(text, ranges): i = 0 for start, length, color in sorted(ranges): -- cgit v1.2.1