def import_whole_image_points(self,annotation_set, import_data): """ create annotation points with information from uploaded CSV and add to this annotation set """ from projects.models import WholeImageAnnotation images = annotation_set.images.all() points_to_bulk_save = [] # iterate through the images and create points for image in images: for annotation in import_data[str(image.deployment.id)][image.image_name]: whole_image_annotation = WholeImageAnnotation() whole_image_annotation.annotation_set = annotation_set whole_image_annotation.image = image whole_image_annotation.owner = annotation_set.owner whole_image_annotation.annotation_caab_code = annotation['Annotation Code'] whole_image_annotation.qualifier_short_name = ['Qualifier Name'] whole_image_annotation.annotation_caab_code_secondary = annotation['Annotation Code'] whole_image_annotation.qualifier_short_name_secondary = ['Qualifier Name 2'] points_to_bulk_save.append(whole_image_annotation) # do the bulk save - for performance WholeImageAnnotation.objects.bulk_create(points_to_bulk_save)
def apply_whole_image_points(self, annotation_set): """ Randomly apply points to the images attached to this annotation set """ from projects.models import WholeImageAnnotation whole_image_annotation_count = 4 images = annotation_set.images.all() points_to_bulk_save = [] # iterate through the images and create points for image in images: for i in range(whole_image_annotation_count): whole_image_annotation = WholeImageAnnotation() whole_image_annotation.annotation_set = annotation_set whole_image_annotation.image = image whole_image_annotation.owner = annotation_set.owner whole_image_annotation.annotation_caab_code = "" whole_image_annotation.qualifier_short_name = "" whole_image_annotation.annotation_caab_code_secondary = "" whole_image_annotation.qualifier_short_name_secondary = "" points_to_bulk_save.append(whole_image_annotation) # do the bulk save - for performance WholeImageAnnotation.objects.bulk_create(points_to_bulk_save)