summaryrefslogtreecommitdiff
path: root/monkey
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-02-25 16:06:51 +0100
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-02-25 16:06:51 +0100
commitb0033953c1f7677a30471692d93d2e669b0aeecc (patch)
tree33a97acbfb47339165680102ef2a3cea3066cd9f /monkey
parent8077d4729f0a148e2832f1bab3980c019d1a3191 (diff)
Update monkey.action parser
Diffstat (limited to 'monkey')
-rw-r--r--monkey/action.py30
1 files changed, 23 insertions, 7 deletions
diff --git a/monkey/action.py b/monkey/action.py
index 2ea311c..43747b0 100644
--- a/monkey/action.py
+++ b/monkey/action.py
@@ -16,6 +16,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import sys
+
class Action:
def __init__(self, abstime, data):
self.type = data['typ']
@@ -35,13 +37,28 @@ class Action:
self.text = data['txt']
self.length = len(self.text)
elif self.type == 'test':
- self.feedback = data['feedback']
+ # data['feedback'] is a 'test_results' hint object, or a list
+ # containing such hint
+ hint = None
+ if isinstance(data['feedback'], list):
+ for hint in data['feedback']:
+ if hint['id'] == 'test_results':
+ break
+ else:
+ hint = data['feedback']
+ if hint is not None:
+ self.n_correct = hint['args']['passed']
+ self.n_all = hint['args']['total']
+ else:
+ self.n_correct = self.n_all = None
elif self.type == 'hint':
self.feedback = data['feedback']
elif self.type == 'hnt':
# obsolete Prolog hint action, with no additional info
self.type = 'hint'
self.feedback = None
+ elif self.type == 'plan':
+ self.index = data.get('index')
# Prolog actions
elif self.type == 'prolog_solve':
@@ -66,17 +83,15 @@ class Action:
if self.type in {'insert', 'remove'}:
s += ' "' + self.text.replace('\n', '\\n').replace('\t', '\\t') + '" at ' + str(self.offset)
elif self.type == 'test':
- if self.feedback is not None:
- for hint in self.feedback:
- if hint['id'] == 'test_results':
- args = hint['args']
- s += ' {0} / {1}'.format(args['passed'], args['total'])
- break
+ s += ' {0} / {1}'.format(self.n_correct, self.n_all)
elif self.type == 'hint':
if self.feedback is not None:
s += ' ' + ', '.join(sorted([hint['id'] for hint in self.feedback]))
else:
s += ' ?'
+ elif self.type == 'plan':
+ if self.index is not None:
+ s += ' ' + str(self.index)
elif self.type == 'prolog_solve':
s += ' "' + self.query + '"'
return s
@@ -116,6 +131,7 @@ def parse(data):
action = Action(time, packet)
except:
# ignore any errors while decoding a packet
+ sys.stderr.write('Error decoding packet: {}'.format(packet))
continue
# skip normalization if this is the first action