def import_index_entries(self): previous_transformed = set() for i in self.json['index_entries_list']: di = IndexEntries() di.video = self.video di.algorithm = i['algorithm'] # defaults only for backward compatibility di.indexer_shasum =i.get('indexer_shasum',self.name_to_shasum[i['algorithm']]) di.count = i['count'] di.contains_detections = i['contains_detections'] di.contains_frames = i['contains_frames'] di.approximate = i['approximate'] di.created = i['created'] di.features_file_name = i['features_file_name'] di.entries_file_name = i['entries_file_name'] di.detection_name = i['detection_name'] signature = "{}".format(di.entries_file_name) if signature in previous_transformed: logging.warning("repeated index entries found, skipping {}".format(signature)) else: previous_transformed.add(signature) entries = json.load(file('{}/indexes/{}'.format(self.root, di.entries_file_name))) transformed = [] for entry in entries: entry['video_primary_key'] = self.video.pk 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) with open('{}/indexes/{}'.format(self.root, di.entries_file_name), 'w') as output: json.dump(transformed, output) 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.algorithm = i['algorithm'] di.count = i['count'] di.contains_detections = i['contains_detections'] di.contains_frames = i['contains_frames'] di.approximate = i['approximate'] di.created = i['created'] di.features_file_name = i['features_file_name'] di.entries_file_name = i['entries_file_name'] di.detection_name = i['detection_name'] signature = "{}".format(di.entries_file_name) if signature in previous_transformed: logging.warning("repeated index entries found, skipping {}".format(signature)) else: previous_transformed.add(signature) entries = json.load(file('{}/indexes/{}'.format(self.root, di.entries_file_name))) transformed = [] for entry in entries: entry['video_primary_key'] = self.video.pk 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) with open('{}/indexes/{}'.format(self.root, di.entries_file_name), 'w') as output: json.dump(transformed, output) di.save()
def import_index_entries(i,video_obj,previous_transformed,detection_to_pk,frame_to_pk,video_root_dir): di = IndexEntries() di.video = video_obj di.algorithm = i['algorithm'] di.count = i['count'] di.contains_detections = i['contains_detections'] di.contains_frames = i['contains_frames'] di.approximate = i['approximate'] di.created = i['created'] di.features_file_name = i['features_file_name'] di.entries_file_name = i['entries_file_name'] di.detection_name = i['detection_name'] signature = "{}".format(di.entries_file_name) if signature in previous_transformed: logging.warning("repeated index entries found, skipping {}".format(signature)) else: previous_transformed.add(signature) transform_index_entries(di, detection_to_pk, frame_to_pk, video_obj.pk, video_root_dir) di.save()