import os
import sys

#python3 ijcai2024-anchored/generate_referencesV2.py -model_directory=ijcai2024-anchored/ijcai2024-anchored/models/breastTumor -dataset=../datasets_ijcai/

dir_path_csv=sys.argv[1]

def get_file_names(directory):
    results=[]
    # Iterate directory
    for file_path in os.listdir(directory):
        # check if current file_path is a file
        if os.path.isfile(os.path.join(directory, file_path)):
            # add filename to list
            results.append(directory+file_path)
    return results

csv = get_file_names(dir_path_csv)
for file_csv in csv:
    if file_csv.endswith(".csv"):
        #print("file:", file_csv)
        name = file_csv.split(os.sep)[-1].split(".")[0]
        print("name:", name)
        files = get_file_names("ijcai2024-anchored/ijcai2024-anchored/models/"+name)
        files = [file for file in files if file.endswith(".v2.references.json")]
        if len(files) == 40:
            print("len:", len(files))
            print("name OK:", name)
        else:
            print("name NOT OK:", name)
            command = "python3 ijcai2024-anchored/generate_referencesV2.py"
            command += " -model_directory=ijcai2024-anchored/ijcai2024-anchored/models/"+name
            command += " -dataset=../datasets_ijcai/"
            print(command)
            os.system(command)
            input("Press Enter to continue...")
