Example #1
0
 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.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()
 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.storage_type = i['storage_type']
         di.features = i['features']
         di.uuid = i['uuid']
         di.entries = i['entries']
         di.target = i['target']
         di.metadata = i.get('metadata', {})
         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()
 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()