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
OpenEdx
configuration
Commits
21a21832
Commit
21a21832
authored
7 years ago
by
Shirley He
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix up naming
parent
0dfbdcbd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
10 deletions
+14
-10
util/course-permutation-tool/generate_permutations.py
+14
-10
No files found.
util/course-permutation-tool/generate_permutations.py
View file @
21a21832
...
@@ -50,17 +50,17 @@ def process_field_arguments(parser_args):
...
@@ -50,17 +50,17 @@ def process_field_arguments(parser_args):
sys
.
exit
()
sys
.
exit
()
field_args
=
{}
field_args
=
{}
parsed_field_args
=
parser_args
.
fields
parsed_field_args
=
parser_args
.
fields
[
0
]
if
isinstance
(
parser_args
.
fields
,
list
)
else
None
# if no field arguments are given, just return default data
# if no field arguments are given, just return default data
if
not
parsed_field_args
:
if
not
parsed_field_args
:
field_args
=
file_data
[
"default_data"
]
field_args
=
file_data
[
"default_data"
]
else
:
else
:
num_field_args
=
len
(
parsed_field_args
[
0
]
)
num_field_args
=
len
(
parsed_field_args
)
if
(
num_field_args
>
3
):
if
(
num_field_args
>
3
):
raise
argparse
.
ArgumentTypeError
(
"Only a max of 3 fields allowed"
)
raise
argparse
.
ArgumentTypeError
(
"Only a max of 3 fields allowed"
)
# add each command line field to fields dict
# add each command line field to fields dict
for
field
in
parsed_field_args
[
0
]
:
for
field
in
parsed_field_args
:
try
:
try
:
field_args
[
field
]
=
permutation_data
[
field
]
field_args
[
field
]
=
permutation_data
[
field
]
except
KeyError
:
except
KeyError
:
...
@@ -68,7 +68,7 @@ def process_field_arguments(parser_args):
...
@@ -68,7 +68,7 @@ def process_field_arguments(parser_args):
sys
.
exit
()
sys
.
exit
()
# calculate the difference between all possible fields and the chosen permutation ones
# calculate the difference between all possible fields and the chosen permutation ones
default_fields
=
list
(
set
(
default_data_keys
)
-
set
(
parsed_field_args
[
0
]
))
default_fields
=
list
(
set
(
default_data_keys
)
-
set
(
parsed_field_args
))
# add non permutation fields to dict
# add non permutation fields to dict
for
field
in
default_fields
:
for
field
in
default_fields
:
...
@@ -91,9 +91,10 @@ def generate_permutations(field_args, index, results, courses_dict, field_values
...
@@ -91,9 +91,10 @@ def generate_permutations(field_args, index, results, courses_dict, field_values
courses_dict
[
"user"
]
=
COURSE_USER
courses_dict
[
"user"
]
=
COURSE_USER
courses_dict
[
"partner"
]
=
COURSE_PARTNER
courses_dict
[
"partner"
]
=
COURSE_PARTNER
# configure enrollment seat settings
# configure enrollment seat settings
enrollment_dict
=
{}
enrollment_dict
=
{
enrollment_dict
[
"credit"
]
=
False
"credit"
:
False
,
enrollment_dict
[
"credit_provider"
]
=
"test-credit-provider"
"credit-provider"
:
"test-credit-provider"
}
# add permutation fields to dict
# add permutation fields to dict
field_values_dict
[
permutation_option
]
=
permutation_value
field_values_dict
[
permutation_option
]
=
permutation_value
...
@@ -121,12 +122,13 @@ def generate_permutations(field_args, index, results, courses_dict, field_values
...
@@ -121,12 +122,13 @@ def generate_permutations(field_args, index, results, courses_dict, field_values
wrapper_courses_dict
=
{}
wrapper_courses_dict
=
{}
wrapper_courses_dict
[
"courses"
]
=
results
wrapper_courses_dict
[
"courses"
]
=
results
create_courses_json_file
(
wrapper_courses_dict
)
return
wrapper_courses_dict
def
create_courses_json_file
(
wrapper_courses_dict
):
def
create_courses_json_file
(
wrapper_courses_dict
):
with
open
(
TEST_COURSES_FILE
,
"w"
)
as
outfile
:
with
open
(
TEST_COURSES_FILE
,
"w"
)
as
outfile
:
json
.
dump
(
wrapper_courses_dict
,
outfile
)
json
.
dump
(
wrapper_courses_dict
,
outfile
)
return
TEST_COURSES_FILE
def
calculate_date_value
(
date_const
):
def
calculate_date_value
(
date_const
):
...
@@ -142,13 +144,15 @@ def calculate_date_value(date_const):
...
@@ -142,13 +144,15 @@ def calculate_date_value(date_const):
return
None
return
None
except
ValueError
:
except
ValueError
:
print
"Dates can only be future or past"
print
"Dates can only be future or past"
sys
.
exit
()
def
start_field_recursion
(
process_field_args
):
def
start_field_recursion
(
process_field_args
):
generate_permutations
(
process_field_args
,
0
,
[],
{},
{})
return
generate_permutations
(
process_field_args
,
0
,
[],
{},
{})
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
args
=
arg_parse
()
args
=
arg_parse
()
process_field_args
=
process_field_arguments
(
args
)
process_field_args
=
process_field_arguments
(
args
)
start_field_recursion
(
process_field_args
)
json_file
=
start_field_recursion
(
process_field_args
)
create_courses_json_file
(
json_file
)
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