Skip to content

Commit

Permalink
black filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
KunalTiwary committed Sep 19, 2024
1 parent f6cf078 commit 568ac0e
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 126 deletions.
126 changes: 84 additions & 42 deletions backend/organizations/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
un_pack_annotation_tasks,
)
from django.db.models import Q
from tasks.utils import calculateWordCount, calculateAudioDuration, calculateSentenceCount
from tasks.utils import (
calculateWordCount,
calculateAudioDuration,
calculateSentenceCount,
)


def get_all_annotation_reports(
Expand Down Expand Up @@ -209,13 +213,19 @@ def get_all_annotation_reports(
meta_stats = []
if project_type == "AllAudioProjects":
if "acoustic_normalised_duration" in meta_stats:
acoustic_normalised_duration.append(meta_stats["acoustic_normalised_duration"])
acoustic_normalised_duration.append(
meta_stats["acoustic_normalised_duration"]
)
else:
for r in anno.result:
if r["from_name"] == "acoustic_normalised_transcribed_json":
acoustic_normalised_duration.append(calculateAudioDuration(r))
acoustic_normalised_duration.append(
calculateAudioDuration(r)
)
if "acoustic_normalised_word_count" in meta_stats:
acoustic_normalised_word_count.append(meta_stats["acoustic_normalised_word_count"])
acoustic_normalised_word_count.append(
meta_stats["acoustic_normalised_word_count"]
)
else:
for r in anno.result:
if r["from_name"] == "acoustic_normalised_transcribed_json":
Expand Down Expand Up @@ -246,13 +256,19 @@ def get_all_annotation_reports(
transcribed_word_count.append(calculateAudioDuration(r))
elif project_type == "AcousticNormalisedTranscriptionEditing":
if "acoustic_normalised_duration" in meta_stats:
acoustic_normalised_duration.append(meta_stats["acoustic_normalised_duration"])
acoustic_normalised_duration.append(
meta_stats["acoustic_normalised_duration"]
)
else:
for r in anno.result:
if r["from_name"] == "acoustic_normalised_transcribed_json":
acoustic_normalised_duration.append(calculateAudioDuration(r))
acoustic_normalised_duration.append(
calculateAudioDuration(r)
)
if "acoustic_normalised_word_count" in meta_stats:
acoustic_normalised_word_count.append(meta_stats["acoustic_normalised_word_count"])
acoustic_normalised_word_count.append(
meta_stats["acoustic_normalised_word_count"]
)
else:
for r in anno.result:
if r["from_name"] == "acoustic_normalised_transcribed_json":
Expand Down Expand Up @@ -283,9 +299,7 @@ def get_all_annotation_reports(
if r["from_name"] == "transcribed_json":
transcribed_word_count.append(calculateAudioDuration(r))
try:
total_raw_audio_duration_list.append(
anno.task.data["audio_duration"]
)
total_raw_audio_duration_list.append(anno.task.data["audio_duration"])
except:
pass
if "total_segment_duration" in meta_stats:
Expand All @@ -301,18 +315,20 @@ def get_all_annotation_reports(
only_tasks = True
total_raw_audio_duration, total_word_count = 0, 0
if project_type in get_audio_project_types() or project_type == "AllAudioProjects":
acoustic_normalised_duration = convert_seconds_to_hours(sum(acoustic_normalised_duration))
acoustic_normalised_duration = convert_seconds_to_hours(
sum(acoustic_normalised_duration)
)
verbatim_duration = convert_seconds_to_hours(sum(verbatim_duration))
transcribed_duration = convert_seconds_to_hours(sum(transcribed_duration))
acoustic_normalised_word_count = convert_seconds_to_hours(sum(acoustic_normalised_word_count))
acoustic_normalised_word_count = convert_seconds_to_hours(
sum(acoustic_normalised_word_count)
)
verbatim_word_count = convert_seconds_to_hours(sum(verbatim_word_count))
transcribed_word_count = convert_seconds_to_hours(sum(transcribed_word_count))
total_raw_audio_duration = convert_seconds_to_hours(
sum(total_raw_audio_duration_list)
)
total_segment_duration = convert_seconds_to_hours(
sum(total_segment_duration)
)
total_segment_duration = convert_seconds_to_hours(sum(total_segment_duration))
else:
total_word_count = sum(total_word_count_list)
cumulative_rejection_score_ar = 0
Expand Down Expand Up @@ -559,19 +575,25 @@ def get_all_review_reports(
else:
total_word_count_list.append(ocr_word_count(anno.result))
elif (
project_type in get_audio_project_types() or project_type == "AllAudioProjects"
project_type in get_audio_project_types() or project_type == "AllAudioProjects"
):
for anno in submitted_tasks:
meta_stats = anno.meta_stats
if project_type == "AllAudioProjects":
if "acoustic_normalised_duration" in meta_stats:
acoustic_normalised_duration.append(meta_stats["acoustic_normalised_duration"])
acoustic_normalised_duration.append(
meta_stats["acoustic_normalised_duration"]
)
else:
for r in anno.result:
if r["from_name"] == "acoustic_normalised_transcribed_json":
acoustic_normalised_duration.append(calculateAudioDuration(r))
acoustic_normalised_duration.append(
calculateAudioDuration(r)
)
if "acoustic_normalised_word_count" in meta_stats:
acoustic_normalised_word_count.append(meta_stats["acoustic_normalised_word_count"])
acoustic_normalised_word_count.append(
meta_stats["acoustic_normalised_word_count"]
)
else:
for r in anno.result:
if r["from_name"] == "acoustic_normalised_transcribed_json":
Expand Down Expand Up @@ -602,13 +624,19 @@ def get_all_review_reports(
transcribed_word_count.append(calculateAudioDuration(r))
elif project_type == "AcousticNormalisedTranscriptionEditing":
if "acoustic_normalised_duration" in meta_stats:
acoustic_normalised_duration.append(meta_stats["acoustic_normalised_duration"])
acoustic_normalised_duration.append(
meta_stats["acoustic_normalised_duration"]
)
else:
for r in anno.result:
if r["from_name"] == "acoustic_normalised_transcribed_json":
acoustic_normalised_duration.append(calculateAudioDuration(r))
acoustic_normalised_duration.append(
calculateAudioDuration(r)
)
if "acoustic_normalised_word_count" in meta_stats:
acoustic_normalised_word_count.append(meta_stats["acoustic_normalised_word_count"])
acoustic_normalised_word_count.append(
meta_stats["acoustic_normalised_word_count"]
)
else:
for r in anno.result:
if r["from_name"] == "acoustic_normalised_transcribed_json":
Expand Down Expand Up @@ -648,28 +676,28 @@ def get_all_review_reports(
except:
pass
try:
total_raw_audio_duration_list.append(
anno.task.data["audio_duration"]
)
total_raw_audio_duration_list.append(anno.task.data["audio_duration"])
except:
pass
else:
only_tasks = True

total_raw_audio_duration, total_word_count = 0, 0
if project_type in get_audio_project_types() or project_type == "AllAudioProjects":
acoustic_normalised_duration = convert_seconds_to_hours(sum(acoustic_normalised_duration))
acoustic_normalised_duration = convert_seconds_to_hours(
sum(acoustic_normalised_duration)
)
verbatim_duration = convert_seconds_to_hours(sum(verbatim_duration))
transcribed_duration = convert_seconds_to_hours(sum(transcribed_duration))
acoustic_normalised_word_count = convert_seconds_to_hours(sum(acoustic_normalised_word_count))
acoustic_normalised_word_count = convert_seconds_to_hours(
sum(acoustic_normalised_word_count)
)
verbatim_word_count = convert_seconds_to_hours(sum(verbatim_word_count))
transcribed_word_count = convert_seconds_to_hours(sum(transcribed_word_count))
total_raw_audio_duration = convert_seconds_to_hours(
sum(total_raw_audio_duration_list)
)
total_segment_duration = convert_seconds_to_hours(
sum(total_segment_duration)
)
total_segment_duration = convert_seconds_to_hours(sum(total_segment_duration))
else:
total_word_count = sum(total_word_count_list)
cumulative_rejection_score_ar = 0
Expand Down Expand Up @@ -845,19 +873,25 @@ def get_all_supercheck_reports(
else:
validated_word_count_list.append(ocr_word_count(anno.result))
elif (
project_type in get_audio_project_types() or project_type == "AllAudioProjects"
project_type in get_audio_project_types() or project_type == "AllAudioProjects"
):
for anno in submitted_tasks:
meta_stats = anno.meta_stats
if project_type == "AllAudioProjects":
if "acoustic_normalised_duration" in meta_stats:
acoustic_normalised_duration.append(meta_stats["acoustic_normalised_duration"])
acoustic_normalised_duration.append(
meta_stats["acoustic_normalised_duration"]
)
else:
for r in anno.result:
if r["from_name"] == "acoustic_normalised_transcribed_json":
acoustic_normalised_duration.append(calculateAudioDuration(r))
acoustic_normalised_duration.append(
calculateAudioDuration(r)
)
if "acoustic_normalised_word_count" in meta_stats:
acoustic_normalised_word_count.append(meta_stats["acoustic_normalised_word_count"])
acoustic_normalised_word_count.append(
meta_stats["acoustic_normalised_word_count"]
)
else:
for r in anno.result:
if r["from_name"] == "acoustic_normalised_transcribed_json":
Expand Down Expand Up @@ -888,13 +922,19 @@ def get_all_supercheck_reports(
transcribed_word_count.append(calculateAudioDuration(r))
elif project_type == "AcousticNormalisedTranscriptionEditing":
if "acoustic_normalised_duration" in meta_stats:
acoustic_normalised_duration.append(meta_stats["acoustic_normalised_duration"])
acoustic_normalised_duration.append(
meta_stats["acoustic_normalised_duration"]
)
else:
for r in anno.result:
if r["from_name"] == "acoustic_normalised_transcribed_json":
acoustic_normalised_duration.append(calculateAudioDuration(r))
acoustic_normalised_duration.append(
calculateAudioDuration(r)
)
if "acoustic_normalised_word_count" in meta_stats:
acoustic_normalised_word_count.append(meta_stats["acoustic_normalised_word_count"])
acoustic_normalised_word_count.append(
meta_stats["acoustic_normalised_word_count"]
)
else:
for r in anno.result:
if r["from_name"] == "acoustic_normalised_transcribed_json":
Expand Down Expand Up @@ -944,18 +984,20 @@ def get_all_supercheck_reports(

validated_raw_audio_duration, validated_word_count = 0, 0
if project_type in get_audio_project_types() or project_type == "AllAudioProjects":
acoustic_normalised_duration = convert_seconds_to_hours(sum(acoustic_normalised_duration))
acoustic_normalised_duration = convert_seconds_to_hours(
sum(acoustic_normalised_duration)
)
verbatim_duration = convert_seconds_to_hours(sum(verbatim_duration))
transcribed_duration = convert_seconds_to_hours(sum(transcribed_duration))
acoustic_normalised_word_count = convert_seconds_to_hours(sum(acoustic_normalised_word_count))
acoustic_normalised_word_count = convert_seconds_to_hours(
sum(acoustic_normalised_word_count)
)
verbatim_word_count = convert_seconds_to_hours(sum(verbatim_word_count))
transcribed_word_count = convert_seconds_to_hours(sum(transcribed_word_count))
validated_raw_audio_duration = convert_seconds_to_hours(
sum(validated_raw_audio_duration_list)
)
total_segment_duration = convert_seconds_to_hours(
sum(total_segment_duration)
)
total_segment_duration = convert_seconds_to_hours(sum(total_segment_duration))
else:
validated_word_count = sum(validated_word_count_list)
cumulative_rejection_score_rs = 0
Expand Down
14 changes: 9 additions & 5 deletions backend/tasks/migrations/0049_annotation_meta_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@


class Migration(migrations.Migration):

dependencies = [
('tasks', '0048_alter_annotation_unique_together'),
("tasks", "0048_alter_annotation_unique_together"),
]

operations = [
migrations.AddField(
model_name='annotation',
name='meta_stats',
field=models.JSONField(blank=True, help_text='Meta statistics for the annotation result', null=True, verbose_name='meta_stats'),
model_name="annotation",
name="meta_stats",
field=models.JSONField(
blank=True,
help_text="Meta statistics for the annotation result",
null=True,
verbose_name="meta_stats",
),
),
]
Loading

0 comments on commit 568ac0e

Please sign in to comment.