| 62 | |
| 63 | |
| 64 | def parse_function(*metrics, directory="", args=None, end_signal=None): |
| 65 | print(f"Parsing files in {directory}") |
| 66 | subdirs = listdir_nohidden(directory, sort=True) |
| 67 | |
| 68 | outputs = [] |
| 69 | |
| 70 | for subdir in subdirs: |
| 71 | fpath = osp.join(directory, subdir, "log.txt") |
| 72 | assert check_isfile(fpath) |
| 73 | good_to_go = False |
| 74 | output = OrderedDict() |
| 75 | |
| 76 | with open(fpath, "r") as f: |
| 77 | lines = f.readlines() |
| 78 | |
| 79 | for line in lines: |
| 80 | line = line.strip() |
| 81 | |
| 82 | if line == end_signal: |
| 83 | good_to_go = True |
| 84 | |
| 85 | for metric in metrics: |
| 86 | match = metric["regex"].search(line) |
| 87 | if match and good_to_go: |
| 88 | if "file" not in output: |
| 89 | output["file"] = fpath |
| 90 | num = float(match.group(1)) |
| 91 | name = metric["name"] |
| 92 | output[name] = num |
| 93 | |
| 94 | if output: |
| 95 | outputs.append(output) |
| 96 | |
| 97 | assert len(outputs) > 0, f"Nothing found in {directory}" |
| 98 | |
| 99 | metrics_results = defaultdict(list) |
| 100 | |
| 101 | for output in outputs: |
| 102 | msg = "" |
| 103 | for key, value in output.items(): |
| 104 | if isinstance(value, float): |
| 105 | msg += f"{key}: {value:.2f}%. " |
| 106 | else: |
| 107 | msg += f"{key}: {value}. " |
| 108 | if key != "file": |
| 109 | metrics_results[key].append(value) |
| 110 | print(msg) |
| 111 | |
| 112 | output_results = OrderedDict() |
| 113 | |
| 114 | print("===") |
| 115 | print(f"Summary of directory: {directory}") |
| 116 | for key, values in metrics_results.items(): |
| 117 | avg = np.mean(values) |
| 118 | std = compute_ci95(values) if args.ci95 else np.std(values) |
| 119 | print(f"* {key}: {avg:.2f}% +- {std:.2f}%") |
| 120 | output_results[key] = avg |
| 121 | print("===") |