

"""
# coding: utf-8
# NAME: filter_random_object_subset_OP_v1
# FILE: filter_random_object_subset_OP_v1
# REVISION : 1.1.0 - 2023_08_24
# AUTHOR : Mariia Burdyniuk 
# Copyright(c) 2023 arivis AG, Germany. All Rights Reserved.
#
# Permission is granted to use, modify and distribute this code,
# as long as this copyright notice remains part of the code.
#
# PURPOSE: The script selects a subset of objects, picked randomly 
# Release : 4.1.1  -- tested on : 2023_08_24
#
# NOTE: 
"""

import arivis_operation, arivis_parameter
import random

@arivis_parameter.add_arivis_parameters(Input_tag = "[ENTER_OBJECT_TAG_HERE]", Subset_size = 1000) 
@arivis_parameter.add_param_description(Input_tag = "[ENTER_OBJECT_TAG_HERE]",Subset_size = "Number of obejcts to sample randomly.")
def main(Input_tag, Subset_size):

    context = arivis_operation.Operation.get_context()
    input_object_data = context.get_input(0)
    output_data = context.get_output()
    
    IdList = input_object_data.get_object_ids(Input_tag)
    print(str(len(IdList)), ' objects with the given tag found. Start processing...')
    
    totalWork =  len(IdList)
    workDone = 0
    
    if len(IdList) > Subset_size: 
        random_numbers = [random.randint(1, len(IdList)) for _ in range(Subset_size)]
        
        for indice in random_numbers:
          Object1 = input_object_data.get_object(IdList[indice], True)
          tags = Object1.get_tags()
          tags.append('Random selection')
          Object1.set_tags(tags)
          output_data.add_object(Object1)

          workDone = workDone + 1
          context.notify_progress(workDone * 100 / totalWork)

    else:
        print('Total number of objects is larger than the subset size')





