Remove unused fixtures
This commit is contained in:
committed by
Calen Pennington
parent
79a029ce9a
commit
4a835433ab
@@ -1,98 +0,0 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
import sys
|
||||
import json
|
||||
import random
|
||||
import copy
|
||||
from collections import defaultdict
|
||||
from argparse import ArgumentParser, FileType
|
||||
from datetime import datetime
|
||||
|
||||
def generate_user(user_number):
|
||||
return {
|
||||
"pk": user_number,
|
||||
"model": "auth.user",
|
||||
"fields": {
|
||||
"status": "w",
|
||||
"last_name": "Last",
|
||||
"gold": 0,
|
||||
"is_staff": False,
|
||||
"user_permissions": [],
|
||||
"interesting_tags": "",
|
||||
"email_key": None,
|
||||
"date_joined": "2012-04-26 11:36:39",
|
||||
"first_name": "",
|
||||
"email_isvalid": False,
|
||||
"avatar_type": "n",
|
||||
"website": "",
|
||||
"is_superuser": False,
|
||||
"date_of_birth": None,
|
||||
"last_login": "2012-04-26 11:36:48",
|
||||
"location": "",
|
||||
"new_response_count": 0,
|
||||
"email": "user{num}@example.com".format(num=user_number),
|
||||
"username": "user{num}".format(num=user_number),
|
||||
"is_active": True,
|
||||
"consecutive_days_visit_count": 0,
|
||||
"email_tag_filter_strategy": 1,
|
||||
"groups": [],
|
||||
"password": "sha1$90e6f$562a1d783a0c47ce06ebf96b8c58123a0671bbf0",
|
||||
"silver": 0,
|
||||
"bronze": 0,
|
||||
"questions_per_page": 10,
|
||||
"about": "",
|
||||
"show_country": True,
|
||||
"country": "",
|
||||
"display_tag_filter_strategy": 0,
|
||||
"seen_response_count": 0,
|
||||
"real_name": "",
|
||||
"ignored_tags": "",
|
||||
"reputation": 1,
|
||||
"gravatar": "366d981a10116969c568a18ee090f44c",
|
||||
"last_seen": "2012-04-26 11:36:39"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def parse_args(args=sys.argv[1:]):
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument('-d', '--data', type=FileType('r'), default=sys.stdin)
|
||||
parser.add_argument('-o', '--output', type=FileType('w'), default=sys.stdout)
|
||||
parser.add_argument('count', type=int)
|
||||
return parser.parse_args(args)
|
||||
|
||||
|
||||
def main(args=sys.argv[1:]):
|
||||
args = parse_args(args)
|
||||
|
||||
data = json.load(args.data)
|
||||
unique_students = set(entry['fields']['student'] for entry in data)
|
||||
if args.count > len(unique_students) * 0.1:
|
||||
raise Exception("Can't be sufficiently anonymous selecting {count} of {unique} students".format(
|
||||
count=args.count, unique=len(unique_students)))
|
||||
|
||||
by_problems = defaultdict(list)
|
||||
for entry in data:
|
||||
by_problems[entry['fields']['module_id']].append(entry)
|
||||
|
||||
out_data = []
|
||||
out_pk = 1
|
||||
for name, answers in by_problems.items():
|
||||
for student_id in xrange(args.count):
|
||||
sample = random.choice(answers)
|
||||
data = copy.deepcopy(sample)
|
||||
data["fields"]["student"] = student_id + 1
|
||||
data["fields"]["created"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
data["fields"]["modified"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
data["pk"] = out_pk
|
||||
out_pk += 1
|
||||
out_data.append(data)
|
||||
|
||||
for student_id in xrange(args.count):
|
||||
out_data.append(generate_user(student_id))
|
||||
|
||||
json.dump(out_data, args.output, indent=2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -1 +0,0 @@
|
||||
[{"pk": 1, "model": "user.userprofile", "fields": {"name": "pm", "language": "pm", "courseware": "course.xml", "meta": "", "location": "pm", "user": 1}}, {"pk": 1, "model": "auth.user", "fields": {"status": "w", "last_name": "", "gold": 0, "is_staff": true, "user_permissions": [], "interesting_tags": "", "email_key": null, "date_joined": "2012-01-23 17:03:54", "first_name": "", "email_isvalid": false, "avatar_type": "n", "website": "", "is_superuser": true, "date_of_birth": null, "last_login": "2012-01-23 17:04:16", "location": "", "new_response_count": 0, "email": "pmitros@csail.mit.edu", "username": "pm", "is_active": true, "consecutive_days_visit_count": 0, "email_tag_filter_strategy": 1, "groups": [], "password": "sha1$a3e96$dbabbd114f0da01bce2cc2adcafa2ca651c7ae0a", "silver": 0, "bronze": 0, "questions_per_page": 10, "about": "", "show_country": false, "country": "", "display_tag_filter_strategy": 0, "seen_response_count": 0, "real_name": "", "ignored_tags": "", "reputation": 1, "gravatar": "7a591afd0cc7972fdbe5e12e26af352a", "last_seen": "2012-01-23 17:04:41"}}, {"pk": 1, "model": "user.userprofile", "fields": {"name": "pm", "language": "pm", "courseware": "course.xml", "meta": "", "location": "pm", "user": 1}}, {"pk": 1, "model": "auth.user", "fields": {"status": "w", "last_name": "", "gold": 0, "is_staff": true, "user_permissions": [], "interesting_tags": "", "email_key": null, "date_joined": "2012-01-23 17:03:54", "first_name": "", "email_isvalid": false, "avatar_type": "n", "website": "", "is_superuser": true, "date_of_birth": null, "last_login": "2012-01-23 17:04:16", "location": "", "new_response_count": 0, "email": "pmitros@csail.mit.edu", "username": "pm", "is_active": true, "consecutive_days_visit_count": 0, "email_tag_filter_strategy": 1, "groups": [], "password": "sha1$a3e96$dbabbd114f0da01bce2cc2adcafa2ca651c7ae0a", "silver": 0, "bronze": 0, "questions_per_page": 10, "about": "", "show_country": false, "country": "", "display_tag_filter_strategy": 0, "seen_response_count": 0, "real_name": "", "ignored_tags": "", "reputation": 1, "gravatar": "7a591afd0cc7972fdbe5e12e26af352a", "last_seen": "2012-01-23 17:04:41"}}]
|
||||
Reference in New Issue
Block a user