Skip to content

Commit

Permalink
Merge pull request #419 from AI4Bharat/translation_bugs
Browse files Browse the repository at this point in the history
Get fail info for inprogress task
  • Loading branch information
Shruti1229 authored Jul 24, 2023
2 parents 3f07d5a + dd44a11 commit df5d31b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 18 deletions.
8 changes: 7 additions & 1 deletion backend/task/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
process_translation_payload,
send_mail_to_user,
get_bad_sentences,
get_bad_sentences_in_progress,
)
from transcript.models import (
Transcript,
Expand Down Expand Up @@ -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(
{
Expand Down
25 changes: 9 additions & 16 deletions backend/translation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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 = (
Expand Down
54 changes: 53 additions & 1 deletion backend/voiceover/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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,
Expand All @@ -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


Expand Down

0 comments on commit df5d31b

Please sign in to comment.