Skip to content

Commit fa54c01

Browse files
committed
Add created_at updated_at
1 parent e51cfad commit fa54c01

File tree

6 files changed

+44
-18
lines changed

6 files changed

+44
-18
lines changed

src/superannotate/lib/app/annotation_helpers.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ def _postprocess_annotation_json(annotation_json, path):
3434
return annotation_json
3535

3636

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+
3749
def add_annotation_comment_to_json(
3850
annotation_json,
3951
comment_text,
@@ -64,24 +76,17 @@ def add_annotation_comment_to_json(
6476
annotation_json, image_name=image_name
6577
)
6678

67-
created_at = (
68-
datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%f")[
69-
:-3
70-
]
71-
+ "Z"
72-
)
7379
user_action = {"email": comment_author, "role": "Admin"}
7480

7581
annotation = {
7682
"x": comment_coords[0],
7783
"y": comment_coords[1],
7884
"correspondence": [{"text": comment_text, "email": comment_author}],
7985
"resolved": resolved,
80-
"createdAt": created_at,
81-
"updatedAt": created_at,
8286
"createdBy": user_action,
8387
"updatedBy": user_action,
8488
}
89+
annotation = _add_created_updated(annotation)
8590
annotation_json["comments"].append(annotation)
8691

8792
return _postprocess_annotation_json(annotation_json, path)
@@ -130,6 +135,7 @@ def add_annotation_bbox_to_json(
130135
else annotation_class_attributes,
131136
}
132137

138+
annotation = _add_created_updated(annotation)
133139
annotation_json["instances"].append(annotation)
134140

135141
return _postprocess_annotation_json(annotation_json, path)
@@ -178,6 +184,7 @@ def add_annotation_point_to_json(
178184
else annotation_class_attributes,
179185
}
180186

187+
annotation = _add_created_updated(annotation)
181188
annotation_json["instances"].append(annotation)
182189

183190
return _postprocess_annotation_json(annotation_json, path)

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

Lines changed: 15 additions & 3 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,7 +2507,11 @@ 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(
25082516
annotations,
25092517
point,
@@ -2542,7 +2550,11 @@ def add_annotation_comment_to_image(
25422550
:param resolved: comment resolve status
25432551
:type resolved: bool
25442552
"""
2545-
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"]
25462558
annotations = add_annotation_comment_to_json(
25472559
annotations,
25482560
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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +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
53-
None, alias="pointLabels"
54-
)
51+
Dict[constr(regex=r"^[0-9]+$"), NotEmptyStr] # noqa F722
52+
] = Field(None, alias="pointLabels")
5553
timeline: Dict[float, BboxTimeStamp]
5654

5755

tests/integration/annotations/test_annotation_adding.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ def test_add_point_to_empty_image(self):
6060
self.PROJECT_NAME, self.EXAMPLE_IMAGE_1
6161
)["annotation_json"]
6262

63+
annotations_new["instances"][0]['createdAt'] = ''
64+
annotations_new["instances"][0]['updatedAt'] = ''
65+
6366
self.assertEqual(
6467
annotations_new["instances"][0], {
6568
'x': 250.0,
@@ -73,7 +76,9 @@ def test_add_point_to_empty_image(self):
7376
'type': 'point',
7477
'pointLabels': {},
7578
'groupId': 0,
76-
'classId': -1
79+
'classId': -1,
80+
'createdAt': '',
81+
'updatedAt': ''
7782
})
7883

7984
def test_add_bbox_to_empty_annotation(self):
@@ -89,6 +94,9 @@ def test_add_bbox_to_empty_annotation(self):
8994
self.PROJECT_NAME, self.EXAMPLE_IMAGE_1
9095
)["annotation_json"]
9196

97+
annotations_new["instances"][0]['createdAt'] = ''
98+
annotations_new["instances"][0]['updatedAt'] = ''
99+
92100
self.assertEqual(annotations_new['instances'][0], {
93101
'creationType': 'Preannotation',
94102
'className': 'test_add', 'visible': True,
@@ -98,7 +106,9 @@ def test_add_bbox_to_empty_annotation(self):
98106
'pointLabels': {},
99107
'groupId': 0,
100108
'points': {'x1': 10.0, 'x2': 500.0, 'y1': 10.0, 'y2': 100.0},
101-
'classId': -1
109+
'classId': -1,
110+
'createdAt': '',
111+
'updatedAt': ''
102112
})
103113

104114

tests/unit/test_s3_no_contents.py

Whitespace-only changes.

0 commit comments

Comments
 (0)