From 1cba40a960965fb3ffeb3bee8635c2c899001d6b Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 22 Jan 2015 16:29:41 +0100 Subject: 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 : dictionary of frequencies The data in this file will be loaded by the tutor app and used for generating hints. --- monkey/edits.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'monkey') 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')) -- cgit v1.2.1