Skip to content

Commit e51cfad

Browse files
committed
Add createdat updatedat
1 parent 8202cd9 commit e51cfad

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/superannotate/lib/app/annotation_helpers.py

Lines changed: 13 additions & 1 deletion
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
@@ -63,12 +64,23 @@ def add_annotation_comment_to_json(
6364
annotation_json, image_name=image_name
6465
)
6566

67+
created_at = (
68+
datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%f")[
69+
:-3
70+
]
71+
+ "Z"
72+
)
73+
user_action = {"email": comment_author, "role": "Admin"}
74+
6675
annotation = {
67-
"type": "comment",
6876
"x": comment_coords[0],
6977
"y": comment_coords[1],
7078
"correspondence": [{"text": comment_text, "email": comment_author}],
7179
"resolved": resolved,
80+
"createdAt": created_at,
81+
"updatedAt": created_at,
82+
"createdBy": user_action,
83+
"updatedBy": user_action,
7284
}
7385
annotation_json["comments"].append(annotation)
7486

tests/integration/annotations/test_annotation_adding.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,32 @@ def test_add_bbox_to_empty_annotation(self):
102102
})
103103

104104

105+
def test_add_comment_to_empty_annotation(self):
106+
sa.upload_images_from_folder_to_project(
107+
self.PROJECT_NAME, self.folder_path, annotation_status="InProgress"
108+
)
109+
110+
sa.add_annotation_comment_to_image(self.PROJECT_NAME, self.EXAMPLE_IMAGE_1, "some comment", [1, 2], "abc@abc.com")
111+
112+
annotations_new = sa.get_image_annotations(
113+
self.PROJECT_NAME, self.EXAMPLE_IMAGE_1
114+
)["annotation_json"]
115+
116+
annotations_new['comments'][0]['createdAt'] = ""
117+
annotations_new['comments'][0]['updatedAt'] = ""
118+
119+
self.assertEqual(annotations_new['comments'][0],
120+
{'createdBy': {'email': 'abc@abc.com', 'role': 'Admin'},
121+
'updatedBy': {'email': 'abc@abc.com', 'role': 'Admin'},
122+
'creationType': 'Preannotation',
123+
'createdAt': '',
124+
'updatedAt': '',
125+
'x': 1.0, 'y': 2.0,
126+
'resolved': False,
127+
'correspondence': [{'text': 'some comment', 'email': 'abc@abc.com'}]
128+
})
129+
130+
105131
def test_add_bbox(self):
106132
sa.upload_images_from_folder_to_project(
107133
self.PROJECT_NAME, self.folder_path, annotation_status="InProgress"

0 commit comments

Comments
 (0)