|
8 | 8 | from typing import Callable |
9 | 9 | from typing import Dict |
10 | 10 | from typing import List |
| 11 | +from operator import itemgetter |
11 | 12 |
|
12 | | -import lib.core as constances |
13 | | -from lib.core.enums import AnnotationTypes |
14 | | -from lib.core.reporter import Reporter |
15 | 13 | from superannotate_schemas.schemas.classes import AnnotationClass |
16 | 14 | from superannotate_schemas.schemas.classes import Attribute |
17 | 15 | from superannotate_schemas.schemas.classes import AttributeGroup |
18 | 16 |
|
| 17 | +import lib.core as constances |
| 18 | +from lib.core.enums import AnnotationTypes |
| 19 | +from lib.core.reporter import Reporter |
| 20 | + |
19 | 21 |
|
20 | 22 | class BaseDataHandler(metaclass=ABCMeta): |
21 | 23 | @abstractmethod |
@@ -47,7 +49,7 @@ def get_annotation_class(self, name: str) -> AnnotationClass: |
47 | 49 |
|
48 | 50 | @lru_cache() |
49 | 51 | def get_attribute_group( |
50 | | - self, annotation_class: AnnotationClass, attr_group_name: str |
| 52 | + self, annotation_class: AnnotationClass, attr_group_name: str |
51 | 53 | ) -> AttributeGroup: |
52 | 54 | for attr_group in annotation_class.attribute_groups: |
53 | 55 | if attr_group.name == attr_group_name: |
@@ -114,10 +116,10 @@ def handle(self, annotation: dict): |
114 | 116 |
|
115 | 117 | class MissingIDsHandler(BaseAnnotationDateHandler): |
116 | 118 | def __init__( |
117 | | - self, |
118 | | - annotation_classes: List[AnnotationClass], |
119 | | - templates: List[dict], |
120 | | - reporter: Reporter, |
| 119 | + self, |
| 120 | + annotation_classes: List[AnnotationClass], |
| 121 | + templates: List[dict], |
| 122 | + reporter: Reporter, |
121 | 123 | ): |
122 | 124 | super().__init__(annotation_classes) |
123 | 125 | self.validate_existing_classes(annotation_classes) |
@@ -187,7 +189,7 @@ def handle(self, annotation: dict): |
187 | 189 | template["name"]: template["id"] for template in self._templates |
188 | 190 | } |
189 | 191 | for annotation_instance in ( |
190 | | - i for i in annotation["instances"] if i.get("type", None) == "template" |
| 192 | + i for i in annotation["instances"] if i.get("type", None) == "template" |
191 | 193 | ): |
192 | 194 | annotation_instance["templateId"] = template_name_id_map.get( |
193 | 195 | annotation_instance.get("templateName", ""), -1 |
@@ -237,6 +239,8 @@ def handle(self, annotation: dict): |
237 | 239 |
|
238 | 240 |
|
239 | 241 | class VideoFormatHandler(BaseAnnotationDateHandler): |
| 242 | + INSTANCE_FIELDS = {"className", "pointLabels", "createdBy", "createdAt", "updatedBy", "updatedAt"} |
| 243 | + |
240 | 244 | @staticmethod |
241 | 245 | def _point_handler(time_stamp): |
242 | 246 | pass |
@@ -266,7 +270,7 @@ def safe_time(timestamp): |
266 | 270 | return "0" if str(timestamp) == "0.0" else timestamp |
267 | 271 |
|
268 | 272 | def convert_timestamp(timestamp): |
269 | | - return timestamp / 10**6 if timestamp else "0" |
| 273 | + return timestamp / 10 ** 6 if timestamp else "0" |
270 | 274 |
|
271 | 275 | editor_data = { |
272 | 276 | "instances": [], |
@@ -300,8 +304,9 @@ def convert_timestamp(timestamp): |
300 | 304 | else: |
301 | 305 | editor_instance["classId"] = id_generator.send("unknown_class") |
302 | 306 |
|
303 | | - if meta.get("pointLabels", None): |
304 | | - editor_instance["pointLabels"] = meta["pointLabels"] |
| 307 | + matched_fields = self.INSTANCE_FIELDS & meta.keys() |
| 308 | + for matched_field in matched_fields: |
| 309 | + editor_instance[matched_field] = meta[matched_field] |
305 | 310 | active_attributes = set() |
306 | 311 | for parameter in instance["parameters"]: |
307 | 312 | start_time = safe_time(convert_timestamp(parameter["start"])) |
@@ -363,10 +368,10 @@ def convert_timestamp(timestamp): |
363 | 368 | (group_name, attr_name) |
364 | 369 | ) |
365 | 370 | attributes_to_add = ( |
366 | | - existing_attributes_in_current_instance - active_attributes |
| 371 | + existing_attributes_in_current_instance - active_attributes |
367 | 372 | ) |
368 | 373 | attributes_to_delete = ( |
369 | | - active_attributes - existing_attributes_in_current_instance |
| 374 | + active_attributes - existing_attributes_in_current_instance |
370 | 375 | ) |
371 | 376 | if attributes_to_add or attributes_to_delete: |
372 | 377 | editor_instance["timeline"][timestamp][ |
|
0 commit comments