Skip to content

Commit bd54576

Browse files
committed
Updated video data handler to incldue more instance fields
1 parent 167b043 commit bd54576

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

src/superannotate/lib/core/data_handlers.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
from typing import Callable
99
from typing import Dict
1010
from typing import List
11+
from operator import itemgetter
1112

12-
import lib.core as constances
13-
from lib.core.enums import AnnotationTypes
14-
from lib.core.reporter import Reporter
1513
from superannotate_schemas.schemas.classes import AnnotationClass
1614
from superannotate_schemas.schemas.classes import Attribute
1715
from superannotate_schemas.schemas.classes import AttributeGroup
1816

17+
import lib.core as constances
18+
from lib.core.enums import AnnotationTypes
19+
from lib.core.reporter import Reporter
20+
1921

2022
class BaseDataHandler(metaclass=ABCMeta):
2123
@abstractmethod
@@ -47,7 +49,7 @@ def get_annotation_class(self, name: str) -> AnnotationClass:
4749

4850
@lru_cache()
4951
def get_attribute_group(
50-
self, annotation_class: AnnotationClass, attr_group_name: str
52+
self, annotation_class: AnnotationClass, attr_group_name: str
5153
) -> AttributeGroup:
5254
for attr_group in annotation_class.attribute_groups:
5355
if attr_group.name == attr_group_name:
@@ -114,10 +116,10 @@ def handle(self, annotation: dict):
114116

115117
class MissingIDsHandler(BaseAnnotationDateHandler):
116118
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,
121123
):
122124
super().__init__(annotation_classes)
123125
self.validate_existing_classes(annotation_classes)
@@ -187,7 +189,7 @@ def handle(self, annotation: dict):
187189
template["name"]: template["id"] for template in self._templates
188190
}
189191
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"
191193
):
192194
annotation_instance["templateId"] = template_name_id_map.get(
193195
annotation_instance.get("templateName", ""), -1
@@ -237,6 +239,8 @@ def handle(self, annotation: dict):
237239

238240

239241
class VideoFormatHandler(BaseAnnotationDateHandler):
242+
INSTANCE_FIELDS = {"className", "pointLabels", "createdBy", "createdAt", "updatedBy", "updatedAt"}
243+
240244
@staticmethod
241245
def _point_handler(time_stamp):
242246
pass
@@ -266,7 +270,7 @@ def safe_time(timestamp):
266270
return "0" if str(timestamp) == "0.0" else timestamp
267271

268272
def convert_timestamp(timestamp):
269-
return timestamp / 10**6 if timestamp else "0"
273+
return timestamp / 10 ** 6 if timestamp else "0"
270274

271275
editor_data = {
272276
"instances": [],
@@ -300,8 +304,9 @@ def convert_timestamp(timestamp):
300304
else:
301305
editor_instance["classId"] = id_generator.send("unknown_class")
302306

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]
305310
active_attributes = set()
306311
for parameter in instance["parameters"]:
307312
start_time = safe_time(convert_timestamp(parameter["start"]))
@@ -363,10 +368,10 @@ def convert_timestamp(timestamp):
363368
(group_name, attr_name)
364369
)
365370
attributes_to_add = (
366-
existing_attributes_in_current_instance - active_attributes
371+
existing_attributes_in_current_instance - active_attributes
367372
)
368373
attributes_to_delete = (
369-
active_attributes - existing_attributes_in_current_instance
374+
active_attributes - existing_attributes_in_current_instance
370375
)
371376
if attributes_to_add or attributes_to_delete:
372377
editor_instance["timeline"][timestamp][

tests/integration/annotations/test_video_annotation_upload.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,27 @@ def test_video_annotation_converter(self):
148148
data = {'instances': [
149149
{
150150
'attributes': [], 'timeline': {
151-
'0': {'active': True, 'points': {'x1': 223.32, 'y1': 78.45, 'x2': 312.31, 'y2': 176.66}},
152-
17.271058: {'points': {'x1': 182.08, 'y1': 33.18, 'x2': 283.45, 'y2': 131.39}},
153-
30.526667: {'active': False, 'points': {'x1': 182.42, 'y1': 97.19, 'x2': 284.11, 'y2': 195.4}}},
154-
'type': 'bbox', 'locked': False, 'classId': -1, 'pointLabels': {'3': 'point label bro'}
151+
'0': {
152+
'active': True, 'points': {'x1': 223.32, 'y1': 78.45, 'x2': 312.31, 'y2': 176.66}},
153+
17.271058: {
154+
'points': {
155+
'x1': 182.08, 'y1': 33.18, 'x2': 283.45, 'y2': 131.39}
156+
},
157+
30.526667: {
158+
'active': False, 'points': {'x1': 182.42, 'y1': 97.19, 'x2': 284.11, 'y2': 195.4}}},
159+
'type': 'bbox', 'locked': False, 'classId': -1, "className": "vid",
160+
"pointLabels": {
161+
"3": "point label bro"
162+
},
155163
},
156164
{
157165
'attributes': [],
158166
'timeline': {29.713736: {'active': True, 'x': 1, 'y': 2}, 30.526667: {'active': False, 'x': 2, 'y': 3}},
159-
'type': 'point', 'locked': False, 'classId': -1
167+
'type': 'point', 'locked': False, 'classId': -1, "className": "vid",
160168
},
161169
{
162170
'attributes': [], 'timeline': {5.528212: {'active': True}, 6.702957: {}, 7.083022: {'active': False}},
163-
'type': 'event', 'locked': False, 'classId': -1
171+
'type': 'event', 'locked': False, 'classId': -1, "className": "vid",
164172
}
165173
],
166174
'tags': ['some tag'], 'name': 'video.mp4',

0 commit comments

Comments
 (0)