summaryrefslogtreecommitdiff
path: root/test-rules.py
diff options
context:
space:
mode:
Diffstat (limited to 'test-rules.py')
-rwxr-xr-xtest-rules.py17
1 files changed, 16 insertions, 1 deletions
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):