11import copy
22import json
3+ from dataclasses import dataclass
34from pathlib import Path
45from typing import List
56from typing import Optional
67from typing import Union
78
89import lib .core as constances
910import pandas as pd
10- from dataclasses import dataclass
1111from lib .app .exceptions import AppException
1212from lib .core import ATTACHED_VIDEO_ANNOTATION_POSTFIX
1313from lib .core import PIXEL_ANNOTATION_POSTFIX
@@ -99,6 +99,7 @@ class DataAggregator:
9999 ry = annotation ["ry" ],
100100 angle = annotation ["angle" ],
101101 ),
102+ "tag" : lambda annotation : None ,
102103 }
103104
104105 def __init__ (
@@ -171,6 +172,18 @@ def aggregate_annotations_as_df(self):
171172 elif self .project_type == constances .ProjectType .DOCUMENT .name :
172173 return self .aggregate_document_annotations_as_df (annotation_paths )
173174
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 ("groupName" )
180+ attribute_raw .attributeName = attribute .get ("name" )
181+ raws .append (attribute_raw )
182+ if not attributes :
183+ raws .append (element_raw )
184+
185+ return raws
186+
174187 def aggregate_video_annotations_as_df (self , annotation_paths : List [str ]):
175188 raws = []
176189 for annotation_path in annotation_paths :
@@ -225,6 +238,9 @@ def aggregate_video_annotations_as_df(self, annotation_paths: List[str]):
225238 )
226239 instance_raw .pointLabels = instance ["meta" ].get ("pointLabels" )
227240 parameters = instance .get ("parameters" , [])
241+ if instance_raw .type == "tag" :
242+ attributes = instance ["meta" ].get ("attributes" , [])
243+ raws = self .__add_attributes_to_raws (raws , attributes , instance_raw )
228244 for parameter_id , parameter in enumerate (parameters ):
229245 parameter_raw = copy .copy (instance_raw )
230246 parameter_raw .parameterId = parameter_id
@@ -236,19 +252,12 @@ def aggregate_video_annotations_as_df(self, annotation_paths: List[str]):
236252 timestamp_raw .timestampId = timestamp_id
237253 timestamp_raw .meta = self .MAPPERS [instance_type ](timestamp )
238254 attributes = timestamp .get ("attributes" , [])
239- for attribute_id , attribute in enumerate (attributes ):
240- attribute_raw = copy .copy (timestamp_raw )
241- attribute_raw .attributeId = attribute_id
242- attribute_raw .attributeGroupName = attribute .get (
243- "groupName"
244- )
245- attribute_raw .attributeName = attribute .get ("name" )
246- raws .append (attribute_raw )
247- if not attributes :
248- raws .append (timestamp_raw )
255+ raws = self .__add_attributes_to_raws (
256+ raws , attributes , timestamp_raw
257+ )
249258 if not timestamps :
250259 raws .append (parameter_raw )
251- if not parameters :
260+ if not parameters and instance_type != "tag" :
252261 raws .append (instance_raw )
253262 if not instances :
254263 raws .append (raw_data )
0 commit comments