Skip to content

Commit

Permalink
moved correct answers logic inside answer proc
Browse files Browse the repository at this point in the history
  • Loading branch information
olearydj committed Sep 24, 2023
1 parent b372cc9 commit 8f06248
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions src/formats/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,31 +87,29 @@ def write_file(data, outfile):
logger.info(f"Adding text to question {q_num+1}: {repr(handled_text)}")
markdown_list.append(handled_text)

# find correct answer
if 'answer' in question and question['answer'] is not None:
# Create a list containing all answers from 'question['answer']' where the key 'correct' is present and its value is True.
correct_answers = [answer for answer in question['answer'] if 'correct' in answer and answer['correct']]

if correct_answers:
if len(correct_answers) > 1:
logger.warning(f"Multiple correct answers found in question {q_num+1}, using first")

answer = correct_answers[0]
correct_answer_id = answer['id']
logger.debug(f"contents of correct field: {repr(answer['correct'])}")
logger.debug(f"type of correct field: {type(answer['correct'])}")
logger.info(f"Correct answer ({correct_answer_id}): {answer['text']}")
else:
logger.debug(f"No text in question {q_num+1}")

# Add any answers found
if 'answer' in question and question['answer'] is not None:

else:
logger.warning(f"No correct answer found in question {q_num+1}")
# first identify correct answer and handle if multiple or none
# Create a list containing all answers from 'question['answer']' where the key 'correct' is present and its value is True.
correct_answers = [answer for answer in question['answer'] if 'correct' in answer and answer['correct']]

if correct_answers:
if len(correct_answers) > 1:
logger.warning(f"Multiple correct answers found in question {q_num+1}, using first")

answer = correct_answers[0]
correct_answer_id = answer['id']
logger.debug(f"contents of correct field: {repr(answer['correct'])}")
logger.debug(f"type of correct field: {type(answer['correct'])}")
logger.info(f"Correct answer ({correct_answer_id}): {answer['text']}")

else:
logger.warning(f"No answers found for question {q_num+1}")
logger.warning(f"No correct answer found in question {q_num+1}")

else:
logger.debug(f"No text in question {q_num+1}")

if 'answer' in question:
"""
implement `matching_question` next, other types aren't used
will need to make sure formatting here matches what is required by text2qti
Expand Down Expand Up @@ -151,6 +149,9 @@ def write_file(data, outfile):
else:
markdown_list.append(config.blanks_replace_str * config.blanks_answer_n)

else:
logger.warning(f"No answers found for question {q_num+1}")

# Writing the Generated Markdown to a File
with open(outfile, 'w') as md_file:
md_file.write(''.join(markdown_list))
Expand Down

0 comments on commit 8f06248

Please sign in to comment.