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
043c30b5
Commit
043c30b5
authored
Aug 09, 2017
by
Shirley He
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
polish up file
parent
a0a511b3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
26 deletions
+25
-26
util/course-permutation-tool/generate_permutations.py
+19
-23
util/course-permutation-tool/permutations.json
+6
-3
util/course-permutation-tool/test_courses.json
+0
-0
No files found.
util/course-permutation-tool/generate_permutations.py
View file @
043c30b5
#!/usr/bin/env python
#!/usr/bin/env python
# other comment about how this file works, plus probably an example of implementation
#
# Create a file of course permutations based on permutations.json file configuration. A max
# of 3 fields can be chosen to build permutations on, and only the fields under
# "permutation_data" are eligible. No field input pulls from "default_data"
#
# ./generate_permutations.py --seed_data_file permutations.json --fields field1 field2 field3
import
json
import
json
import
argparse
import
argparse
...
@@ -17,13 +22,14 @@ def parse_field_arguments():
...
@@ -17,13 +22,14 @@ 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
,
help
=
"Specify which fields to generate permutations on"
)
help
=
"Specify which fields to generate permutations on"
)
parser
.
add_argument
(
'
filename'
)
parser
.
add_argument
(
'
--seed_data_file'
,
help
=
"Input a permutation configuration file"
)
num_args
=
parser
.
parse_args
()
num_args
=
parser
.
parse_args
()
file
=
open
(
num_args
.
filenam
e
)
file
=
open
(
num_args
.
seed_data_fil
e
)
file_data
=
json
.
load
(
file
)
file_data
=
json
.
load
(
file
)
default_data
=
file_data
[
"default_data"
]
default_data
=
file_data
[
"default_data"
]
permutation_data
=
file_data
[
"permutation_data"
]
permutation_data
=
file_data
[
"permutation_data"
]
...
@@ -31,7 +37,7 @@ def parse_field_arguments():
...
@@ -31,7 +37,7 @@ def parse_field_arguments():
fields
=
{}
fields
=
{}
# if no field arguments are given, just
print out
default data
# if no field arguments are given, just
return
default data
if
not
num_args
.
fields
:
if
not
num_args
.
fields
:
default_permutation
=
file_data
[
"default_data"
]
default_permutation
=
file_data
[
"default_data"
]
fields
=
default_permutation
fields
=
default_permutation
...
@@ -39,16 +45,16 @@ def parse_field_arguments():
...
@@ -39,16 +45,16 @@ def parse_field_arguments():
field_length
=
len
(
num_args
.
fields
[
0
])
field_length
=
len
(
num_args
.
fields
[
0
])
if
(
field_length
>
3
):
if
(
field_length
>
3
):
raise
argparse
.
ArgumentTypeError
(
"
--fields can only take a max of 3 values
"
)
raise
argparse
.
ArgumentTypeError
(
"
Only a max of 3 fields allowed
"
)
# add each command line field to fields dict
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_choices
[
i
]]
fields
[
permutation_choices
[
i
]]
=
permutation_data
[
permutation_choices
[
i
]]
# the difference btwn all possible fields and the permutation ones
# the difference btwn all possible fields and the
chosen
permutation ones
default_fields
=
list
(
set
(
default_data_keys
)
-
set
(
num_args
.
fields
[
0
]))
default_fields
=
list
(
set
(
default_data_keys
)
-
set
(
num_args
.
fields
[
0
]))
# add non permutation fields
# add non permutation fields
to dict
for
j
in
range
(
0
,
len
(
default_fields
)):
for
j
in
range
(
0
,
len
(
default_fields
)):
fields
[
default_fields
[
j
]]
=
default_data
[
default_fields
[
j
]]
fields
[
default_fields
[
j
]]
=
default_data
[
default_fields
[
j
]]
...
@@ -58,12 +64,11 @@ def parse_field_arguments():
...
@@ -58,12 +64,11 @@ def parse_field_arguments():
def
generate_permutations
(
fields
,
index
,
results
,
current
,
fields_dict
):
def
generate_permutations
(
fields
,
index
,
results
,
current
,
fields_dict
):
all_permutations_keys
=
fields
.
keys
()
all_permutations_keys
=
fields
.
keys
()
permutation_option
=
all_permutations_keys
[
index
]
permutation_option
=
all_permutations_keys
[
index
]
permutations_values
=
fields
[
permutation_option
]
permutations_values
=
fields
[
permutation_option
]
for
i
in
range
(
len
(
permutations_values
)):
for
i
in
range
(
len
(
permutations_values
)):
# add other required default fields to dict
# add other required default fields to dict
current
[
"number"
]
=
"123"
# will be generated automatically by course creation script
current
[
"number"
]
=
None
# will be generated automatically by course creation script
current
[
"organization"
]
=
"RITX"
current
[
"organization"
]
=
"RITX"
current
[
"run"
]
=
"3T2017"
current
[
"run"
]
=
"3T2017"
current
[
"user"
]
=
"edx@example.com"
current
[
"user"
]
=
"edx@example.com"
...
@@ -73,10 +78,10 @@ def generate_permutations(fields, index, results, current, fields_dict):
...
@@ -73,10 +78,10 @@ def generate_permutations(fields, index, results, current, fields_dict):
enrollment_dict
=
{}
enrollment_dict
=
{}
enrollment_dict
[
"credit"
]
=
False
enrollment_dict
[
"credit"
]
=
False
enrollment_dict
[
"credit_provider"
]
=
"test-credit-provider"
enrollment_dict
[
"credit_provider"
]
=
"test-credit-provider"
# enrollment_dict["audit"] = True
# add permutation fields to dict
# add permutation fields to dict
fields_dict
[
permutation_option
]
=
permutations_values
[
i
]
fields_dict
[
permutation_option
]
=
permutations_values
[
i
]
# generate dates
now
=
datetime
.
datetime
.
now
(
pytz
.
UTC
)
now
=
datetime
.
datetime
.
now
(
pytz
.
UTC
)
if
permutations_values
[
i
]
==
"future"
:
if
permutations_values
[
i
]
==
"future"
:
future
=
str
(
now
+
datetime
.
timedelta
(
days
=
365
))
future
=
str
(
now
+
datetime
.
timedelta
(
days
=
365
))
...
@@ -86,31 +91,22 @@ def generate_permutations(fields, index, results, current, fields_dict):
...
@@ -86,31 +91,22 @@ def generate_permutations(fields, index, results, current, fields_dict):
fields_dict
[
permutation_option
]
=
past
fields_dict
[
permutation_option
]
=
past
if
permutations_values
[
i
]
==
None
:
if
permutations_values
[
i
]
==
None
:
fields_dict
[
permutation_option
]
=
None
fields_dict
[
permutation_option
]
=
None
# add audit and verify fields to dict
if
all_permutations_keys
[
i
]
==
"audit"
and
permutations_values
[
i
]
==
True
:
if
all_permutations_keys
[
i
]
==
"audit"
and
permutations_values
[
i
]
==
True
:
enrollment_dict
[
"audit"
]
=
permutations_values
[
i
]
enrollment_dict
[
"audit"
]
=
permutations_values
[
i
]
if
all_permutations_keys
[
i
]
==
"verify"
and
permutations_values
[
i
]
==
True
:
if
all_permutations_keys
[
i
]
==
"verify"
and
permutations_values
[
i
]
==
True
:
enrollment_dict
[
"verify"
]
=
True
enrollment_dict
[
"verify"
]
=
True
if
index
+
1
<
len
(
all_permutations_keys
):
if
index
+
1
<
len
(
all_permutations_keys
):
generate_permutations
(
fields
,
index
+
1
,
results
,
current
,
fields_dict
)
generate_permutations
(
fields
,
index
+
1
,
results
,
current
,
fields_dict
)
current
[
"enrollment"
]
=
enrollment_dict
current
[
"enrollment"
]
=
enrollment_dict
current
[
"fields"
]
=
fields_dict
.
copy
()
current
[
"fields"
]
=
fields_dict
.
copy
()
results
.
append
(
current
.
copy
())
results
.
append
(
current
.
copy
())
# results["courses"] = current.copy()
wrapper_courses_dict
=
{}
wrapper_courses_dict
=
{}
# needed to match course input file creation
wrapper_courses_dict
[
"courses"
]
=
results
wrapper_courses_dict
[
"courses"
]
=
results
with
open
(
"test_courses.json"
,
"w"
)
as
outfile
:
with
open
(
"test_courses.json"
,
"w"
)
as
outfile
:
json
.
dump
(
wrapper_courses_dict
,
outfile
)
json
.
dump
(
wrapper_courses_dict
,
outfile
)
...
...
util/course-permutation-tool/permutations.json
View file @
043c30b5
...
@@ -26,7 +26,6 @@
...
@@ -26,7 +26,6 @@
false
,
false
,
null
null
],
],
"mobile_available"
:
[
"mobile_available"
:
[
true
,
true
,
false
,
false
,
...
@@ -43,8 +42,12 @@
...
@@ -43,8 +42,12 @@
"display_name"
:
[
"display_name"
:
[
"International Project Management"
"International Project Management"
],
],
"audit"
:
[
true
],
"audit"
:
[
"verified"
:
[
true
],
true
],
"verified"
:
[
true
],
"mobile_available"
:
[
"mobile_available"
:
[
true
true
]
]
...
...
util/course-permutation-tool/test_courses.json
View file @
043c30b5
This diff is collapsed.
Click to expand it.
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