|
21 | 21 | from .log import slogger
|
22 | 22 | from . import serializers
|
23 | 23 |
|
| 24 | +"""dot.notation access to dictionary attributes""" |
| 25 | +class dotdict(OrderedDict): |
| 26 | + __getattr__ = OrderedDict.get |
| 27 | + __setattr__ = OrderedDict.__setitem__ |
| 28 | + __delattr__ = OrderedDict.__delitem__ |
| 29 | + __eq__ = lambda self, other: self.id == other.id |
| 30 | + __hash__ = lambda self: self.id |
| 31 | + |
24 | 32 | class PatchAction(str, Enum):
|
25 | 33 | CREATE = "create"
|
26 | 34 | UPDATE = "update"
|
@@ -142,15 +150,6 @@ def bulk_create(db_model, objects, flt_param):
|
142 | 150 | return []
|
143 | 151 |
|
144 | 152 | def _merge_table_rows(rows, keys_for_merge, field_id):
|
145 |
| - """dot.notation access to dictionary attributes""" |
146 |
| - from collections import OrderedDict |
147 |
| - class dotdict(OrderedDict): |
148 |
| - __getattr__ = OrderedDict.get |
149 |
| - __setattr__ = OrderedDict.__setitem__ |
150 |
| - __delattr__ = OrderedDict.__delitem__ |
151 |
| - __eq__ = lambda self, other: self.id == other.id |
152 |
| - __hash__ = lambda self: self.id |
153 |
| - |
154 | 153 | # It is necessary to keep a stable order of original rows
|
155 | 154 | # (e.g. for tracked boxes). Otherwise prev_box.frame can be bigger
|
156 | 155 | # than next_box.frame.
|
@@ -202,12 +201,16 @@ def __init__(self, pk, user):
|
202 | 201 | "all": OrderedDict(),
|
203 | 202 | }
|
204 | 203 | for db_attr in db_label.attributespec_set.all():
|
| 204 | + default_value = dotdict([ |
| 205 | + ('spec_id', db_attr.id), |
| 206 | + ('value', db_attr.default_value), |
| 207 | + ]) |
205 | 208 | if db_attr.mutable:
|
206 |
| - self.db_attributes[db_label.id]["mutable"][db_attr.id] = db_attr |
| 209 | + self.db_attributes[db_label.id]["mutable"][db_attr.id] = default_value |
207 | 210 | else:
|
208 |
| - self.db_attributes[db_label.id]["immutable"][db_attr.id] = db_attr |
| 211 | + self.db_attributes[db_label.id]["immutable"][db_attr.id] = default_value |
209 | 212 |
|
210 |
| - self.db_attributes[db_label.id]["all"][db_attr.id] = db_attr |
| 213 | + self.db_attributes[db_label.id]["all"][db_attr.id] = default_value |
211 | 214 |
|
212 | 215 | def reset(self):
|
213 | 216 | self.ir_data.reset()
|
@@ -458,13 +461,13 @@ def delete(self, data=None):
|
458 | 461 | self._commit()
|
459 | 462 |
|
460 | 463 | @staticmethod
|
461 |
| - def _extend_attributes(attributeval_set, attribute_specs): |
| 464 | + def _extend_attributes(attributeval_set, default_attribute_values): |
462 | 465 | shape_attribute_specs_set = set(attr.spec_id for attr in attributeval_set)
|
463 |
| - for db_attr_spec in attribute_specs: |
464 |
| - if db_attr_spec.id not in shape_attribute_specs_set: |
465 |
| - attributeval_set.append(OrderedDict([ |
466 |
| - ('spec_id', db_attr_spec.id), |
467 |
| - ('value', db_attr_spec.default_value), |
| 466 | + for db_attr in default_attribute_values: |
| 467 | + if db_attr.spec_id not in shape_attribute_specs_set: |
| 468 | + attributeval_set.append(dotdict([ |
| 469 | + ('spec_id', db_attr.spec_id), |
| 470 | + ('value', db_attr.value), |
468 | 471 | ]))
|
469 | 472 |
|
470 | 473 | def _init_tags_from_db(self):
|
@@ -600,12 +603,16 @@ def _init_tracks_from_db(self):
|
600 | 603 | self._extend_attributes(db_track.labeledtrackattributeval_set,
|
601 | 604 | self.db_attributes[db_track.label_id]["immutable"].values())
|
602 | 605 |
|
| 606 | + default_attribute_values = self.db_attributes[db_track.label_id]["mutable"].values() |
603 | 607 | for db_shape in db_track["trackedshape_set"]:
|
604 | 608 | db_shape["trackedshapeattributeval_set"] = list(
|
605 | 609 | set(db_shape["trackedshapeattributeval_set"])
|
606 | 610 | )
|
607 |
| - self._extend_attributes(db_shape["trackedshapeattributeval_set"], |
608 |
| - self.db_attributes[db_track.label_id]["mutable"].values()) |
| 611 | + # in case of trackedshapes need to interpolate attriute values and extend it |
| 612 | + # by previous shape attribute values (not default values) |
| 613 | + self._extend_attributes(db_shape["trackedshapeattributeval_set"], default_attribute_values) |
| 614 | + default_attribute_values = db_shape["trackedshapeattributeval_set"] |
| 615 | + |
609 | 616 |
|
610 | 617 | serializer = serializers.LabeledTrackSerializer(db_tracks, many=True)
|
611 | 618 | self.ir_data.tracks = serializer.data
|
|
0 commit comments