优化超时判定
This commit is contained in:
BIN
AUTO_MAA.exe
BIN
AUTO_MAA.exe
Binary file not shown.
94
AUTO_MAA.py
94
AUTO_MAA.py
@@ -119,21 +119,17 @@ class MaaRunner(QtCore.QThread):
|
|||||||
maa = subprocess.Popen([self.MaaPath])
|
maa = subprocess.Popen([self.MaaPath])
|
||||||
# 记录当前时间
|
# 记录当前时间
|
||||||
StartTime = datetime.datetime.now()
|
StartTime = datetime.datetime.now()
|
||||||
# 初始化log记录列表
|
# 记录是否超时的标记
|
||||||
if j == 0:
|
self.TimeOut = False
|
||||||
logx = [k for k in range(self.Annihilation * 60)]
|
|
||||||
elif j == 1:
|
|
||||||
logx = [k for k in range(self.Routine * 60)]
|
|
||||||
logi = 0
|
|
||||||
# 更新运行信息
|
# 更新运行信息
|
||||||
WaitUid = [
|
WaitUid = [
|
||||||
idx for idx in AllUid if (not idx in OverUid + ErrorUid + [uid])
|
idx for idx in AllUid if (not idx in OverUid + ErrorUid + [uid])
|
||||||
]
|
]
|
||||||
# 监测MAA运行状态
|
# 监测MAA运行状态
|
||||||
while True:
|
while True:
|
||||||
# 更新MAA日志
|
# 获取MAA日志
|
||||||
|
logs = []
|
||||||
with open(self.LogPath, "r", encoding="utf-8") as f:
|
with open(self.LogPath, "r", encoding="utf-8") as f:
|
||||||
logs = []
|
|
||||||
for entry in f:
|
for entry in f:
|
||||||
try:
|
try:
|
||||||
entry_time = datetime.datetime.strptime(
|
entry_time = datetime.datetime.strptime(
|
||||||
@@ -143,26 +139,41 @@ class MaaRunner(QtCore.QThread):
|
|||||||
logs.append(entry)
|
logs.append(entry)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
log = "".join(logs)
|
# 判断是否超时
|
||||||
if j == 0:
|
if len(logs) > 0:
|
||||||
self.UpGui.emit(
|
LastTime = datetime.datetime.strptime(
|
||||||
self.data[uid][0] + "_第" + str(i + 1) + "次_剿灭",
|
logs[-1][1:20], "%Y-%m-%d %H:%M:%S"
|
||||||
"\n".join([self.data[k][0] for k in WaitUid]),
|
)
|
||||||
"\n".join([self.data[k][0] for k in OverUid]),
|
NowTime = datetime.datetime.now()
|
||||||
"\n".join([self.data[k][0] for k in ErrorUid]),
|
if (
|
||||||
log,
|
j == 0
|
||||||
)
|
and NowTime - LastTime
|
||||||
elif j == 1:
|
> datetime.timedelta(minutes=self.Annihilation)
|
||||||
self.UpGui.emit(
|
) or (
|
||||||
self.data[uid][0] + "_第" + str(i + 1) + "次_日常",
|
j == 1
|
||||||
"\n".join([self.data[k][0] for k in WaitUid]),
|
and NowTime - LastTime
|
||||||
"\n".join([self.data[k][0] for k in OverUid]),
|
> datetime.timedelta(minutes=self.Routine)
|
||||||
"\n".join([self.data[k][0] for k in ErrorUid]),
|
):
|
||||||
log,
|
self.TimeOut = True
|
||||||
)
|
# 合并日志
|
||||||
if len(logs) != 0:
|
log = "".join(logs)
|
||||||
logx[logi] = logs[-1]
|
# 更新MAA日志
|
||||||
logi = (logi + 1) % len(logx)
|
if j == 0:
|
||||||
|
self.UpGui.emit(
|
||||||
|
self.data[uid][0] + "_第" + str(i + 1) + "次_剿灭",
|
||||||
|
"\n".join([self.data[k][0] for k in WaitUid]),
|
||||||
|
"\n".join([self.data[k][0] for k in OverUid]),
|
||||||
|
"\n".join([self.data[k][0] for k in ErrorUid]),
|
||||||
|
log,
|
||||||
|
)
|
||||||
|
elif j == 1:
|
||||||
|
self.UpGui.emit(
|
||||||
|
self.data[uid][0] + "_第" + str(i + 1) + "次_日常",
|
||||||
|
"\n".join([self.data[k][0] for k in WaitUid]),
|
||||||
|
"\n".join([self.data[k][0] for k in OverUid]),
|
||||||
|
"\n".join([self.data[k][0] for k in ErrorUid]),
|
||||||
|
log,
|
||||||
|
)
|
||||||
# 判断MAA程序运行状态
|
# 判断MAA程序运行状态
|
||||||
if "任务已全部完成!" in log:
|
if "任务已全部完成!" in log:
|
||||||
runbook[j] = True
|
runbook[j] = True
|
||||||
@@ -179,10 +190,11 @@ class MaaRunner(QtCore.QThread):
|
|||||||
("请检查连接设置或尝试重启模拟器与 ADB 或重启电脑" in log)
|
("请检查连接设置或尝试重启模拟器与 ADB 或重启电脑" in log)
|
||||||
or ("已停止" in log)
|
or ("已停止" in log)
|
||||||
or ("MaaAssistantArknights GUI exited" in log)
|
or ("MaaAssistantArknights GUI exited" in log)
|
||||||
or self.TimeOut(logx)
|
or self.TimeOut
|
||||||
or not self.ifRun
|
or not self.ifRun
|
||||||
):
|
):
|
||||||
# 打印中止信息
|
# 打印中止信息
|
||||||
|
# 此时,log变量内存储的就是出现异常的日志信息,可以保存或发送用于问题排查
|
||||||
if (
|
if (
|
||||||
(
|
(
|
||||||
"请检查连接设置或尝试重启模拟器与 ADB 或重启电脑"
|
"请检查连接设置或尝试重启模拟器与 ADB 或重启电脑"
|
||||||
@@ -192,7 +204,7 @@ class MaaRunner(QtCore.QThread):
|
|||||||
or ("MaaAssistantArknights GUI exited" in log)
|
or ("MaaAssistantArknights GUI exited" in log)
|
||||||
):
|
):
|
||||||
info = "检测到MAA进程异常\n正在中止相关程序\n请等待10s"
|
info = "检测到MAA进程异常\n正在中止相关程序\n请等待10s"
|
||||||
elif self.TimeOut(logx):
|
elif self.TimeOut:
|
||||||
info = "检测到MAA进程超时\n正在中止相关程序\n请等待10s"
|
info = "检测到MAA进程超时\n正在中止相关程序\n请等待10s"
|
||||||
elif not self.ifRun:
|
elif not self.ifRun:
|
||||||
info = "您中止了本次任务\n正在中止相关程序\n请等待"
|
info = "您中止了本次任务\n正在中止相关程序\n请等待"
|
||||||
@@ -392,14 +404,6 @@ class MaaRunner(QtCore.QThread):
|
|||||||
json.dump(data, f, indent=4)
|
json.dump(data, f, indent=4)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# 超时判断
|
|
||||||
def TimeOut(self, logx):
|
|
||||||
log0 = logx[0]
|
|
||||||
for i in logx:
|
|
||||||
if i != log0:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class MainTimer(QtCore.QThread):
|
class MainTimer(QtCore.QThread):
|
||||||
|
|
||||||
@@ -1005,15 +1009,11 @@ class Main(QWidget):
|
|||||||
if os.path.exists(self.GameidPath):
|
if os.path.exists(self.GameidPath):
|
||||||
with open(self.GameidPath, encoding="utf-8") as f:
|
with open(self.GameidPath, encoding="utf-8") as f:
|
||||||
gameids = f.readlines()
|
gameids = f.readlines()
|
||||||
for i in range(len(gameids)):
|
for line in gameids:
|
||||||
for j in range(len(gameids[i])):
|
if ":" in line:
|
||||||
if gameids[i][j] == ":" or gameids[i][j] == ":":
|
gamein, gameout = line.split(":", 1)
|
||||||
gamein = gameids[i][:j]
|
games[gamein.strip()] = gameout.strip()
|
||||||
gameout = gameids[i][j + 1 :]
|
text = games.get(text, text)
|
||||||
break
|
|
||||||
games[gamein.strip()] = gameout.strip()
|
|
||||||
if text in games:
|
|
||||||
text = games[text]
|
|
||||||
if item.column() == 9:
|
if item.column() == 9:
|
||||||
text = text.replace("\\", "/")
|
text = text.replace("\\", "/")
|
||||||
if item.column() == 10:
|
if item.column() == 10:
|
||||||
|
|||||||
Reference in New Issue
Block a user