From fa6c3c329ec48f31b31f3882a820f9fc1fa30000 Mon Sep 17 00:00:00 2001 From: kartikvirendrar Date: Mon, 27 Jan 2025 11:33:57 +0530 Subject: [PATCH 1/4] changes for inter-annotator-difference --- backend/projects/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/projects/utils.py b/backend/projects/utils.py index 653c74cc..11b9cad9 100644 --- a/backend/projects/utils.py +++ b/backend/projects/utils.py @@ -530,7 +530,7 @@ def add_extra_task_data(t, project): .filter(review_user__isnull=True) ) total_ratings, seen = [], {} - max_rating, curr_response = float("-inf"), "" + max_rating, curr_response, min_rating = float("-inf"), "", float("inf") for st in similar_tasks: ann = Annotation.objects.filter(task=st, annotation_status=LABELED)[0] for r in ann.result: @@ -558,14 +558,16 @@ def add_extra_task_data(t, project): seen[st.id] = curr_response total_ratings.append(curr_response) max_rating = max(max_rating, curr_response) + min_rating = min(min_rating, curr_response) t.data["avg_rating"] = -1 t.data["curr_rating"] = -1 t.data["inter_annotator_difference"] = -1 if t.id in seen: t.data["avg_rating"] = sum(total_ratings) / len(total_ratings) + t.data["total_rating"] = sum(total_ratings) t.data["curr_rating"] = seen[t.id] t.data["inter_annotator_difference"] = ( - max_rating - seen[t.id] if max_rating > float("-inf") else -1 + max_rating - min_rating if (max_rating > float("-inf") and min_rating < float("inf")) else -1 ) t.save() From b6ad73c2e0af4d05ab60680ceb7105276f46ccb3 Mon Sep 17 00:00:00 2001 From: kartikvirendrar Date: Mon, 27 Jan 2025 11:35:35 +0530 Subject: [PATCH 2/4] fixed black linting error --- backend/dataset/views.py | 6 +-- backend/functions/tasks.py | 24 +++++----- backend/notifications/tasks.py | 4 +- backend/organizations/tasks.py | 20 +++------ backend/organizations/views.py | 14 +++--- backend/projects/utils.py | 4 +- backend/projects/views.py | 16 +++---- backend/tasks/views.py | 80 ++++++++++++++++++---------------- backend/users/views.py | 18 ++++---- backend/utils/search.py | 12 ++--- backend/workspaces/tasks.py | 24 +++------- backend/workspaces/views.py | 4 +- 12 files changed, 104 insertions(+), 122 deletions(-) diff --git a/backend/dataset/views.py b/backend/dataset/views.py index e72d9752..717b85e1 100644 --- a/backend/dataset/views.py +++ b/backend/dataset/views.py @@ -325,9 +325,9 @@ def download(self, request, pk): json_data = json.dumps(exported_items, default=str) # Create a StreamingHttpResponse with the JSON data response = StreamingHttpResponse(json_data, content_type="application/json") - response[ - "Content-Disposition" - ] = f'attachment; filename="{dataset_instance}.json"' + response["Content-Disposition"] = ( + f'attachment; filename="{dataset_instance}.json"' + ) return response return StreamingHttpResponse( exported_items, status=status.HTTP_200_OK, content_type=content_type diff --git a/backend/functions/tasks.py b/backend/functions/tasks.py index 0c656781..69a40567 100644 --- a/backend/functions/tasks.py +++ b/backend/functions/tasks.py @@ -452,15 +452,15 @@ def get_modified_stats_result( for key, value in result_rev_anno_stats.items(): result[f"Reviewer - {key.replace('_', ' ').title()} Annotations"] = value for key, value in result_sup_anno_stats.items(): - result[ - f"Superchecker - {key.replace('_', ' ').title()} Annotations" - ] = value + result[f"Superchecker - {key.replace('_', ' ').title()} Annotations"] = ( + value + ) if meta_stats or complete_stats: for key, value in result_ann_meta_stats.items(): for sub_key in value.keys(): - result[ - f"Annotator - {key.replace('_', ' ').title()} {sub_key}" - ] = value[sub_key] + result[f"Annotator - {key.replace('_', ' ').title()} {sub_key}"] = ( + value[sub_key] + ) for key, value in result_rev_meta_stats.items(): for sub_key in value.keys(): result[f"Reviewer - {key.replace('_', ' ').title()} {sub_key}"] = value[ @@ -468,9 +468,9 @@ def get_modified_stats_result( ] for key, value in result_sup_meta_stats.items(): for sub_key in value.keys(): - result[ - f"Superchecker - {key.replace('_', ' ').title()} {sub_key}" - ] = value[sub_key] + result[f"Superchecker - {key.replace('_', ' ').title()} {sub_key}"] = ( + value[sub_key] + ) # adding unassigned tasks count result["Annotator - Unassigned Tasks"] = get_task_count_unassigned(proj_id, user) @@ -770,9 +770,9 @@ def schedule_mail_to_download_all_projects( query_params = QueryDict(mutable=True) query_params["include_input_data_metadata_json"] = "true" query_params["export_type"] = "CSV" - query_params[ - "task_status" - ] = "incomplete,annotated,reviewed,super_checked,exported" + query_params["task_status"] = ( + "incomplete,annotated,reviewed,super_checked,exported" + ) custom_request = Request(factory.get(url, data=query_params, timeout=15)) custom_request.user = user try: diff --git a/backend/notifications/tasks.py b/backend/notifications/tasks.py index 352a36ae..00ece505 100644 --- a/backend/notifications/tasks.py +++ b/backend/notifications/tasks.py @@ -38,9 +38,7 @@ def create_notification_handler( else ( f"/projects/{project_id}" if project_id - else f"/task/{task_id}" - if task_id - else None + else f"/task/{task_id}" if task_id else None ) ) new_notif = Notification( diff --git a/backend/organizations/tasks.py b/backend/organizations/tasks.py index 2b21de06..8c2d284c 100644 --- a/backend/organizations/tasks.py +++ b/backend/organizations/tasks.py @@ -47,9 +47,7 @@ def get_all_annotation_reports( else ( "Part Time" if participation_type == 2 - else "Contract Basis" - if participation_type == 4 - else "N/A" + else "Contract Basis" if participation_type == 4 else "N/A" ) ) role = get_role_name(user.role) @@ -130,9 +128,7 @@ def get_all_review_reports( else ( "Part Time" if participation_type == 2 - else "Contract Basis" - if participation_type == 4 - else "N/A" + else "Contract Basis" if participation_type == 4 else "N/A" ) ) role = get_role_name(user.role) @@ -246,9 +242,7 @@ def get_all_supercheck_reports( else ( "Part Time" if user.participation_type == 2 - else "Contract Basis" - if user.participation_type == 4 - else "N/A" + else "Contract Basis" if user.participation_type == 4 else "N/A" ) ) role = get_role_name(user.role) @@ -464,9 +458,7 @@ def send_user_reports_mail_org( else ( "Part Time" if participation_type == 2 - else "Contract Basis" - if participation_type == 4 - else "N/A" + else "Contract Basis" if participation_type == 4 else "N/A" ) ) for participation_type in participation_types @@ -1199,9 +1191,7 @@ def send_user_analytics_mail_org( else ( "Part Time" if participation_type == 2 - else "Contract Basis" - if participation_type == 4 - else "N/A" + else "Contract Basis" if participation_type == 4 else "N/A" ) ) role = get_role_name(annotator.role) diff --git a/backend/organizations/views.py b/backend/organizations/views.py index 9fc52f09..ac3a03d4 100644 --- a/backend/organizations/views.py +++ b/backend/organizations/views.py @@ -456,9 +456,7 @@ def quality_reports(self, request, pk=None): else ( "Part Time" if participation_type == 2 - else "Contract Basis" - if participation_type == 4 - else "N/A" + else "Contract Basis" if participation_type == 4 else "N/A" ) ) role = get_role_name(annotator.role) @@ -776,9 +774,7 @@ def user_analytics(self, request, pk=None): else ( "Part Time" if participation_type == 2 - else "Contract Basis" - if participation_type == 4 - else "N/A" + else "Contract Basis" if participation_type == 4 else "N/A" ) ) role = get_role_name(annotator.role) @@ -902,9 +898,9 @@ def iter_items(items, pseudo_buffer): status=status.HTTP_200_OK, content_type="text/csv", ) - response[ - "Content-Disposition" - ] = f'attachment; filename="{organization.title}_user_analytics.csv"' + response["Content-Disposition"] = ( + f'attachment; filename="{organization.title}_user_analytics.csv"' + ) return response return Response(data=final_result, status=status.HTTP_200_OK) diff --git a/backend/projects/utils.py b/backend/projects/utils.py index 11b9cad9..c08a943a 100644 --- a/backend/projects/utils.py +++ b/backend/projects/utils.py @@ -567,7 +567,9 @@ def add_extra_task_data(t, project): t.data["total_rating"] = sum(total_ratings) t.data["curr_rating"] = seen[t.id] t.data["inter_annotator_difference"] = ( - max_rating - min_rating if (max_rating > float("-inf") and min_rating < float("inf")) else -1 + max_rating - min_rating + if (max_rating > float("-inf") and min_rating < float("inf")) + else -1 ) t.save() diff --git a/backend/projects/views.py b/backend/projects/views.py index 41d61296..458a46bd 100644 --- a/backend/projects/views.py +++ b/backend/projects/views.py @@ -636,9 +636,9 @@ def get_supercheck_reports(proj_id, userid, start_date, end_date): result["Rejected Word Count"] = rejected_word_count elif proj_type in get_audio_project_types(): result["Validated Segments Duration"] = validated_audio_duration - result[ - "Validated With Changes Segments Duration" - ] = validated_with_changes_audio_duration + result["Validated With Changes Segments Duration"] = ( + validated_with_changes_audio_duration + ) result["Rejected Segments Duration"] = rejected_audio_duration result["Total Raw Audio Duration"] = total_raw_audio_duration result["Average Word Error Rate R/S"] = round(avg_word_error_rate, 2) @@ -3790,11 +3790,11 @@ def download(self, request, pk=None, *args, **kwargs): if include_input_data_metadata_json: dataset_type = project.dataset_id.all()[0].dataset_type dataset_model = getattr(dataset_models, dataset_type) - task_dict["data"][ - "input_data_metadata_json" - ] = dataset_model.objects.get( - pk=task_dict["input_data"] - ).metadata_json + task_dict["data"]["input_data_metadata_json"] = ( + dataset_model.objects.get( + pk=task_dict["input_data"] + ).metadata_json + ) del task_dict["annotation_users"] del task_dict["review_user"] tasks_list.append(OrderedDict(task_dict)) diff --git a/backend/tasks/views.py b/backend/tasks/views.py index 35fdd801..19d47a99 100644 --- a/backend/tasks/views.py +++ b/backend/tasks/views.py @@ -1215,12 +1215,16 @@ def get_users_recent_tasks(self, request): "Project ID": annotation.task.project_id.id, "Task ID": annotation.task.id, "Updated at": utc_to_ist(annotation.updated_at), - "Annotated at": utc_to_ist(annotation.annotated_at) - if annotation.annotated_at - else None, - "Created at": utc_to_ist(annotation.created_at) - if annotation.created_at - else None, + "Annotated at": ( + utc_to_ist(annotation.annotated_at) + if annotation.annotated_at + else None + ), + "Created at": ( + utc_to_ist(annotation.created_at) + if annotation.created_at + else None + ), } response.append(data) @@ -1656,16 +1660,16 @@ def partial_update(self, request, pk=None): and len(annotation_obj.result) > len(request.data["result"]) ): request.data["result"] = annotation_obj.result - request.data[ - "meta_stats" - ] = compute_meta_stats_for_instruction_driven_chat( - annotation_obj.result + request.data["meta_stats"] = ( + compute_meta_stats_for_instruction_driven_chat( + annotation_obj.result + ) ) else: - request.data[ - "meta_stats" - ] = compute_meta_stats_for_instruction_driven_chat( - request.data["result"] + request.data["meta_stats"] = ( + compute_meta_stats_for_instruction_driven_chat( + request.data["result"] + ) ) annotation_response = super().partial_update(request) if is_IDC: @@ -1844,16 +1848,16 @@ def partial_update(self, request, pk=None): and len(annotation_obj.result) > len(request.data["result"]) ): request.data["result"] = annotation_obj.result - request.data[ - "meta_stats" - ] = compute_meta_stats_for_instruction_driven_chat( - annotation_obj.result + request.data["meta_stats"] = ( + compute_meta_stats_for_instruction_driven_chat( + annotation_obj.result + ) ) else: - request.data[ - "meta_stats" - ] = compute_meta_stats_for_instruction_driven_chat( - request.data["result"] + request.data["meta_stats"] = ( + compute_meta_stats_for_instruction_driven_chat( + request.data["result"] + ) ) annotation_response = super().partial_update(request) if is_IDC: @@ -2053,16 +2057,16 @@ def partial_update(self, request, pk=None): and len(annotation_obj.result) > len(request.data["result"]) ): request.data["result"] = annotation_obj.result - request.data[ - "meta_stats" - ] = compute_meta_stats_for_instruction_driven_chat( - annotation_obj.result + request.data["meta_stats"] = ( + compute_meta_stats_for_instruction_driven_chat( + annotation_obj.result + ) ) else: - request.data[ - "meta_stats" - ] = compute_meta_stats_for_instruction_driven_chat( - request.data["result"] + request.data["meta_stats"] = ( + compute_meta_stats_for_instruction_driven_chat( + request.data["result"] + ) ) annotation_response = super().partial_update(request) if is_IDC: @@ -2197,9 +2201,11 @@ def convert_chitralekha_format_to_LSF( text_dict = { "origin": "manual", "to_name": "audio_url", - "from_name": "transcribed_json" - if not is_acoustic - else "verbatim_transcribed_json", + "from_name": ( + "transcribed_json" + if not is_acoustic + else "verbatim_transcribed_json" + ), "original_length": audio_duration, } @@ -2479,19 +2485,19 @@ def get_celery_tasks(request): for i in filtered_tasks: if filtered_tasks[i]["succeeded"] is not None: filtered_tasks[i]["succeeded"] = datetime.fromtimestamp( - filtered_tasks[i]["succeeded"],tz=timezone.utc + filtered_tasks[i]["succeeded"], tz=timezone.utc ).strftime("%Y-%m-%dT%H:%M:%S.%fZ") if filtered_tasks[i]["failed"] is not None: filtered_tasks[i]["failed"] = datetime.fromtimestamp( - filtered_tasks[i]["failed"],tz=timezone.utc + filtered_tasks[i]["failed"], tz=timezone.utc ).strftime("%Y-%m-%dT%H:%M:%S.%fZ") if filtered_tasks[i]["started"] is not None: filtered_tasks[i]["started"] = datetime.fromtimestamp( - filtered_tasks[i]["started"],tz=timezone.utc + filtered_tasks[i]["started"], tz=timezone.utc ).strftime("%Y-%m-%dT%H:%M:%S.%fZ") if filtered_tasks[i]["received"] is not None: filtered_tasks[i]["received"] = datetime.fromtimestamp( - filtered_tasks[i]["received"],tz=timezone.utc + filtered_tasks[i]["received"], tz=timezone.utc ).strftime("%Y-%m-%dT%H:%M:%S.%fZ") if "error" in filtered_tasks: diff --git a/backend/users/views.py b/backend/users/views.py index afdd0b79..59dc9dad 100644 --- a/backend/users/views.py +++ b/backend/users/views.py @@ -1807,16 +1807,16 @@ def get_scheduled_mails(self, request, pk=None): schedule = ( "Daily" if task.schedule == 1 - else "Weekly" - if task.schedule == 2 - else "Monthly" + else "Weekly" if task.schedule == 2 else "Monthly" ) scheduled_day = ( calendar.day_name[int(task.celery_task.crontab.day_of_week) - 1] if task.schedule == 2 - else task.celery_task.crontab.day_of_month - if task.schedule == 3 - else None + else ( + task.celery_task.crontab.day_of_month + if task.schedule == 3 + else None + ) ) result.append( { @@ -1829,9 +1829,9 @@ def get_scheduled_mails(self, request, pk=None): "Scheduled Day": scheduled_day, "Created At": task.created_at, "Run Count": task.celery_task.total_run_count, - "Status": "Enabled" - if task.celery_task.enabled == True - else "Disabled", + "Status": ( + "Enabled" if task.celery_task.enabled == True else "Disabled" + ), } ) result = sorted(result, key=lambda x: x["Created At"], reverse=True) diff --git a/backend/utils/search.py b/backend/utils/search.py index 63663722..61ac0fd2 100644 --- a/backend/utils/search.py +++ b/backend/utils/search.py @@ -65,18 +65,18 @@ def process_search_query( print({i: j}) if i in searchable_fields: if type(parsed_value) == str: - queryset_dict[ - f"{search_field_name}__{i}__icontains" - ] = parsed_value # Unaccent doesn't work as intended. + queryset_dict[f"{search_field_name}__{i}__icontains"] = ( + parsed_value # Unaccent doesn't work as intended. + ) else: queryset_dict[f"{search_field_name}__{i}"] = parsed_value else: if type(parsed_value) != str: queryset_dict[i] = parse_for_data_types(j) else: - queryset_dict[ - f"{i}__icontains" - ] = parsed_value # Unaccent is not supported for CharField + queryset_dict[f"{i}__icontains"] = ( + parsed_value # Unaccent is not supported for CharField + ) except Exception as e: print(f"\033[1mError found while processing query dictionary. In: {e}\033[0m") diff --git a/backend/workspaces/tasks.py b/backend/workspaces/tasks.py index 4505ed22..b2b663c9 100644 --- a/backend/workspaces/tasks.py +++ b/backend/workspaces/tasks.py @@ -43,9 +43,7 @@ def get_all_annotation_reports( else ( "Part Time" if participation_type == 2 - else "Contract Basis" - if participation_type == 4 - else "N/A" + else "Contract Basis" if participation_type == 4 else "N/A" ) ) role = get_role_name(user.role) @@ -126,9 +124,7 @@ def get_all_review_reports( else ( "Part Time" if participation_type == 2 - else "Contract Basis" - if participation_type == 4 - else "N/A" + else "Contract Basis" if participation_type == 4 else "N/A" ) ) role = get_role_name(user.role) @@ -243,9 +239,7 @@ def get_all_supercheck_reports( else ( "Part Time" if user.participation_type == 2 - else "Contract Basis" - if user.participation_type == 4 - else "N/A" + else "Contract Basis" if user.participation_type == 4 else "N/A" ) ) role = get_role_name(user.role) @@ -468,9 +462,7 @@ def send_user_reports_mail_ws( else ( "Part Time" if participation_type == 2 - else "Contract Basis" - if participation_type == 4 - else "N/A" + else "Contract Basis" if participation_type == 4 else "N/A" ) ) for participation_type in participation_types @@ -907,9 +899,7 @@ def get_supercheck_reports(proj_ids, userid, start_date, end_date, project_type= else ( "Part Time" if participation_type == 2 - else "Contract Basis" - if participation_type == 4 - else "N/A" + else "Contract Basis" if participation_type == 4 else "N/A" ) ) role = get_role_name(user.role) @@ -1076,9 +1066,7 @@ def get_review_reports( else ( "Part Time" if participation_type == 2 - else "Contract Basis" - if participation_type == 4 - else "N/A" + else "Contract Basis" if participation_type == 4 else "N/A" ) ) role = get_role_name(user.role) diff --git a/backend/workspaces/views.py b/backend/workspaces/views.py index df717f61..1ba67a95 100644 --- a/backend/workspaces/views.py +++ b/backend/workspaces/views.py @@ -164,7 +164,9 @@ def list_guest_workspaces(self, request): authenticated_workspaces = guest_workspaces.filter(members=request.user) serializer = WorkspaceSerializer(guest_workspaces, many=True) for workspace in serializer.data: - workspace["is_autheticated"]= workspace["id"] in authenticated_workspaces.values_list("id",flat=True) + workspace["is_autheticated"] = workspace[ + "id" + ] in authenticated_workspaces.values_list("id", flat=True) return Response(serializer.data, status=status.HTTP_200_OK) except Exception as e: return Response( From 96eb8b58cf718ac71a9c75e7d4d554979b1a7515 Mon Sep 17 00:00:00 2001 From: Kartik Virendra Rajput <88619994+kartikvirendrar@users.noreply.github.com> Date: Mon, 27 Jan 2025 11:36:44 +0530 Subject: [PATCH 3/4] Update linters.yml --- .github/workflows/linters.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index adaca638..f46dfaa3 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -5,7 +5,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - name: Set up Python 3.9.20 + - name: Set up Python 3.9.21 uses: actions/setup-python@v1 with: python-version: 3.9.20 From f191f60195a6938e89b656780ba6a60c88714519 Mon Sep 17 00:00:00 2001 From: Kartik Virendra Rajput <88619994+kartikvirendrar@users.noreply.github.com> Date: Mon, 27 Jan 2025 11:36:59 +0530 Subject: [PATCH 4/4] Update linters.yml --- .github/workflows/linters.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index f46dfaa3..73ff1bf2 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -8,7 +8,7 @@ jobs: - name: Set up Python 3.9.21 uses: actions/setup-python@v1 with: - python-version: 3.9.20 + python-version: 3.9.21 - name: Debug Message - Check Github branch run: echo "Current Git branch is ${GITHUB_REF##*/}" - name: Install Black