summary refs log tree commit diff stats
path: root/classification/tools/create_csv.py
blob: ea997ccff6ba9b918470ef848df516e894996d0e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from os import listdir, path
from argparse import ArgumentParser

root_directory = "../../results/classifier/"

parser = ArgumentParser()
parser.add_argument('-d', '--directory')

args = parser.parse_args()

def parse_iteration(directory):
    dictionary = {}

    for entry in listdir(directory):
        full_path = path.join(directory, entry)
        if path.isdir(full_path):
            dictionary[entry] = len([name for name in listdir(full_path)])

    return dictionary

def output_csv(dictionary, full_path):
    with open(path.join(full_path, 'categories.csv'), "w") as file:
        file.write("category, count\n")
        for key, value in dictionary.items():
            file.write(f"{key}, {value}\n")

def main():
    if args.directory:
        dictionary = parse_iteration(args.directory)
        output_csv(dictionary, args.directory)
        exit()

    for entry in listdir(root_directory):
        full_path = path.join(root_directory, entry)
        if path.isdir(full_path):
            dictionary = parse_iteration(full_path)
            output_csv(dictionary, full_path)

if __name__ == "__main__":
    main()