Skip to content

Commit 6fc1298

Browse files
committed
add user metadata for comment
1 parent f6f1d65 commit 6fc1298

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

superannotate/analytics/common.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import logging
33
from pathlib import Path
4+
import glob
45

56
import pandas as pd
67
from ..exceptions import SABaseException
@@ -215,21 +216,46 @@ def __get_image_metadata(image_name, annotations):
215216
break
216217
return image_metadata
217218

219+
def __get_user_metadata(annotation):
220+
annotation_created_at = pd.to_datetime(annotation.get("createdAt"))
221+
annotation_created_by = annotation.get("createdBy")
222+
annotation_creator_email = None
223+
annotation_creator_role = None
224+
if annotation_created_by:
225+
annotation_creator_email = annotation_created_by.get("email")
226+
annotation_creator_role = annotation_created_by.get("role")
227+
annotation_creation_type = annotation.get("creationType")
228+
annotation_updated_at = pd.to_datetime(annotation.get("updatedAt"))
229+
annotation_updated_by = annotation.get("updatedBy")
230+
annotation_updator_email = None
231+
annotation_updator_role = None
232+
if annotation_updated_by:
233+
annotation_updator_email = annotation_updated_by.get("email")
234+
annotation_updator_role = annotation_updated_by.get("role")
235+
user_metadata = {
236+
"createdAt": annotation_created_at,
237+
"creatorRole": annotation_creator_role,
238+
"creatorEmail": annotation_creator_email,
239+
"creationType": annotation_creation_type,
240+
"updatedAt": annotation_updated_at,
241+
"updatorRole": annotation_updator_role,
242+
"updatorEmail": annotation_updator_email
243+
}
244+
return user_metadata
245+
218246
annotations_paths = []
219-
247+
220248
for path in Path(project_root).glob('*.json'):
221-
if path.name.endswith('___objects.json'
222-
) or path.name.endswith('___pixel.json'):
223-
annotations_paths.append(path)
249+
annotations_paths.append(path)
224250

225251
if not annotations_paths:
226252
logger.warning(
227253
"No annotations found in project export root %s", project_root
228254
)
229-
255+
type_postfix = "___objects.json" if glob.glob("{}/*___objects.json".format(project_root)) else "___pixel.json"
230256
for annotation_path in annotations_paths:
231257
annotation_json = json.load(open(annotation_path))
232-
image_name = annotation_path.name.split("___objects.json")[0]
258+
image_name = annotation_path.name.split(type_postfix)[0]
233259
image_metadata = __get_image_metadata(image_name, annotation_json)
234260
annotation_instance_id = 0
235261
for annotation in annotation_json:
@@ -249,8 +275,9 @@ def __get_image_metadata(image_name, annotations):
249275
"meta": comment_meta,
250276
"commentResolved": comment_resolved,
251277
}
278+
user_metadata = __get_user_metadata(annotation)
279+
annotation_dict.update(user_metadata)
252280
annotation_dict.update(image_metadata)
253-
254281
__append_annotation(annotation_dict)
255282
continue
256283
if annotation_type == "tag":
@@ -276,21 +303,6 @@ def __get_image_metadata(image_name, annotations):
276303
annotation_locked = annotation.get("locked")
277304
annotation_visible = annotation.get("visible")
278305
annotation_tracking_id = annotation.get("trackingId")
279-
annotation_created_at = annotation.get("createdAt")
280-
annotation_created_by = annotation.get("createdBy")
281-
annotation_creator_email = None
282-
annotation_creator_role = None
283-
if annotation_created_by:
284-
annotation_creator_email = annotation_created_by.get("email")
285-
annotation_creator_role = annotation_created_by.get("role")
286-
annotation_creation_type = annotation.get("creationType")
287-
annotation_updated_at = annotation.get("updatedAt")
288-
annotation_updated_by = annotation.get("updatedBy")
289-
annotation_updator_email = None
290-
annotation_updator_role = None
291-
if annotation_updated_by:
292-
annotation_updator_email = annotation_updated_by.get("email")
293-
annotation_updator_role = annotation_updated_by.get("role")
294306
annotation_meta = None
295307
if annotation_type in ["bbox", "polygon", "polyline", "cuboid"]:
296308
annotation_meta = {"points": annotation["points"]}
@@ -315,7 +327,7 @@ def __get_image_metadata(image_name, annotations):
315327
annotation_probability = annotation.get("probability")
316328
annotation_point_labels = annotation.get("pointLabels")
317329
attributes = annotation.get("attributes")
318-
330+
user_metadata = __get_user_metadata(annotation)
319331
if not attributes:
320332
annotation_dict = {
321333
"imageName": image_name,
@@ -331,14 +343,8 @@ def __get_image_metadata(image_name, annotations):
331343
"pointLabels": annotation_point_labels,
332344
"classColor": annotation_class_color,
333345
"groupId": annotation_group_id,
334-
"createdAt": annotation_created_at,
335-
"creatorRole": annotation_creator_role,
336-
"creatorEmail": annotation_creator_email,
337-
"creationType": annotation_creation_type,
338-
"updatedAt": annotation_updated_at,
339-
"updatorRole": annotation_updator_role,
340-
"updatorEmail": annotation_updator_email
341346
}
347+
annotation_dict.update(user_metadata)
342348
annotation_dict.update(image_metadata)
343349
__append_annotation(annotation_dict)
344350
else:
@@ -375,14 +381,8 @@ def __get_image_metadata(image_name, annotations):
375381
"pointLabels": annotation_point_labels,
376382
"classColor": annotation_class_color,
377383
"groupId": annotation_group_id,
378-
"createdAt": annotation_created_at,
379-
"creatorRole": annotation_creator_role,
380-
"creatorEmail": annotation_creator_email,
381-
"creationType": annotation_creation_type,
382-
"updatedAt": annotation_updated_at,
383-
"updatorRole": annotation_updator_role,
384-
"updatorEmail": annotation_updator_email
385384
}
385+
annotation_dict.update(user_metadata)
386386
annotation_dict.update(image_metadata)
387387
__append_annotation(annotation_dict)
388388

0 commit comments

Comments
 (0)