Skip to content

Commit 8b180e0

Browse files
committed
Add assign_images,df_to_annotations
1 parent 55b0a0b commit 8b180e0

File tree

4 files changed

+76
-10
lines changed

4 files changed

+76
-10
lines changed

src/superannotate/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from superannotate.lib.app.analytics.class_analytics import aggregate_annotations_as_df
21
from superannotate.lib.app.analytics.class_analytics import attribute_distribution
32
from superannotate.lib.app.analytics.class_analytics import class_distribution
43
from superannotate.lib.app.annotation_helpers import add_annotation_bbox_to_json
@@ -38,6 +37,7 @@
3837
from superannotate.lib.app.interface.sdk_interface import (
3938
add_annotation_template_to_image,
4039
)
40+
from superannotate.lib.app.interface.sdk_interface import aggregate_annotations_as_df
4141
from superannotate.lib.app.interface.sdk_interface import assign_folder
4242
from superannotate.lib.app.interface.sdk_interface import assign_images
4343
from superannotate.lib.app.interface.sdk_interface import attach_image_urls_to_project

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,7 @@ def delete_images(project, image_names=None):
994994
)
995995

996996

997+
@Trackable
997998
def assign_images(project, image_names, user):
998999
"""Assigns images to a user. The assignment role, QA or Annotator, will
9991000
be deduced from the user's role in the project. With SDK, the user can be
@@ -1009,6 +1010,21 @@ def assign_images(project, image_names, user):
10091010
project_name, folder_name = extract_project_folder(project)
10101011
if not folder_name:
10111012
folder_name = "root"
1013+
1014+
contributors = controller.get_project_metadata(
1015+
project_name=project_name, include_contributors=True
1016+
).data["contributors"]
1017+
contributor = None
1018+
for c in contributors:
1019+
if c["user_id"] == user:
1020+
contributor = user
1021+
1022+
if not contributor:
1023+
logger.warning(
1024+
f"Skipping {user}. {user} is not a verified contributor for the {project_name}"
1025+
)
1026+
return
1027+
10121028
controller.assign_images(project_name, folder_name, image_names, user)
10131029

10141030

@@ -3338,3 +3354,49 @@ def _upload_s3_image(image_path: str):
33383354
duplicates.extend(duplications)
33393355

33403356
return uploaded, failed_images, duplicates
3357+
3358+
3359+
@Trackable
3360+
def aggregate_annotations_as_df(
3361+
project_root,
3362+
include_classes_wo_annotations=False,
3363+
include_comments=False,
3364+
include_tags=False,
3365+
verbose=True,
3366+
folder_names=None,
3367+
):
3368+
"""Aggregate annotations as pandas dataframe from project root.
3369+
3370+
:param project_root: export path of the project
3371+
:type project_root: Pathlike (str or Path)
3372+
:param include_classes_wo_annotations: enables inclusion of classes info
3373+
that have no instances in annotations
3374+
:type include_classes_wo_annotations: bool
3375+
:param include_comments: enables inclusion of comments info as commentResolved column
3376+
:type include_comments: bool
3377+
:param include_tags: enables inclusion of tags info as tag column
3378+
:type include_tags: bool
3379+
:param folder_names: Aggregate the specified folders from project_root.
3380+
If None aggregate all folders in the project_root.
3381+
:type folder_names: (list of str)
3382+
3383+
:return: DataFrame on annotations with columns:
3384+
"imageName", "instanceId",
3385+
"className", "attributeGroupName", "attributeName", "type", "error", "locked",
3386+
"visible", "trackingId", "probability", "pointLabels",
3387+
"meta" (geometry information as string), "commentResolved", "classColor",
3388+
"groupId", "imageWidth", "imageHeight", "imageStatus", "imagePinned",
3389+
"createdAt", "creatorRole", "creationType", "creatorEmail", "updatedAt",
3390+
"updatorRole", "updatorEmail", "tag", "folderName"
3391+
:rtype: pandas DataFrame
3392+
"""
3393+
from superannotate.lib.app.analytics.common import aggregate_annotations_as_df
3394+
3395+
aggregate_annotations_as_df(
3396+
project_root,
3397+
include_classes_wo_annotations,
3398+
include_comments,
3399+
include_tags,
3400+
verbose,
3401+
folder_names,
3402+
)

src/superannotate/lib/app/mixp/utils/parsers.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,20 +1102,24 @@ def assign_images(*args, **kwargs):
11021102
user = kwargs.get("user", None)
11031103
if not user:
11041104
user = args[2]
1105-
from superannotate.db.users import get_team_contributor_metadata
11061105

1107-
res = get_team_contributor_metadata(user)
1106+
contributors = controller.get_project_metadata(
1107+
project_name=project, include_contributors=True
1108+
).data["contributors"]
1109+
contributor = None
1110+
for c in contributors:
1111+
if c["user_id"] == user:
1112+
contributor = c
11081113
user_role = "ADMIN"
1109-
if res["user_role"] == 3:
1114+
if contributor["user_role"] == 3:
11101115
user_role = "ANNOTATOR"
1111-
if res["user_role"] == 4:
1116+
if contributor["user_role"] == 4:
11121117
user_role = "QA"
1113-
from superannotate.db.project_api import get_project_and_folder_metadata
1114-
1115-
project, folder = get_project_and_folder_metadata(project)
1118+
_, folder_name = extract_project_folder(project)
11161119
is_root = True
1117-
if folder:
1120+
if folder_name:
11181121
is_root = False
1122+
11191123
return {
11201124
"event_name": "assign_images",
11211125
"properties": {

src/superannotate/lib/infrastructure/services.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class SuperannotateBackendService(BaseBackendService):
148148
URL_COPY_IMAGES_FROM_FOLDER = "images/copy-image-or-folders"
149149
URL_MOVE_IMAGES_FROM_FOLDER = "image/move"
150150
URL_GET_COPY_PROGRESS = "images/copy-image-progress"
151-
URL_ASSIGN_IMAGES = "images/editAssignment"
151+
URL_ASSIGN_IMAGES = "images/editAssignment/"
152152
URL_ASSIGN_FOLDER = "folder/editAssignment"
153153
URL_S3_ACCESS_POINT = "/project/{}/get-image-s3-access-point"
154154
URL_S3_UPLOAD_STATUS = "/project/{}/getS3UploadStatus"

0 commit comments

Comments
 (0)