Replace clock with process_time. Submit works.

This commit is contained in:
2020-01-06 20:25:04 -05:00
parent c3d6863ab6
commit 126d7103fa

View File

@@ -87,7 +87,7 @@ def load_metadata(metadata_file_name='_coursera'):
def part_prompt(problems): def part_prompt(problems):
''' '''
Prompts the user for which parts of the assignment they would like to Prompts the user for which parts of the assignment they would like to
submit. submit.
Args: Args:
@@ -140,7 +140,7 @@ def compute(metadata, solver_file_override=None):
Args: Args:
metadata: the assignment metadata metadata: the assignment metadata
solver_file_override: an optional model file to override the metadata solver_file_override: an optional model file to override the metadata
default default
Returns: Returns:
@@ -162,7 +162,7 @@ def compute(metadata, solver_file_override=None):
solver_file = solver_file_override solver_file = solver_file_override
else: else:
solver_file = problem.solver_file solver_file = problem.solver_file
if not os.path.isfile(solver_file): if not os.path.isfile(solver_file):
print('Unable to locate assignment file "%s" in the current working directory.' % solver_file) print('Unable to locate assignment file "%s" in the current working directory.' % solver_file)
continue continue
@@ -214,7 +214,7 @@ def output(input_file, solver_file):
solution = '' solution = ''
start = time.clock() start = time.process_time()
try: try:
solution = pkg.solve_it(load_input_data(input_file)) solution = pkg.solve_it(load_input_data(input_file))
except Exception as e: except Exception as e:
@@ -224,7 +224,7 @@ def output(input_file, solver_file):
print(str(e)) print(str(e))
print('') print('')
return 'Local Exception =(' return 'Local Exception =('
end = time.clock() end = time.process_time()
if not (isinstance(solution, str) or isinstance(solution, unicode)): if not (isinstance(solution, str) or isinstance(solution, unicode)):
print('Warning: the solver did not return a string. The given object will be converted with the str() method.') print('Warning: the solver did not return a string. The given object will be converted with the str() method.')
@@ -238,13 +238,13 @@ def output(input_file, solver_file):
def login_dialog(assignment_key, results, credentials_file_location = '_credentials'): def login_dialog(assignment_key, results, credentials_file_location = '_credentials'):
''' '''
Requests Coursera login credentials from the student and submits the Requests Coursera login credentials from the student and submits the
student's solutions for grading student's solutions for grading
Args: Args:
assignment_key: Coursera's assignment key assignment_key: Coursera's assignment key
results: a dictionary of results in Cousera's format results: a dictionary of results in Cousera's format
credentials_file_location: a file location where login credentials can credentials_file_location: a file location where login credentials can
be found be found
''' '''
@@ -253,7 +253,7 @@ def login_dialog(assignment_key, results, credentials_file_location = '_credenti
while not success: while not success:
# stops infinate loop when credentials file is incorrect # stops infinate loop when credentials file is incorrect
if tries <= 0: if tries <= 0:
login, token = login_prompt(credentials_file_location) login, token = login_prompt(credentials_file_location)
else: else:
@@ -264,7 +264,7 @@ def login_dialog(assignment_key, results, credentials_file_location = '_credenti
print('\n== Coursera Responce ...') print('\n== Coursera Responce ...')
#print(code) #print(code)
print(responce) print(responce)
if code != 401: if code != 401:
success = True success = True
else: else:
@@ -277,7 +277,7 @@ def login_prompt(credentials_file_location):
Returns: Returns:
the user's login and token the user's login and token
''' '''
if os.path.isfile(credentials_file_location): if os.path.isfile(credentials_file_location):
try: try:
with open(credentials_file_location, 'r') as metadata_file: with open(credentials_file_location, 'r') as metadata_file:
@@ -293,7 +293,7 @@ def login_prompt(credentials_file_location):
def basic_prompt(): def basic_prompt():
''' '''
Prompt the user for login credentials. Prompt the user for login credentials.
Returns: Returns:
the user's login and token the user's login and token
''' '''
@@ -304,7 +304,7 @@ def basic_prompt():
def submit_solution(assignment_key, email_address, token, results): def submit_solution(assignment_key, email_address, token, results):
''' '''
Sends the student's submission to Coursera for grading via the submission Sends the student's submission to Coursera for grading via the submission
API. API.
Args: Args:
@@ -318,14 +318,14 @@ def submit_solution(assignment_key, email_address, token, results):
''' '''
print('\n== Connecting to Coursera ...') print('\n== Connecting to Coursera ...')
print('Submitting %d of %d parts' % print('Submitting %d of %d parts' %
(sum(['output' in v for k,v in results.items()]), len(results))) (sum(['output' in v for k,v in results.items()]), len(results)))
# build json datastructure # build json datastructure
parts = {} parts = {}
submission = { submission = {
'assignmentKey': assignment_key, 'assignmentKey': assignment_key,
'submitterEmail': email_address, 'submitterEmail': email_address,
'secret': token, 'secret': token,
'parts': results 'parts': results
} }
@@ -360,12 +360,12 @@ def submit_solution(assignment_key, email_address, token, results):
def main(args): def main(args):
''' '''
1) Reads a metadata file to customize the submission process to 1) Reads a metadata file to customize the submission process to
a particular assignment. a particular assignment.
2) The compute the student's answers to the assignment parts. 2) The compute the student's answers to the assignment parts.
3) Submits the student's answers for grading. 3) Submits the student's answers for grading.
Provides the an option for saving the submissions locally. This is very Provides the an option for saving the submissions locally. This is very
helpful when testing the assignment graders. helpful when testing the assignment graders.
Args: Args:
@@ -382,7 +382,7 @@ def main(args):
metadata = load_metadata(args.metadata) metadata = load_metadata(args.metadata)
print('==\n== '+metadata.name+' Solution Submission \n==') print('==\n== '+metadata.name+' Solution Submission \n==')
# compute dialog # compute dialog
results = compute(metadata, args.override) results = compute(metadata, args.override)
@@ -424,27 +424,27 @@ def build_parser():
''' '''
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='''The submission script for Discrete Optimization description='''The submission script for Discrete Optimization
assignments on the Coursera Platform.''', assignments on the Coursera Platform.''',
epilog='''Please file bugs on github at: epilog='''Please file bugs on github at:
https://github.com/discreteoptimization/assignment/issues. If you https://github.com/discreteoptimization/assignment/issues. If you
would like to contribute to this tool's development, check it out at: would like to contribute to this tool's development, check it out at:
https://github.com/discreteoptimization/assignment''' https://github.com/discreteoptimization/assignment'''
) )
parser.add_argument('-v', '--version', action='version', parser.add_argument('-v', '--version', action='version',
version='%(prog)s '+version) version='%(prog)s '+version)
parser.add_argument('-o', '--override', parser.add_argument('-o', '--override',
help='overrides the python source file specified in the \'_coursera\' file') help='overrides the python source file specified in the \'_coursera\' file')
parser.add_argument('-m', '--metadata', parser.add_argument('-m', '--metadata',
help='overrides the \'_coursera\' metadata file') help='overrides the \'_coursera\' metadata file')
parser.add_argument('-c', '--credentials', parser.add_argument('-c', '--credentials',
help='overrides the \'_credentials\' credentials file') help='overrides the \'_credentials\' credentials file')
parser.add_argument('-rs', '--record_submission', parser.add_argument('-rs', '--record_submission',
help='records the submission(s) as files', action='store_true') help='records the submission(s) as files', action='store_true')
return parser return parser