From 4776f242295c647741d54adaad076b9085cecd9a Mon Sep 17 00:00:00 2001 From: Cristiano Ferreira Date: Tue, 23 Jul 2024 13:22:52 +0100 Subject: [PATCH] Fix speaking grading overall. --- app.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/app.py b/app.py index 24ecb52..de47607 100644 --- a/app.py +++ b/app.py @@ -660,11 +660,7 @@ def grade_speaking_task_1(): response['transcript_' + str(i)] = answer response['fixed_text_' + str(i)] = get_speaking_corrections(answer) - if response["overall"] == "0.0" or response["overall"] == 0.0: - response["overall"] = round((response["task_response"]["Fluency and Coherence"] + - response["task_response"]["Lexical Resource"] + response["task_response"][ - "Grammatical Range and Accuracy"] + response["task_response"][ - "Pronunciation"]) / 4, 1) + response["overall"] = fix_speaking_overall(response["overall"], response["task_response"]) logging.info("POST - speaking_task_1 - " + str(request_id) + " - Final response: " + str(response)) return response @@ -830,11 +826,7 @@ def grade_speaking_task_2(): response['fixed_text'] = get_speaking_corrections(answer) logging.info("POST - speaking_task_2 - " + str(request_id) + " - Fixed text: " + response['fixed_text']) - if response["overall"] == "0.0" or response["overall"] == 0.0: - response["overall"] = round((response["task_response"]["Fluency and Coherence"] + - response["task_response"]["Lexical Resource"] + response["task_response"][ - "Grammatical Range and Accuracy"] + response["task_response"][ - "Pronunciation"]) / 4, 1) + response["overall"] = fix_speaking_overall(response["overall"], response["task_response"]) logging.info("POST - speaking_task_2 - " + str(request_id) + " - Final response: " + str(response)) return response @@ -1121,16 +1113,24 @@ def grade_speaking_task_3(): for i, answer in enumerate(text_answers, start=1): response['transcript_' + str(i)] = answer response['fixed_text_' + str(i)] = get_speaking_corrections(answer) - if response["overall"] == "0.0" or response["overall"] == 0.0: - response["overall"] = round((response["task_response"]["Fluency and Coherence"] + response["task_response"][ - "Lexical Resource"] + response["task_response"]["Grammatical Range and Accuracy"] + - response["task_response"]["Pronunciation"]) / 4, 1) + response["overall"] = fix_speaking_overall(response["overall"], response["task_response"]) logging.info("POST - speaking_task_3 - " + str(request_id) + " - Final response: " + str(response)) return response except Exception as e: return str(e), 400 +def fix_speaking_overall(overall: float, task_response: dict): + grades = [category["grade"] for category in task_response.values()] + + if overall > max(grades) or overall < min(grades): + total_sum = sum(grades) + average = total_sum / len(grades) + rounded_average = round(average, 0) + return rounded_average + + return overall + @app.route('/speaking', methods=['POST']) @jwt_required() def save_speaking():