Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
configuration
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
configuration
Commits
5b0ce9a9
Commit
5b0ce9a9
authored
Aug 04, 2017
by
Shirley He
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
create output file
parent
036f6805
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
14 deletions
+31
-14
util/course-permutation-tool/generate_permutations.py
+29
-14
util/course-permutation-tool/test_courses.json
+2
-0
No files found.
util/course-permutation-tool/generate_permutations.py
View file @
5b0ce9a9
...
@@ -6,8 +6,10 @@ import argparse
...
@@ -6,8 +6,10 @@ import argparse
from
argparse
import
ArgumentParser
from
argparse
import
ArgumentParser
from
pprint
import
pprint
from
pprint
import
pprint
from
itertools
import
product
from
itertools
import
product
from
itertools
import
permutations
import
sys
import
sys
def
parse_field_arguments
():
def
parse_field_arguments
():
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--fields'
,
nargs
=
"*"
,
action
=
"append"
,
default
=
None
,
parser
.
add_argument
(
'--fields'
,
nargs
=
"*"
,
action
=
"append"
,
default
=
None
,
...
@@ -15,34 +17,47 @@ def parse_field_arguments():
...
@@ -15,34 +17,47 @@ def parse_field_arguments():
parser
.
add_argument
(
'filename'
)
parser
.
add_argument
(
'filename'
)
num_args
=
parser
.
parse_args
()
num_args
=
parser
.
parse_args
()
field_length
=
len
(
num_args
.
fields
[
0
])
if
(
field_length
>
3
):
raise
argparse
.
ArgumentTypeError
(
"--fields can only take a max of 3 values"
)
file
=
open
(
num_args
.
filename
)
file
=
open
(
num_args
.
filename
)
permutation
_data
=
json
.
load
(
file
)
file
_data
=
json
.
load
(
file
)
fields
=
{}
default_data
=
file_data
[
"default_data"
]
permutation_data
=
file_data
[
"permutation_data"
]
default_data_keys
=
permutation_data
.
keys
()
#
first_field = permutation_data
#
print default_data_keys
# second_field = permutation_data
# third_field = permutation_data
fields
=
{}
# if no field arguments are given, just print out default data
# if no field arguments are given, just print out default data
if
not
num_args
.
fields
:
if
not
num_args
.
fields
:
default_permutation
=
permutation
_data
[
"default_data"
]
default_permutation
=
file
_data
[
"default_data"
]
print
default_permutation
fields
=
default_permutation
else
:
else
:
field_length
=
len
(
num_args
.
fields
[
0
])
if
(
field_length
>
3
):
raise
argparse
.
ArgumentTypeError
(
"--fields can only take a max of 3 values"
)
for
permutation_choices
in
num_args
.
fields
:
for
permutation_choices
in
num_args
.
fields
:
for
i
in
range
(
0
,
field_length
):
for
i
in
range
(
0
,
field_length
):
fields
[
permutation_choices
[
i
]]
=
permutation_data
[
"permutation_data"
][
permutation_choices
[
i
]]
fields
[
permutation_choices
[
i
]]
=
permutation_data
[
permutation_choices
[
i
]]
# for j in range(field_length, total_num_fields):
# fields[permutation_choices[j]] =
# print permutation_data.keys() not in permutation_choices
return
fields
return
fields
def
generate_permutations
(
fields
):
def
generate_permutations
(
fields
):
#permutation_generation = [first_field, second_field, third_field]
# print list(product(*fields))
field_permutations
=
list
(
product
(
*
fields
.
values
()))
print
fields
# make JSON output file
with
open
(
"test_courses.json"
,
"w"
)
as
outfile
:
json
.
dump
(
field_permutations
,
outfile
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
util/course-permutation-tool/test_courses.json
0 → 100644
View file @
5b0ce9a9
[[
"past"
,
true
,
"past"
],
[
"past"
,
true
,
"future"
],
[
"past"
,
true
,
null
],
[
"past"
,
false
,
"past"
],
[
"past"
,
false
,
"future"
],
[
"past"
,
false
,
null
],
[
"past"
,
null
,
"past"
],
[
"past"
,
null
,
"future"
],
[
"past"
,
null
,
null
],
[
"future"
,
true
,
"past"
],
[
"future"
,
true
,
"future"
],
[
"future"
,
true
,
null
],
[
"future"
,
false
,
"past"
],
[
"future"
,
false
,
"future"
],
[
"future"
,
false
,
null
],
[
"future"
,
null
,
"past"
],
[
"future"
,
null
,
"future"
],
[
"future"
,
null
,
null
],
[
null
,
true
,
"past"
],
[
null
,
true
,
"future"
],
[
null
,
true
,
null
],
[
null
,
false
,
"past"
],
[
null
,
false
,
"future"
],
[
null
,
false
,
null
],
[
null
,
null
,
"past"
],
[
null
,
null
,
"future"
],
[
null
,
null
,
null
]]
\ No newline at end of file
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