Skip to content

Commit f222214

Browse files
committed
reshuffled aggregate function to handle tag attributes
1 parent d67866f commit f222214

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/superannotate/lib/app/analytics/aggregators.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,20 @@ def aggregate_annotations_as_df(self):
172172
elif self.project_type == constances.ProjectType.DOCUMENT.name:
173173
return self.aggregate_document_annotations_as_df(annotation_paths)
174174

175+
def __add_attributes_to_raws(self, raws, attributes, element_raw):
176+
for attribute_id, attribute in enumerate(attributes):
177+
attribute_raw = copy.copy(element_raw)
178+
attribute_raw.attributeId = attribute_id
179+
attribute_raw.attributeGroupName = attribute.get(
180+
"groupName"
181+
)
182+
attribute_raw.attributeName = attribute.get("name")
183+
raws.append(attribute_raw)
184+
if not attributes:
185+
raws.append(element_raw)
186+
187+
return raws
188+
175189
def aggregate_video_annotations_as_df(self, annotation_paths: List[str]):
176190
raws = []
177191
for annotation_path in annotation_paths:
@@ -226,6 +240,10 @@ def aggregate_video_annotations_as_df(self, annotation_paths: List[str]):
226240
)
227241
instance_raw.pointLabels = instance["meta"].get("pointLabels")
228242
parameters = instance.get("parameters", [])
243+
if instance_raw.type == 'tag':
244+
print(instance["meta"]["attributes"])
245+
attributes = instance["meta"].get("attributes",[])
246+
raws = self.__add_attributes_to_raws(raws, attributes, instance_raw)
229247
for parameter_id, parameter in enumerate(parameters):
230248
parameter_raw = copy.copy(instance_raw)
231249
parameter_raw.parameterId = parameter_id
@@ -237,16 +255,7 @@ def aggregate_video_annotations_as_df(self, annotation_paths: List[str]):
237255
timestamp_raw.timestampId = timestamp_id
238256
timestamp_raw.meta = self.MAPPERS[instance_type](timestamp)
239257
attributes = timestamp.get("attributes", [])
240-
for attribute_id, attribute in enumerate(attributes):
241-
attribute_raw = copy.copy(timestamp_raw)
242-
attribute_raw.attributeId = attribute_id
243-
attribute_raw.attributeGroupName = attribute.get(
244-
"groupName"
245-
)
246-
attribute_raw.attributeName = attribute.get("name")
247-
raws.append(attribute_raw)
248-
if not attributes:
249-
raws.append(timestamp_raw)
258+
raws = self.__add_attributes_to_raws(raws, attributes, timestamp_raw)
250259
if not timestamps:
251260
raws.append(parameter_raw)
252261
if not parameters:

0 commit comments

Comments
 (0)