Skip to content

Commit c62d29a

Browse files
authored
Merge pull request #346 from superannotateai/friday
Friday
2 parents 02d11ff + 56a8457 commit c62d29a

File tree

17 files changed

+322
-147
lines changed

17 files changed

+322
-147
lines changed

src/superannotate/lib/app/analytics/aggregators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import copy
22
import json
33
import logging
4-
from dataclasses import dataclass
54
from pathlib import Path
65
from typing import List
76
from typing import Optional
87
from typing import Union
98

109
import lib.core as constances
1110
import pandas as pd
11+
from dataclasses import dataclass
1212
from lib.app.exceptions import AppException
1313
from lib.core import ATTACHED_VIDEO_ANNOTATION_POSTFIX
1414
from lib.core import PIXEL_ANNOTATION_POSTFIX

src/superannotate/lib/app/annotation_helpers.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""SuperAnnotate format annotation JSON helpers"""
2+
import datetime
23
import json
34

45
from superannotate.lib.app.exceptions import AppException
@@ -33,6 +34,18 @@ def _postprocess_annotation_json(annotation_json, path):
3334
return annotation_json
3435

3536

37+
def _add_created_updated(annotation):
38+
created_at = (
39+
datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%f")[
40+
:-3
41+
]
42+
+ "Z"
43+
)
44+
annotation["createdAt"] = created_at
45+
annotation["updatedAt"] = created_at
46+
return annotation
47+
48+
3649
def add_annotation_comment_to_json(
3750
annotation_json,
3851
comment_text,
@@ -63,13 +76,17 @@ def add_annotation_comment_to_json(
6376
annotation_json, image_name=image_name
6477
)
6578

79+
user_action = {"email": comment_author, "role": "Admin"}
80+
6681
annotation = {
67-
"type": "comment",
6882
"x": comment_coords[0],
6983
"y": comment_coords[1],
7084
"correspondence": [{"text": comment_text, "email": comment_author}],
7185
"resolved": resolved,
86+
"createdBy": user_action,
87+
"updatedBy": user_action,
7288
}
89+
annotation = _add_created_updated(annotation)
7390
annotation_json["comments"].append(annotation)
7491

7592
return _postprocess_annotation_json(annotation_json, path)
@@ -118,6 +135,7 @@ def add_annotation_bbox_to_json(
118135
else annotation_class_attributes,
119136
}
120137

138+
annotation = _add_created_updated(annotation)
121139
annotation_json["instances"].append(annotation)
122140

123141
return _postprocess_annotation_json(annotation_json, path)
@@ -127,6 +145,7 @@ def add_annotation_point_to_json(
127145
annotation_json,
128146
point,
129147
annotation_class_name,
148+
image_name,
130149
annotation_class_attributes=None,
131150
error=None,
132151
):
@@ -148,7 +167,7 @@ def add_annotation_point_to_json(
148167
if len(point) != 2:
149168
raise AppException("Point should be 2 element float list.")
150169

151-
annotation_json, path = _preprocess_annotation_json(annotation_json)
170+
annotation_json, path = _preprocess_annotation_json(annotation_json, image_name)
152171

153172
annotation = {
154173
"type": "point",
@@ -165,6 +184,7 @@ def add_annotation_point_to_json(
165184
else annotation_class_attributes,
166185
}
167186

187+
annotation = _add_created_updated(annotation)
168188
annotation_json["instances"].append(annotation)
169189

170190
return _postprocess_annotation_json(annotation_json, path)

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,7 +2461,11 @@ def add_annotation_bbox_to_image(
24612461
:param error: if not None, marks annotation as error (True) or no-error (False)
24622462
:type error: bool
24632463
"""
2464-
annotations = get_image_annotations(project, image_name)["annotation_json"]
2464+
project_name, folder_name = extract_project_folder(project)
2465+
response = controller.get_image_annotations(
2466+
project_name=project_name, folder_name=folder_name, image_name=image_name
2467+
)
2468+
annotations = response.data["annotation_json"]
24652469
annotations = add_annotation_bbox_to_json(
24662470
annotations,
24672471
bbox,
@@ -2503,9 +2507,18 @@ def add_annotation_point_to_image(
25032507
:param error: if not None, marks annotation as error (True) or no-error (False)
25042508
:type error: bool
25052509
"""
2506-
annotations = get_image_annotations(project, image_name)["annotation_json"]
2510+
project_name, folder_name = extract_project_folder(project)
2511+
response = controller.get_image_annotations(
2512+
project_name=project_name, folder_name=folder_name, image_name=image_name
2513+
)
2514+
annotations = response.data["annotation_json"]
25072515
annotations = add_annotation_point_to_json(
2508-
annotations, point, annotation_class_name, annotation_class_attributes, error
2516+
annotations,
2517+
point,
2518+
annotation_class_name,
2519+
image_name,
2520+
annotation_class_attributes,
2521+
error,
25092522
)
25102523
controller.upload_image_annotations(
25112524
*extract_project_folder(project), image_name, annotations
@@ -2537,7 +2550,11 @@ def add_annotation_comment_to_image(
25372550
:param resolved: comment resolve status
25382551
:type resolved: bool
25392552
"""
2540-
annotations = get_image_annotations(project, image_name)["annotation_json"]
2553+
project_name, folder_name = extract_project_folder(project)
2554+
response = controller.get_image_annotations(
2555+
project_name=project_name, folder_name=folder_name, image_name=image_name
2556+
)
2557+
annotations = response.data["annotation_json"]
25412558
annotations = add_annotation_comment_to_json(
25422559
annotations,
25432560
comment_text,

src/superannotate/lib/core/entities/project_entities.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from typing import Iterable
55
from typing import List
66

7-
import lib.core as constances
87
from lib.core.enums import SegmentationStatus
98

109

src/superannotate/lib/core/entities/video.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ class BaseVideoInstance(BaseInstance):
4848

4949
class BboxInstance(BaseVideoInstance):
5050
point_labels: Optional[
51-
Dict[constr(regex=r"^[0-9]+$"), NotEmptyStr]
52-
] = Field( # noqa F722
51+
Dict[constr(regex=r"^[0-9]+$"), NotEmptyStr] # noqa F722
52+
] = Field(
5353
None, alias="pointLabels"
5454
)
5555
timeline: Dict[float, BboxTimeStamp]

src/superannotate/lib/core/usecases/images.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@
3535
from lib.core.exceptions import ImageProcessingException
3636
from lib.core.plugin import ImagePlugin
3737
from lib.core.plugin import VideoPlugin
38+
from lib.core.reporter import Reporter
3839
from lib.core.repositories import BaseManageableRepository
3940
from lib.core.repositories import BaseReadOnlyRepository
4041
from lib.core.response import Response
4142
from lib.core.serviceproviders import SuerannotateServiceProvider
4243
from lib.core.usecases.base import BaseInteractiveUseCase
44+
from lib.core.usecases.base import BaseReportableUseCae
4345
from lib.core.usecases.base import BaseUseCase
4446
from lib.core.usecases.projects import GetAnnotationClassesUseCase
4547
from lib.core.validators import BaseAnnotationValidator
@@ -2463,16 +2465,17 @@ def execute(self):
24632465
return self._response
24642466

24652467

2466-
class GetImageAnnotationsUseCase(BaseUseCase):
2468+
class GetImageAnnotationsUseCase(BaseReportableUseCae):
24672469
def __init__(
24682470
self,
2471+
reporter: Reporter,
24692472
service: SuerannotateServiceProvider,
24702473
project: ProjectEntity,
24712474
folder: FolderEntity,
24722475
image_name: str,
24732476
images: BaseManageableRepository,
24742477
):
2475-
super().__init__()
2478+
super().__init__(reporter)
24762479
self._service = service
24772480
self._project = project
24782481
self._folder = folder
@@ -2524,7 +2527,7 @@ def execute(self):
25242527
headers=credentials["annotation_json_path"]["headers"],
25252528
)
25262529
if not response.ok:
2527-
logger.warning("Couldn't load annotations.")
2530+
self.reporter.log_warning("Couldn't load annotations.")
25282531
self._response.data = data
25292532
return self._response
25302533
data["annotation_json"] = response.json()

0 commit comments

Comments
 (0)