From dd44a11d37cf7307d6caf7cace843ab74baa49c9 Mon Sep 17 00:00:00 2001 From: Shruti1229 Date: Tue, 25 Jul 2023 01:02:18 +0530 Subject: [PATCH 1/3] Get fail info for inprogress task --- backend/task/views.py | 8 +++++- backend/translation/views.py | 25 ++++++----------- backend/voiceover/utils.py | 54 +++++++++++++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 18 deletions(-) diff --git a/backend/task/views.py b/backend/task/views.py index 96a30edc..7fb4b24c 100644 --- a/backend/task/views.py +++ b/backend/task/views.py @@ -22,6 +22,7 @@ process_translation_payload, send_mail_to_user, get_bad_sentences, + get_bad_sentences_in_progress, ) from transcript.models import ( Transcript, @@ -2640,7 +2641,12 @@ def get_fail_info(self, request, pk, *args, **kwargs): bad_sentences = [] translation = get_translation_id(task) if task.task_type in ["TRANSLATION_EDIT"] and translation: - bad_sentences = get_bad_sentences(translation, task.target_language) + if "COMPLETE" not in translation.status: + bad_sentences = get_bad_sentences_in_progress( + translation, task.target_language + ) + else: + bad_sentences = get_bad_sentences(translation, task.target_language) if len(bad_sentences) > 0: return Response( { diff --git a/backend/translation/views.py b/backend/translation/views.py index a3250dc3..a68736bc 100644 --- a/backend/translation/views.py +++ b/backend/translation/views.py @@ -35,7 +35,7 @@ TRANSLATION_REVIEW_INPROGRESS, TRANSLATION_REVIEW_COMPLETE, ) -from voiceover.utils import process_translation_payload, get_bad_sentences +from voiceover.utils import process_translation_payload, get_bad_sentences_in_progress from .decorators import is_translation_editor from .serializers import TranslationSerializer from .utils import ( @@ -702,7 +702,7 @@ def send_mail_to_user(task): def check_if_translation_correct(translation_obj, task): - bad_sentences = get_bad_sentences(translation_obj, task) + bad_sentences = get_bad_sentences_in_progress(translation_obj, task) if len(bad_sentences) > 0: translation = ( Translation.objects.filter(target_language=translation_obj.target_language) @@ -1277,17 +1277,15 @@ def save_translation(request): for ind in delete_indices: translation_obj.payload["payload"].pop(ind) translation_obj.save() - """ response = check_if_translation_correct(translation_obj, task) if type(response) == dict: return Response( - { - "data": response["data"], - "message": response["message"] - }, - status=status.HTTP_400_BAD_REQUEST, + { + "data": response["data"], + "message": response["message"], + }, + status=status.HTTP_400_BAD_REQUEST, ) - """ message = change_active_status_of_next_tasks( task, translation_obj ) @@ -1389,17 +1387,12 @@ def save_translation(request): translation_obj.save() task.status = "COMPLETE" task.save() - """ response = check_if_translation_correct(translation_obj, task) if type(response) == dict: return Response( - { - "data": response["data"], - "message": response["message"] - }, - status=status.HTTP_400_BAD_REQUEST, + {"data": response["data"], "message": response["message"]}, + status=status.HTTP_400_BAD_REQUEST, ) - """ message = change_active_status_of_next_tasks(task, translation_obj) else: translation_obj = ( diff --git a/backend/voiceover/utils.py b/backend/voiceover/utils.py index 691ce360..bb360d8d 100644 --- a/backend/voiceover/utils.py +++ b/backend/voiceover/utils.py @@ -371,7 +371,7 @@ def get_bad_sentences(translation_obj, target_language): if not compare_time(text["end_time"], text["start_time"])[0]: problem_sentences.append( { - "index": ind % 50, + "index": (ind % 50) + 1, "page_number": (ind // 50) + 1, "start_time": text["start_time"], "end_time": text["end_time"], @@ -386,6 +386,26 @@ def get_bad_sentences(translation_obj, target_language): translation["payload"][ind - 1]["end_time"], text["start_time"] )[0] ): + problem_sentences.append( + { + "index": (ind % 50) + 1, + "page_number": (ind // 50) + 1, + "start_time": text["start_time"], + "end_time": text["end_time"], + "text": text["text"], + "target_text": text["target_text"], + } + ) + return problem_sentences + + +def get_bad_sentences_in_progress(translation_obj, target_language): + tts_input = [] + empty_sentences = [] + delete_indices = [] + translation = translation_obj.payload + for ind, text in enumerate(translation["payload"]): + if not compare_time(text["end_time"], text["start_time"])[0]: problem_sentences.append( { "index": ind % 50, @@ -396,6 +416,38 @@ def get_bad_sentences(translation_obj, target_language): "target_text": text["target_text"], } ) + if ind != 0 and ind < len(translation["payload"]): + compare_with_index = -1 + last_valid_index = -1 + compare = False + if "text" in translation["payload"][ind - 1] and "text" in text.keys(): + compare_with_index = ind - 1 + last_valid_index = ind + compare = True + elif ( + "text" in text.keys() and "text" not in translation["payload"][ind - 1] + ): + compare_with_index = last_valid_index + compare = True + else: + pass + if ( + compare + and compare_time( + translation["payload"][compare_with_index]["end_time"], + text["start_time"], + )[0] + ): + problem_sentences.append( + { + "index": ind % 50, + "page_number": (ind // 50) + 1, + "start_time": text["start_time"], + "end_time": text["end_time"], + "text": text["text"], + "target_text": text["target_text"], + } + ) return problem_sentences From 930e66e24a4fd6a83a9798ae5c9bf349fb31a5d1 Mon Sep 17 00:00:00 2001 From: Shruti1229 Date: Tue, 25 Jul 2023 02:20:07 +0530 Subject: [PATCH 2/3] Vo bug fix --- backend/voiceover/utils.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/backend/voiceover/utils.py b/backend/voiceover/utils.py index bb360d8d..d72da86c 100644 --- a/backend/voiceover/utils.py +++ b/backend/voiceover/utils.py @@ -400,9 +400,7 @@ def get_bad_sentences(translation_obj, target_language): def get_bad_sentences_in_progress(translation_obj, target_language): - tts_input = [] - empty_sentences = [] - delete_indices = [] + problem_sentences = [] translation = translation_obj.payload for ind, text in enumerate(translation["payload"]): if not compare_time(text["end_time"], text["start_time"])[0]: From a2f63d99c7c8ce5580b2d4a371c7cd734ff29968 Mon Sep 17 00:00:00 2001 From: Shruti1229 Date: Tue, 25 Jul 2023 02:52:42 +0530 Subject: [PATCH 3/3] Return correct page info --- backend/translation/views.py | 36 ++++++++++++++++++------------------ backend/voiceover/utils.py | 13 ++++++++----- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/backend/translation/views.py b/backend/translation/views.py index a68736bc..779505c0 100644 --- a/backend/translation/views.py +++ b/backend/translation/views.py @@ -1266,6 +1266,15 @@ def save_translation(request): task.status = "COMPLETE" task.save() translation_obj.save() + response = check_if_translation_correct(translation_obj, task) + if type(response) == dict: + return Response( + { + "data": response["data"], + "message": response["message"], + }, + status=status.HTTP_400_BAD_REQUEST, + ) delete_indices = [] for index, sentence in enumerate( translation_obj.payload["payload"] @@ -1277,15 +1286,6 @@ def save_translation(request): for ind in delete_indices: translation_obj.payload["payload"].pop(ind) translation_obj.save() - response = check_if_translation_correct(translation_obj, task) - if type(response) == dict: - return Response( - { - "data": response["data"], - "message": response["message"], - }, - status=status.HTTP_400_BAD_REQUEST, - ) message = change_active_status_of_next_tasks( task, translation_obj ) @@ -1374,6 +1374,15 @@ def save_translation(request): limit, payload, start_offset, end_offset, translation_obj ) translation_obj.save() + translation_obj.save() + task.status = "COMPLETE" + task.save() + response = check_if_translation_correct(translation_obj, task) + if type(response) == dict: + return Response( + {"data": response["data"], "message": response["message"]}, + status=status.HTTP_400_BAD_REQUEST, + ) delete_indices = [] for index, sentence in enumerate( translation_obj.payload["payload"] @@ -1384,15 +1393,6 @@ def save_translation(request): delete_indices.reverse() for ind in delete_indices: translation_obj.payload["payload"].pop(ind) - translation_obj.save() - task.status = "COMPLETE" - task.save() - response = check_if_translation_correct(translation_obj, task) - if type(response) == dict: - return Response( - {"data": response["data"], "message": response["message"]}, - status=status.HTTP_400_BAD_REQUEST, - ) message = change_active_status_of_next_tasks(task, translation_obj) else: translation_obj = ( diff --git a/backend/voiceover/utils.py b/backend/voiceover/utils.py index d72da86c..63e15ff5 100644 --- a/backend/voiceover/utils.py +++ b/backend/voiceover/utils.py @@ -402,11 +402,16 @@ def get_bad_sentences(translation_obj, target_language): def get_bad_sentences_in_progress(translation_obj, target_language): problem_sentences = [] translation = translation_obj.payload + compare_with_index = -1 + last_valid_index = -1 for ind, text in enumerate(translation["payload"]): - if not compare_time(text["end_time"], text["start_time"])[0]: + if ( + "text" in text.keys() + and not compare_time(text["end_time"], text["start_time"])[0] + ): problem_sentences.append( { - "index": ind % 50, + "index": (ind % 50) + 1, "page_number": (ind // 50) + 1, "start_time": text["start_time"], "end_time": text["end_time"], @@ -415,8 +420,6 @@ def get_bad_sentences_in_progress(translation_obj, target_language): } ) if ind != 0 and ind < len(translation["payload"]): - compare_with_index = -1 - last_valid_index = -1 compare = False if "text" in translation["payload"][ind - 1] and "text" in text.keys(): compare_with_index = ind - 1 @@ -438,7 +441,7 @@ def get_bad_sentences_in_progress(translation_obj, target_language): ): problem_sentences.append( { - "index": ind % 50, + "index": (ind % 50) + 1, "page_number": (ind // 50) + 1, "start_time": text["start_time"], "end_time": text["end_time"],