summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmonkey/action.py24
-rw-r--r--monkey/edits.py1
2 files changed, 15 insertions, 10 deletions
diff --git a/monkey/action.py b/monkey/action.py
index 403c015..f47cbb8 100755
--- a/monkey/action.py
+++ b/monkey/action.py
@@ -1,7 +1,7 @@
#!/usr/bin/python3
class Action:
- # type ∈ ['remove', 'insert', 'solve', 'solve_all']
+ # type ∈ ['insert', 'remove', 'solve', 'solve_all', 'next', 'stop', 'test', 'hint']
# time: absolute elapsed time since the attempt started, in ms
# offset: position of the first inserted/removed character
# text: inserted/removed text or query
@@ -66,7 +66,7 @@ def parse(data):
dt = int(((data[i] << 8) + (data[i+1])) * 100.0)
time += dt
i += 2
- if type == 1: # insert
+ if type == 1: # insert
offset = (data[i] << 8) + data[i+1]
i += 2
length = (data[i] << 8) + data[i+1]
@@ -74,26 +74,32 @@ def parse(data):
text = data[i:i+length].decode()
i += length
action = Action('insert', time, offset=offset, text=text)
- elif type == 2: # remove
+ elif type == 2: # remove
offset = (data[i] << 8) + data[i+1]
i += 2
length = (data[i] << 8) + data[i+1]
i += 2
text = code[offset:offset+length]
action = Action('remove', time, offset=offset, text=text)
- elif type == 3 or type == 4: # solve / solve all
+ elif type == 3 or type == 4: # solve / solve all
length = (data[i] << 8) + data[i+1]
i += 2
query = data[i:i+length].decode()
i += length
act_type = 'solve' + ('_all' if type == 4 else '')
action = Action(act_type, time, text=query)
- elif type == 8: # test
+ elif type == 5: # next solution
+ action = Action('next', time)
+ elif type == 7: # stop/end
+ action = Action('stop', time)
+ elif type == 8: # test
total = data[i]
i += 1
passed = data[i]
i += 1
action = Action('test', time, total=total, passed=passed)
+ elif type == 9: # hint
+ action = Action('hint', time)
else:
# unsupported action type
continue
@@ -243,13 +249,13 @@ if __name__ == '__main__':
problem = Problem.objects.get(pk=pid)
# print all attempt ids for the selected problem
- print('attempts for problem ' + str(pid) + ':')
+ print('users solving problem ' + str(pid) + ':')
attempts = Attempt.objects.filter(problem=problem)
- print(', '.join([str(attempt.pk) for attempt in attempts]))
+ print(', '.join([str(attempt.user_id) for attempt in attempts]))
print()
- aid = input('enter attempt id: ')
- attempt = Attempt.objects.get(pk=aid)
+ uid = input('enter user id: ')
+ attempt = Attempt.objects.get(problem_id=pid, user_id=uid)
try:
actions = parse(attempt.trace)
diff --git a/monkey/edits.py b/monkey/edits.py
index 15734c4..1b5633d 100644
--- a/monkey/edits.py
+++ b/monkey/edits.py
@@ -175,7 +175,6 @@ def get_edits_from_traces(traces):
for submission in trace_submissions:
code = stringify(rename_vars(tokenize(submission)))
submissions[code] += 1
-
for query in trace_queries:
code = stringify(rename_vars(tokenize(query)))
queries[code] += 1