Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
1622f826
Commit
1622f826
authored
Apr 25, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding code to anonymize fixture data
parent
61e005af
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
0 deletions
+43
-0
fixtures/anonymize_fixtures.py
+43
-0
No files found.
fixtures/anonymize_fixtures.py
0 → 100644
View file @
1622f826
import
sys
import
json
import
random
import
copy
from
collections
import
defaultdict
from
argparse
import
ArgumentParser
,
FileType
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
[
"pk"
]
=
out_pk
out_pk
+=
1
out_data
.
append
(
data
)
json
.
dump
(
out_data
,
args
.
output
,
indent
=
2
)
if
__name__
==
"__main__"
:
sys
.
exit
(
main
())
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment