From 1d110d5fa95ad0e9f1d9b43f6c16ec7d59fd2519 Mon Sep 17 00:00:00 2001 From: Cristiano Ferreira Date: Thu, 13 Jun 2024 18:24:42 +0100 Subject: [PATCH] Add exercises for utas level. --- app.py | 94 +++++++++++++++++++++++++++++++++++++++++++-- helper/constants.py | 2 - helper/exercises.py | 50 ++++++------------------ 3 files changed, 101 insertions(+), 45 deletions(-) diff --git a/app.py b/app.py index 6f02d4f..684a422 100644 --- a/app.py +++ b/app.py @@ -1013,14 +1013,100 @@ def get_level_exam(): except Exception as e: return str(e) -@app.route('/level_utas', method=['GET']) +@app.route('/level_utas', methods=['GET']) @jwt_required() def get_level_utas(): try: - number_of_exercises = 45 - mc_exercises = gen_multiple_choice_level(number_of_exercises) + # Formats + mc = { + "id": str(uuid.uuid4()), + "prompt": "Choose the correct word or group of words that completes the sentences.", + "questions": None, + "type": "multipleChoice", + "part": 1 + } + + umc = { + "id": str(uuid.uuid4()), + "prompt": "Choose the underlined word or group of words that is not correct.", + "questions": None, + "type": "multipleChoice", + "part": 2 + } + + bs_1 = { + "id": str(uuid.uuid4()), + "prompt": "Read the text and write the correct word for each space.", + "questions": None, + "type": "blankSpaceText", + "part": 3 + } + + bs_2 = { + "id": str(uuid.uuid4()), + "prompt": "Read the text and write the correct word for each space.", + "questions": None, + "type": "blankSpaceText", + "part": 4 + } + + reading = { + "id": str(uuid.uuid4()), + "prompt": "Read the text and answer the questions below.", + "questions": None, + "type": "readingExercises", + "part": 5 + } + + all_mc_questions = [] + + # PART 1 + mc_exercises1 = gen_multiple_choice_blank_space_utas(15, 1, all_mc_questions) + print(json.dumps(mc_exercises1, indent=4)) + all_mc_questions.append(mc_exercises1) + + # PART 2 + mc_exercises2 = gen_multiple_choice_blank_space_utas(15, 16, all_mc_questions) + print(json.dumps(mc_exercises2, indent=4)) + all_mc_questions.append(mc_exercises2) + + # PART 3 + mc_exercises3 = gen_multiple_choice_blank_space_utas(15, 31, all_mc_questions) + print(json.dumps(mc_exercises3, indent=4)) + all_mc_questions.append(mc_exercises3) + + mc_exercises = mc_exercises1['questions'] + mc_exercises2['questions'] + mc_exercises3['questions'] + print(json.dumps(mc_exercises, indent=4)) + mc["questions"] = mc_exercises + + # Underlined mc + underlined_mc = gen_multiple_choice_underlined_utas(15, 46) + print(json.dumps(underlined_mc, indent=4)) + umc["questions"] = underlined_mc + + # Blank Space text 1 + blank_space_text_1 = gen_blank_space_text_utas(12, 61, 250) + print(json.dumps(blank_space_text_1, indent=4)) + bs_1["questions"] = blank_space_text_1 + + # Blank Space text 2 + blank_space_text_2 = gen_blank_space_text_utas(14, 73, 350) + print(json.dumps(blank_space_text_2, indent=4)) + bs_2["questions"] = blank_space_text_2 + + # Reading text + reading_text = gen_reading_passage_utas(87, 10, 4) + print(json.dumps(reading_text, indent=4)) + reading["questions"] = reading_text + return { - "exercises": [mc_exercises], + "exercises": { + "blankSpaceMultipleChoice": mc, + "underlinedMultipleChoice": umc, + "blankSpaceText1": bs_1, + "blankSpaceText2": bs_2, + "readingExercises": reading, + }, "isDiagnostic": False, "minTimer": 25, "module": "level" diff --git a/helper/constants.py b/helper/constants.py index 7fcc092..c5f924c 100644 --- a/helper/constants.py +++ b/helper/constants.py @@ -141,7 +141,6 @@ mti_topics = [ "Poverty Alleviation", "Cybersecurity and Privacy", "Human Rights", - "Social Justice", "Food and Agriculture", "Cyberbullying and Online Safety", "Linguistic Diversity", @@ -232,7 +231,6 @@ topics = [ "Meditation Practices", "Literary Symbolism", "Marine Conservation", - "Social Justice Movements", "Sustainable Tourism", "Ancient Philosophy", "Cold War Era", diff --git a/helper/exercises.py b/helper/exercises.py index 59db409..1365d78 100644 --- a/helper/exercises.py +++ b/helper/exercises.py @@ -1147,12 +1147,7 @@ def gen_multiple_choice_blank_space_utas(quantity: int, start_id: int, all_exams question["questions"][i], seen_keys = replace_exercise_if_exists(all_exams, question["questions"][i], question, seen_keys) - return { - "id": str(uuid.uuid4()), - "prompt": "Select the appropriate option.", - "questions": fix_exercise_ids(question, start_id)["questions"], - "type": "multipleChoice", - } + return fix_exercise_ids(question, start_id) def gen_multiple_choice_underlined_utas(quantity: int, start_id: int): @@ -1220,12 +1215,7 @@ def gen_multiple_choice_underlined_utas(quantity: int, start_id: int): if len(question["questions"]) != quantity: return gen_multiple_choice_level(quantity, start_id) else: - return { - "id": str(uuid.uuid4()), - "prompt": "Select the appropriate option.", - "questions": fix_exercise_ids(question, start_id)["questions"], - "type": "multipleChoice", - } + return fix_exercise_ids(question, start_id)["questions"] def gen_blank_space_text_utas(quantity: int, start_id: int, size: int, topic=random.choice(mti_topics)): json_format = { @@ -1277,37 +1267,24 @@ def gen_blank_space_text_utas(quantity: int, start_id: int, size: int, topic=ran ["question"], GEN_QUESTION_TEMPERATURE) - return { - "id": str(uuid.uuid4()), - "prompt": "Select the appropriate option.", - "questions": question["question"], - "type": "blankSpace" - } + return question["question"] def gen_reading_passage_utas(start_id, sa_quantity: int, mc_quantity: int, topic=random.choice(mti_topics)): passage = generate_reading_passage(QuestionType.READING_PASSAGE_1, topic) - exercises = gen_reading_exercises_utas(passage["text"], start_id, sa_quantity, mc_quantity) - if contains_empty_dict(exercises): - return gen_reading_passage_utas(start_id, sa_quantity, mc_quantity, topic) + short_answer = gen_short_answer_utas(passage["text"], start_id, sa_quantity) + mc_exercises = gen_text_multiple_choice_utas(passage["text"], start_id+sa_quantity, mc_quantity) return { - "exercises": exercises, + "exercises": { + "shortAnswer":short_answer, + "multipleChoice": mc_exercises, + }, "text": { "content": passage["text"], "title": passage["title"] } } -def gen_reading_exercises_utas(passage: str, start_id: int, sa_quantity: int, mc_quantity: int): - exercises = [] - - sa_questions = gen_short_answer_utas(passage, start_id, sa_quantity) - exercises.append(sa_questions) - mc_questions = gen_text_multiple_choice_utas(passage, start_id+sa_quantity, mc_quantity) - exercises.append(mc_questions) - - return exercises - def gen_short_answer_utas(text: str, start_id: int, sa_quantity: int): json_format = {"questions": [{"id": 1, "question": "question", "possible_answers": ["answer_1", "answer_2"]}]} @@ -1331,7 +1308,7 @@ def gen_short_answer_utas(text: str, start_id: int, sa_quantity: int): token_count = count_total_tokens(messages) return make_openai_call(GPT_4_O, messages, token_count, ["questions"], - GEN_QUESTION_TEMPERATURE) + GEN_QUESTION_TEMPERATURE)["questions"] def gen_text_multiple_choice_utas(text: str, start_id: int, mc_quantity: int): json_format = { "questions": [ @@ -1385,9 +1362,4 @@ def gen_text_multiple_choice_utas(text: str, start_id: int, mc_quantity: int): if len(question["questions"]) != mc_quantity: return gen_multiple_choice_level(mc_quantity, start_id) else: - return { - "id": str(uuid.uuid4()), - "prompt": "Select the appropriate option.", - "questions": fix_exercise_ids(question, start_id)["questions"], - "type": "multipleChoice", - } \ No newline at end of file + return fix_exercise_ids(question, start_id)["questions"] \ No newline at end of file