def bulk_import_index_entries(self, index_entries_list_json): for i in index_entries_list_json: di = IndexEntries() di.video = self.video di.id = i['id'] di.per_event_index = i['per_event_index'] di.algorithm = i['algorithm'] di.indexer_shasum = i['indexer_shasum'] di.approximator_shasum = i['approximator_shasum'] di.count = i['count'] di.approximate = i['approximate'] di.created = i['created'] di.event_id = i['event'] di.features_file_name = i['features_file_name'] di.entries = i['entries'] di.target = i['target'] di.metadata = i.get('metadata', {}) di.save()
def import_index_entries(self): # previous_transformed = set() for i in self.json['index_entries_list']: di = IndexEntries() di.video = self.video di.id = i['id'] di.per_event_index = i.per_event_index di.algorithm = i['algorithm'] # defaults only for backward compatibility if 'indexer_shasum' in i: di.indexer_shasum = i['indexer_shasum'] elif i['algorithm'] in self.name_to_shasum: di.indexer_shasum = self.name_to_shasum[i['algorithm']] else: di.indexer_shasum = 'UNKNOWN' if 'approximator_shasum' in i: di.approximator_shasum = i['approximator_shasum'] di.count = i['count'] di.approximate = i['approximate'] di.created = i['created'] di.event_id = self.event_to_pk[i['event']] di.features_file_name = i['features_file_name'] if 'entries_file_name' in i: entries = json.load( file('{}/indexes/{}'.format(self.root, i['entries_file_name']))) else: entries = i['entries'] di.target = i['target'] di.metadata = i.get('metadata', {}) transformed = [] for entry in entries: if 'detection_primary_key' in entry: entry['detection_primary_key'] = self.region_to_pk[ entry['detection_primary_key']] if 'frame_primary_key' in entry: entry['frame_primary_key'] = self.frame_to_pk[ entry['frame_primary_key']] transformed.append(entry) di.entries = transformed di.save()