summaryrefslogtreecommitdiff
path: root/monkey
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2015-01-22 16:29:41 +0100
committerAleš Smodiš <aless@guru.si>2015-08-11 14:26:01 +0200
commit1cba40a960965fb3ffeb3bee8635c2c899001d6b (patch)
tree71e1a4d1963005b4dfe92056e335330dbe640abf /monkey
parent9763725d157003b02417a37e49788b5a8683f46a (diff)
Pickle frequent edits when calling monkey.edits
Resulting file contains a 4-tuple with edit, line, submission and query frequencies. Each element of the tuple is a dictionary of the form <pid>: dictionary of frequencies The data in this file will be loaded by the tutor app and used for generating hints.
Diffstat (limited to 'monkey')
-rw-r--r--monkey/edits.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/monkey/edits.py b/monkey/edits.py
index 349ebf7..58843f6 100644
--- a/monkey/edits.py
+++ b/monkey/edits.py
@@ -305,3 +305,25 @@ def clean_graph(nodes):
break
diff += 1
node.data[0] -= diff
+
+if __name__ == '__main__':
+ import os
+ import pickle
+ import django
+
+ # Load django models.
+ os.environ['DJANGO_SETTINGS_MODULE'] = 'webmonkey.settings'
+ django.setup()
+ from django.contrib.auth.models import User
+ from tutor.models import Attempt, Problem
+
+ edits = {}
+ lines = {}
+ submissions = {}
+ queries = {}
+ for problem in Problem.objects.all():
+ pid = problem.pk
+ traces = [a.trace for a in Attempt.objects.filter(problem=problem, done=True)]
+ edits[pid], lines[pid], submissions[pid], queries[pid] = get_edits_from_traces(traces)
+
+ pickle.dump((edits, lines, submissions, queries), open('edits.pickle', 'wb'))