Skip to content

Commit

Permalink
handled various outcomes parsing correct answers
Browse files Browse the repository at this point in the history
  • Loading branch information
olearydj committed Sep 24, 2023
1 parent 64e0781 commit b372cc9
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/formats/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
def write_file(data, outfile):
"""
markdown output, handles only standard multiple choice questions now
image support is untested
image support is not working - see `q11_sql.xml` and related
complex question text (e.g. multi-line with code blocks) is not handled
need to test of provided case `imsmanifest.xml`
"""
markdown_list = []
text_maker = html2text.HTML2Text()
Expand Down Expand Up @@ -87,15 +88,26 @@ def write_file(data, outfile):
markdown_list.append(handled_text)

# find correct answer
for answer in question['answer']:
if 'correct' in answer and answer['correct']:
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'])}")
correct_answer_id = answer['id']
logger.info(f"Correct answer ({correct_answer_id}): {answer['text']}")

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

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

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

Expand Down

0 comments on commit b372cc9

Please sign in to comment.