Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translation bugs #422

Merged
merged 3 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
47 changes: 20 additions & 27 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 @@ -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"]
Expand All @@ -1277,17 +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
)
Expand Down Expand Up @@ -1376,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"]
Expand All @@ -1386,20 +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 = (
Expand Down
57 changes: 55 additions & 2 deletions 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 @@ -388,7 +388,7 @@ def get_bad_sentences(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"],
Expand All @@ -399,6 +399,59 @@ def get_bad_sentences(translation_obj, target_language):
return problem_sentences


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 (
"text" in text.keys()
and not compare_time(text["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"],
}
)
if ind != 0 and ind < len(translation["payload"]):
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) + 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 process_translation_payload(translation_obj, target_language):
tts_input = []
empty_sentences = []
Expand Down
Loading