def action_success_definition(action_scenario_dir, output_dir, success_rate=0.8):
    print('input dir:', action_scenario_dir)
    print('output dir:', output_dir)
    ah_paths = glob.glob(f'{action_scenario_dir}/*.json')
    roulette = (([True] * round((success_rate * 10))) + ([False] * round(((1 - success_rate) * 10))))
    print('success_rate :', success_rate)
    print('roulette :', roulette)
    os.makedirs(output_dir, exist_ok=True)
    for ah_path in ah_paths:
        with open(ah_path, 'r') as f:
            action_history = json.load(f)
        file_name = ah_path.split('/')[(- 1)]
        actions = []
        for (i, action_info) in enumerate(action_history['actions']):
            atom = {}
            atom['step'] = i
            atom['action'] = action_info[0]
            if (len(action_info) > 1):
                atom['target_object'] = action_info[1]
            atom['success'] = random.choice(roulette)
            actions.append(atom)
        new_ah = {'actions': actions, 'scene_name': action_history['scene_name'], 'file_name': file_name}
        with open(osp.join(output_dir, file_name), 'w') as f:
            json.dump(new_ah, f, indent='\t')
    print('done')
def action_success_definition(action_scenario_dir, output_dir, success_rate=0.8):
    print('input dir:', action_scenario_dir)
    print('output dir:', output_dir)
    ah_paths = glob.glob(f'{action_scenario_dir}/*.json')
    roulette = (([True] * round((success_rate * 10))) + ([False] * round(((1 - success_rate) * 10))))
    print('success_rate :', success_rate)
    print('roulette :', roulette)
    os.makedirs(output_dir, exist_ok=True)
    for ah_path in ah_paths:
        with open(ah_path, 'r') as f:
            action_history = json.load(f)
        file_name = ah_path.split('/')[(- 1)]
        actions = []
        for (i, action_info) in enumerate(action_history['actions']):
            atom = {}
            atom['step'] = i
            atom['action'] = action_info[0]
            if (len(action_info) > 1):
                atom['target_object'] = action_info[1]
            atom['success'] = random.choice(roulette)
            actions.append(atom)
        new_ah = {'actions': actions, 'scene_name': action_history['scene_name'], 'file_name': file_name}
        with open(osp.join(output_dir, file_name), 'w') as f:
            json.dump(new_ah, f, indent='\t')
    print('done')