summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--monkey/edits.py34
-rwxr-xr-xmonkey/test.py6
2 files changed, 21 insertions, 19 deletions
diff --git a/monkey/edits.py b/monkey/edits.py
index cf2bc66..f34f4b4 100644
--- a/monkey/edits.py
+++ b/monkey/edits.py
@@ -8,13 +8,13 @@ from .graph import Node
from prolog.util import normalized, rename_vars, stringify, tokenize
from .util import get_line, avg, logistic
-# A line edit is a contiguous sequences of actions within a single line. This
-# function takes a sequence of actions and builds a directed acyclic graph
-# where each edit represents one line edit and each node represents a version
-# of some line. The function returns a list of nodes (first element is the
-# root), and sets of submissions (program versions tested by the user) and
-# queries in this attempt.
-def edit_graph(actions, debug=False):
+# Parse the sequence of actions in [trace] and return a directed acyclic graph
+# representing development history. Each node represents a particular version
+# of some line, and each edge represents a "line edit" (contiguous sequence of
+# inserts/removes within a single line).
+# Return a list of nodes (first element is the root), and sets of submissions
+# (program versions tested by the user) and queries in this attempt.
+def trace_graph(trace, debug=False):
# Return values.
nodes = [Node([0, 0, ()])] # Node data: rank (Y), line no. (X), and tokens.
submissions = set() # Program versions at 'test' actions.
@@ -26,8 +26,15 @@ def edit_graph(actions, debug=False):
code_next = '' # Program code after applying the current action.
done = False # Set to True on first correct version.
- # Ensure there is a separate action for each inserted/removed character.
- expand(actions)
+ # Parse trace actions and ensure there is a separate action for each
+ # inserted/removed character.
+ try:
+ actions = parse(trace)
+ expand(actions)
+ except:
+ # Only a few traces fail to parse, so just skip them.
+ actions = []
+
for action_id, action in enumerate(actions):
code = code_next
code_next = action.apply(code)
@@ -164,12 +171,7 @@ def get_edits_from_traces(traces):
n_all = collections.Counter()
for trace in traces:
- try:
- actions = parse(trace)
- except:
- # Only a few traces fail to parse, so just ignore them.
- continue
- nodes, trace_submissions, trace_queries = edit_graph(actions)
+ nodes, trace_submissions, trace_queries = trace_graph(trace)
# Update the submissions/queries counters (use normalized variables).
for submission in trace_submissions:
@@ -190,7 +192,7 @@ def get_edits_from_traces(traces):
end = normalized(path[i], var_names)
# Disallow edits that insert a whole rule (a → … :- …).
- # TODO improve edit_graph to handle this.
+ # TODO improve trace_graph to handle this.
if 'FROM' in [t.type for t in end[:-1]]:
continue
diff --git a/monkey/test.py b/monkey/test.py
index eb91e3c..4b0d192 100755
--- a/monkey/test.py
+++ b/monkey/test.py
@@ -8,7 +8,7 @@ import django
from termcolor import colored
from .action import parse
-from .edits import classify_edits, edit_graph, get_edits_from_traces
+from .edits import classify_edits, trace_graph, get_edits_from_traces
from .graph import graphviz
from .monkey import fix
from prolog.engine import test
@@ -131,9 +131,9 @@ elif len(sys.argv) >= 3 and sys.argv[2] == 'info':
elif len(sys.argv) == 4 and sys.argv[2] == 'graph':
uid = int(sys.argv[3])
user = User.objects.get(pk=uid)
- actions = parse(Attempt.objects.get(problem=problem, user=user).trace)
+ attempt = Attempt.objects.get(problem=problem, user=user)
- nodes, submissions, queries = edit_graph(actions)
+ nodes, submissions, queries = trace_graph(attempt.trace)
def position(node):
return (node.data[1]*150, node.data[0]*-60)