11"""SuperAnnotate format annotation JSON helpers"""
2+ import datetime
23import json
34
45from 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+
3649def 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 )
0 commit comments