forked from aerinon/ALttPDoorRandomizer
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTestSuiteRandom.pyw
More file actions
144 lines (113 loc) · 5.09 KB
/
TestSuiteRandom.pyw
File metadata and controls
144 lines (113 loc) · 5.09 KB
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
import subprocess
import sys
import multiprocessing
import concurrent.futures
import argparse
import sqlite3
from collections import OrderedDict
from datetime import datetime
cpu_threads = multiprocessing.cpu_count()
py_version = f"{sys.version_info.major}.{sys.version_info.minor}"
def main(args=None):
successes = []
errors = []
task_mapping = []
tests = OrderedDict()
max_attempts = 1 #args and args.count if args.count is not None else 1
print(f"Testing Random OWR with {max_attempts} Tests")
pool = concurrent.futures.ThreadPoolExecutor(max_workers=cpu_threads)
dead_or_alive = 0
alive = 0
basecommand = f'py Mystery.py --suppress_rom --suppress_meta --spoiler full --outputpath L:/_Work/Zelda/ROMs/Bug/Automate/{datetime.now().strftime("%y%m%d")} --weights L:/_Work/Zelda/ROMs/Bug/Automate/_test.yml'
def gen_seed():
return subprocess.run(basecommand, capture_output=True, shell=True, text=True)
for x in range(1, max_attempts + 1):
task = pool.submit(gen_seed)
task.success = False
task.name = "OWR Random Test"
task.mode = ""
task.cmd = basecommand
task_mapping.append(task)
from tqdm import tqdm
with tqdm(concurrent.futures.as_completed(task_mapping),
total=len(task_mapping), unit="seed(s)",
desc=f"Success rate: 0.00%") as progressbar:
#with open("L:/_Work/Zelda/ROMs/Bug/Automate/_error_.txt", "a") as ff:
# ff.write("seed")
for task in progressbar:
dead_or_alive += 1
try:
result = task.result()
if result.returncode:
errors.append([datetime.now(), result.stderr])
#print(result.stderr)
#print(result.stdout)
else:
alive += 1
successes.append([datetime.now(), result.stderr])
task.success = True
except Exception as e:
with open("L:/_Work/Zelda/ROMs/Bug/Automate" + datetime.now().strftime("%y%m%d") + "/_error_.txt", "a") as ff:
exc_type, exc_obj, exc_tb = sys.exc_info()
ff.write(exc_type)
ff.write(exc_tb.tb_lineno)
raise e
progressbar.set_description(f"Success rate: {(alive/dead_or_alive)*100:.2f}% - {task.name}{task.mode}")
def get_results(testname: str):
result = ""
dead_or_alive = [task.success for task in task_mapping]
alive = [x for x in dead_or_alive if x]
success = f"Rate: {(len(alive) / len(dead_or_alive)) * 100:.2f}%"
#successes.append(success)
#print(success)
result += f"{(len(alive)/len(dead_or_alive))*100:.2f}%\t"
return result.strip()
results = []
results.append(get_results(""))
#for result in results:
#print(result)
#successes.append(result)
return successes, errors
if __name__ == "__main__":
successes = []
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('--count', default=1, type=lambda value: max(int(value), 1))
parser.add_argument('--cpu_threads', default=cpu_threads, type=lambda value: max(int(value), 1))
parser.add_argument('--help', default=False, action='store_true')
args = parser.parse_args()
if args.help:
parser.print_help()
exit(0)
cpu_threads = args.cpu_threads
args = argparse.Namespace()
successes, errors = main(args=args)
# if successes:
# successes += [""] * 2
# successes += s
# print()
if errors:
with open(f"L:/_Work/Zelda/ROMs/Bug/Automate/{datetime.now().strftime('%y%m%d')}/_error_{datetime.now().strftime('%y%m%d')}.txt", 'a') as stream:
for error in errors:
stream.write("Run at: " + error[0].strftime("%Y-%m-%d %H:%M:%S") + "\n")
stream.write(error[1] + "\n\n")
stream.write("----------------------------------------------------\n")
if successes:
with open(f"L:/_Work/Zelda/ROMs/Bug/Automate/{datetime.now().strftime('%y%m%d')}/_success_{datetime.now().strftime('%y%m%d')}.txt", 'a') as stream:
for success in successes:
stream.write("Run at: " + success[0].strftime("%Y-%m-%d %H:%M:%S") + "\n")
stream.write(success[1] + "\n\n")
stream.write("----------------------------------------------------\n")
# with open(f"L:\\_Work\\Zelda\\ROMs\\Bug\\Automate\\{datetime.now().strftime('%y%m%d')}\\_success.txt", "w") as stream:
# stream.write(str.join("\n", successes))
#conn = sqlite3.connect(f"L:/_Work/Zelda/ROMs/Bug/Automate/{datetime.now().strftime('%y%m%d')}/log.db")
# conn.execute('''CREATE TABLE SEEDGEN
# (SEED INT NOT NULL,
# MYSTERY CHAR(10),
# SETTINGSCODE CHAR(20) NOT NULL,
# VERSION CHAR(10) NOT NULL,
# TIMESTAMP INT NOT NULL,
# SUCCESS INT,
# LOG TEXT);''')
#input("Press enter to continue")
#conn.close()
exit(0)