| 88 | return f"{int(seconds):02d}s" |
| 89 | |
| 90 | def calculate_depth(sub_questions: list): |
| 91 | try: |
| 92 | n = len(sub_questions) |
| 93 | |
| 94 | # Initialize distances matrix with infinity |
| 95 | distances = [[float("inf")] * n for _ in range(n)] |
| 96 | |
| 97 | # Set direct dependencies |
| 98 | for i, sub_q in enumerate(sub_questions): |
| 99 | # Distance to self is 0 |
| 100 | distances[i][i] = 0 |
| 101 | # Set direct dependencies with distance 1 |
| 102 | for dep in sub_q.get("depend", []): |
| 103 | distances[dep][i] = 1 |
| 104 | |
| 105 | # Floyd-Warshall algorithm to find shortest paths |
| 106 | for k in range(n): |
| 107 | for i in range(n): |
| 108 | for j in range(n): |
| 109 | if distances[i][k] != float("inf") and distances[k][j] != float("inf"): |
| 110 | distances[i][j] = min( |
| 111 | distances[i][j], distances[i][k] + distances[k][j] |
| 112 | ) |
| 113 | |
| 114 | # Find maximum finite distance |
| 115 | max_depth = 0 |
| 116 | for i in range(n): |
| 117 | for j in range(n): |
| 118 | if distances[i][j] != float("inf"): |
| 119 | max_depth = max(max_depth, distances[i][j]) |
| 120 | |
| 121 | return int(max_depth) |
| 122 | except: |
| 123 | return 3 |
| 124 | |
| 125 | def get_next_log_file(log_dir, size, dataset): |
| 126 | directory = log_dir.format(dataset=dataset, size=size) |