Skip to content

Commit 9469b4b

Browse files
committed
add missing fields to df
1 parent 7a9f17e commit 9469b4b

File tree

1 file changed

+99
-48
lines changed

1 file changed

+99
-48
lines changed

superannotate/analytics/common.py

Lines changed: 99 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ def aggregate_annotations_as_df(
142142

143143
annotation_data = {
144144
"imageName": [],
145+
"imageHeight": [],
146+
"imageWidth": [],
147+
"imageStatus": [],
148+
"imagePinned": [],
145149
"instanceId": [],
146150
"className": [],
147151
"attributeGroupName": [],
@@ -155,7 +159,14 @@ def aggregate_annotations_as_df(
155159
"pointLabels": [],
156160
"meta": [],
157161
"classColor": [],
158-
"groupId": []
162+
"groupId": [],
163+
"createdAt": [],
164+
"creatorRole": [],
165+
"creationType": [],
166+
"creatorEmail": [],
167+
"updatedAt": [],
168+
"updatorRole": [],
169+
"updatorEmail": []
159170
}
160171

161172
if include_comments:
@@ -183,6 +194,17 @@ def __append_annotation(annotation_dict):
183194
else:
184195
annotation_data[annotation_key].append(None)
185196

197+
def __get_image_metadata(image_name, annotations):
198+
image_metadata = {"imageName": image_name}
199+
for annotation in annotations:
200+
if "type" in annotation and annotation["type"] == "meta":
201+
image_metadata["imageHeight"] = annotation["height"]
202+
image_metadata["imageWidth"] = annotation["width"]
203+
image_metadata["imageStatus"] = annotation["status"]
204+
image_metadata["imagePinned"] = annotation["pinned"]
205+
break
206+
return image_metadata
207+
186208
annotations_paths = []
187209

188210
for path in Path(project_root).glob('*.json'):
@@ -197,11 +219,12 @@ def __append_annotation(annotation_dict):
197219

198220
for annotation_path in annotations_paths:
199221
annotation_json = json.load(open(annotation_path))
200-
annotation_image_name = annotation_path.name.split("___")[0]
222+
image_name = annotation_path.name.split("___objects.json")[0]
223+
image_metadata = __get_image_metadata(image_name, annotation_json)
201224
annotation_instance_id = 0
202225
for annotation in annotation_json:
203226
annotation_type = annotation.get("type", "mask")
204-
if annotation_type in ['meta', 'tag']:
227+
if annotation_type in ['tag', 'meta']:
205228
continue
206229
if annotation_type == "comment":
207230
if include_comments:
@@ -211,14 +234,14 @@ def __append_annotation(annotation_dict):
211234
"y": annotation["y"],
212235
"comments": annotation["comments"]
213236
}
214-
__append_annotation(
215-
{
216-
"imageName": annotation_image_name,
217-
"type": annotation_type,
218-
"meta": comment_meta,
219-
"commentResolved": comment_resolved,
220-
}
221-
)
237+
annotation_dict = {
238+
"type": annotation_type,
239+
"meta": comment_meta,
240+
"commentResolved": comment_resolved,
241+
}
242+
annotation_dict.update(image_metadata)
243+
244+
__append_annotation(annotation_dict)
222245
continue
223246
annotation_instance_id += 1
224247
annotation_class_name = annotation.get("className")
@@ -231,6 +254,21 @@ def __append_annotation(annotation_dict):
231254
annotation_locked = annotation.get("locked")
232255
annotation_visible = annotation.get("visible")
233256
annotation_tracking_id = annotation.get("trackingId")
257+
annotation_created_at = annotation.get("createdAt")
258+
annotation_created_by = annotation.get("createdBy")
259+
annotation_creator_email = None
260+
annotation_creator_role = None
261+
if annotation_created_by:
262+
annotation_creator_email = annotation_created_by.get("email")
263+
annotation_creator_role = annotation_created_by.get("role")
264+
annotation_creation_type = annotation.get("creationType")
265+
annotation_updated_at = annotation.get("updatedAt")
266+
annotation_updated_by = annotation.get("updatedBy")
267+
annotation_updator_email = None
268+
annotation_updator_role = None
269+
if annotation_updated_by:
270+
annotation_updator_email = annotation_updated_by.get("email")
271+
annotation_updator_role = annotation_updated_by.get("role")
234272
annotation_meta = None
235273
if annotation_type in ["bbox", "polygon", "polyline", "cuboid"]:
236274
annotation_meta = {"points": annotation["points"]}
@@ -257,48 +295,61 @@ def __append_annotation(annotation_dict):
257295
attributes = annotation.get("attributes")
258296

259297
if not attributes:
260-
__append_annotation(
261-
{
262-
"imageName": annotation_image_name,
263-
"instanceId": annotation_instance_id,
264-
"className": annotation_class_name,
265-
"type": annotation_type,
266-
"locked": annotation_locked,
267-
"visible": annotation_visible,
268-
"trackingId": annotation_tracking_id,
269-
"meta": annotation_meta,
270-
"error": annotation_error,
271-
"probability": annotation_probability,
272-
"pointLabels": annotation_point_labels,
273-
"classColor": annotation_class_color,
274-
"groupId": annotation_group_id
275-
}
276-
)
298+
annotation_dict = {
299+
"imageName": image_name,
300+
"instanceId": annotation_instance_id,
301+
"className": annotation_class_name,
302+
"type": annotation_type,
303+
"locked": annotation_locked,
304+
"visible": annotation_visible,
305+
"trackingId": annotation_tracking_id,
306+
"meta": annotation_meta,
307+
"error": annotation_error,
308+
"probability": annotation_probability,
309+
"pointLabels": annotation_point_labels,
310+
"classColor": annotation_class_color,
311+
"groupId": annotation_group_id,
312+
"createdAt": annotation_created_at,
313+
"creatorRole": annotation_creator_role,
314+
"creatorEmail": annotation_creator_email,
315+
"creationType": annotation_creation_type,
316+
"updatedAt": annotation_updated_at,
317+
"updatorRole": annotation_updator_role,
318+
"updatorEmail": annotation_updator_email
319+
}
320+
annotation_dict.update(image_metadata)
321+
__append_annotation(annotation_dict)
277322

278323
for attribute in attributes:
279324

280325
attribute_group = attribute["groupName"]
281326
attribute_name = attribute['name']
282-
283-
__append_annotation(
284-
{
285-
"imageName": annotation_image_name,
286-
"instanceId": annotation_instance_id,
287-
"className": annotation_class_name,
288-
"attributeGroupName": attribute_group,
289-
"attributeName": attribute_name,
290-
"type": annotation_type,
291-
"locked": annotation_locked,
292-
"visible": annotation_visible,
293-
"trackingId": annotation_tracking_id,
294-
"meta": annotation_meta,
295-
"error": annotation_error,
296-
"probability": annotation_probability,
297-
"pointLabels": annotation_point_labels,
298-
"classColor": annotation_class_color,
299-
"groupId": annotation_group_id
300-
}
301-
)
327+
annotation_dict = {
328+
"imageName": image_name,
329+
"instanceId": annotation_instance_id,
330+
"className": annotation_class_name,
331+
"attributeGroupName": attribute_group,
332+
"attributeName": attribute_name,
333+
"type": annotation_type,
334+
"locked": annotation_locked,
335+
"visible": annotation_visible,
336+
"trackingId": annotation_tracking_id,
337+
"meta": annotation_meta,
338+
"error": annotation_error,
339+
"probability": annotation_probability,
340+
"pointLabels": annotation_point_labels,
341+
"classColor": annotation_class_color,
342+
"groupId": annotation_group_id,
343+
"createdAt": annotation_created_at,
344+
"creatorRole": annotation_creator_role,
345+
"creatorEmail": annotation_creator_email,
346+
"creationType": annotation_creation_type,
347+
"updatedAt": annotation_updated_at,
348+
"updatorRole": annotation_updator_role,
349+
"updatorEmail": annotation_updator_email
350+
}
351+
annotation_dict.update(image_metadata)
352+
__append_annotation(annotation_dict)
302353

303354
df = pd.DataFrame(annotation_data)
304355

0 commit comments

Comments
 (0)