-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus.py
157 lines (127 loc) · 5.68 KB
/
status.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import argparse
import os
import datetime
import json
from rich import print
import pandas as pd
import time
from pathlib import Path
from rich.progress import Progress, TaskProgressColumn, TimeRemainingColumn, MofNCompleteColumn, SpinnerColumn, \
DownloadColumn
from time import sleep
from rich.table import Column
from rich.progress import Progress, BarColumn, TextColumn
from rich.console import Console
from rich.table import Table
#from rich_tools import table_to_df
def main():
parser = argparse.ArgumentParser(description="Allows you to monitor the status of the experiment execution.")
parser.add_argument("--exec", type=str, help="Show details of an execution. Pass only the execution number (ID). Example: --exec 03")
parser.add_argument("--save", nargs=2, metavar=("ID", "FILE"), help="Saves execution status to a csv file. Example: --save 01 exec01.csv")
args = parser.parse_args()
exec_map = get_results_map()
if args.exec:
execution_info(exec_map[args.exec])
elif args.save:
table = execution_info(exec_map[args.save[0]], print_to_console=False)
save_execution_info(table, args.save[1])
else:
all_executions_info(exec_map)
def save_execution_info(table: Table, output_file: str):
df = table_to_dataframe(table)
df.to_csv(output_file, index=False)
def execution_info(execution_memory: str, print_to_console=True):
table = Table(title="Tasks from: {}".format(execution_memory))
# table.add_column("ID", justify="right", style="cyan", no_wrap=True)
table.add_column("apk", style="magenta")
table.add_column("rep", justify="right", style="green")
table.add_column("timeout", justify="right", style="magenta")
table.add_column("tool", justify="right", style="magenta")
table.add_column("executed", justify="center", style="magenta")
table.add_column("time", justify="right", style="magenta")
execution = read_execution_memory(execution_memory)
for apk in execution:
for rep in execution[apk]:
for timeout in execution[apk][rep]:
for tool in execution[apk][rep][timeout]:
task = execution[apk][rep][timeout][tool]
executed = ""
time = ""
if task["executed"]:
time = task["finish"] - task["start"]
#python -m rich.emoji
executed = ":white_heavy_check_mark:"
table.add_row(apk, str(rep), str(timeout), tool, executed, str(time))
if print_to_console:
console = Console()
console.print(table)
return table
def all_executions_info(exec_map):
map_total = { }
total_tasks = 0
tasks_executed = 0
for _exec in exec_map:
execution = read_execution_memory( exec_map[_exec])
map_total[_exec] = { "total_tasks": 0, "executed": 0, "pct": 0.0}
for apk in execution:
for rep in execution[apk]:
for timeout in execution[apk][rep]:
for tool in execution[apk][rep][timeout]:
task = execution[apk][rep][timeout][tool]
total_tasks += 1
map_total[_exec]["total_tasks"] += 1
if task["executed"]:
tasks_executed += 1
map_total[_exec]["executed"] += 1
executions_progress(map_total)
print(f"tasks_total={total_tasks}")
print(f"tasks_executed={tasks_executed}")
print(f"tasks_pct={((tasks_executed*100)/total_tasks):.2f}%")
def executions_progress(map_total):
with Progress(
TextColumn("[bold green][progress.description]{task.description}"),
BarColumn(),
TaskProgressColumn(),
MofNCompleteColumn(),
TextColumn("[green]tasks completed")) as progress:
for _exec in sorted(map_total):
total = map_total[_exec]["total_tasks"]
executed = map_total[_exec]["executed"]
exec_bar = progress.add_task(f"[green]EXEC_{_exec}", total=total)
progress.update(exec_bar, advance=executed)
def read_execution_memory(file_path: str):
with open(file_path, "r") as exec_file:
dados = json.load(exec_file)
return dados
def get_results_map():
results_map = {}
subdirectories = [f.path for f in os.scandir(".") if f.is_dir()]
if not subdirectories:
return None
for subdir in subdirectories:
if ".git" in subdir or "RESULTS" in subdir or "venv" in subdir:
continue
results_dir = get_latest_subdirectory(os.path.join(subdir,"results"))
results_map[subdir[2:]] = os.path.join(subdir,"results",results_dir,"execution_memory.json")
return results_map
def get_latest_subdirectory(directory):
try:
path = Path(directory)
latest_subdirectory = max(path.glob('*'), key=lambda x: x.stat().st_mtime)
return latest_subdirectory.name
except FileNotFoundError:
print(f"Directory '{directory}' not found.")
return None
def table_to_dataframe(table: Table):
data = []
header = []
for column in table.columns:
header.append(column.header)
line = []
for cell in column.cells:
line.append(cell)
data.append(line)
transposed_matrix = [[row[i] for row in data] for i in range(len(data[0]))]
return pd.DataFrame(transposed_matrix, columns=header)
if __name__ == "__main__":
main()