Skip to content

Commit

Permalink
log 优化,公招限时,maa导航新增timout
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawnsdaddy committed Oct 28, 2024
1 parent 6e77155 commit 67b29b2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
5 changes: 2 additions & 3 deletions arknights_mower/solvers/base_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,8 +836,7 @@ def agent_get_mood(self, skip_dorm=False, force=False):
need_read = set(
v.room
for k, v in self.op_data.operators.items()
if v.need_to_refresh(0.5 if k in ["歌蕾蒂娅", "见行者"] else 2)
and v.room in base_room_list
if v.need_to_refresh() and v.room in base_room_list
)
for room in need_read:
error_count = 0
Expand Down Expand Up @@ -3268,7 +3267,7 @@ def initialize_maa(self):
)
ota_tasks_path = path / "cache" / "resource" / "tasks.json"
ota_tasks_path.parent.mkdir(parents=True, exist_ok=True)
with urllib.request.urlopen(ota_tasks_url) as u:
with urllib.request.urlopen(ota_tasks_url, timeout=60) as u:
res = u.read().decode("utf-8")
with open(ota_tasks_path, "w", encoding="utf-8") as f:
f.write(res)
Expand Down
19 changes: 14 additions & 5 deletions arknights_mower/utils/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,18 @@ def update_detail(self, name, mood, current_room, current_index, update_time=Fal
agent = self.operators[name]
if update_time:
if agent.time_stamp is not None and agent.mood > mood:
agent.depletion_rate = (
(agent.mood - mood)
* 3600
/ ((datetime.now() - agent.time_stamp).total_seconds())
)
time_difference = datetime.now() - agent.time_stamp
if time_difference > timedelta(minutes=29):
logger.debug("开始计算心情掉率")
logger.debug(
f"当前心情:{mood},上次{agent.mood},上次时间{agent.time_stamp}"
)
agent.depletion_rate = (
(agent.mood - mood) * 3600 / time_difference.total_seconds()
)
logger.debug(
f"更新 {agent.name} 心情掉率为:{agent.depletion_rate}"
)
agent.time_stamp = datetime.now()
# 如果移出宿舍,则清除对应宿舍数据 且重新记录高效组心情(如果有备用班,则跳过高效组判定)
if (
Expand Down Expand Up @@ -751,6 +758,8 @@ def is_working(self):

def need_to_refresh(self, h=2, r=""):
# 是否需要读取心情
if self.name in ["歌蕾蒂娅", "见行者"]:
h = 0.5
if (
self.time_stamp is None
or (
Expand Down
9 changes: 9 additions & 0 deletions arknights_mower/utils/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,17 @@ def run(self) -> None:
self.check_current_focus()
retry_times = config.MAX_RETRYTIME
result = None
start_time = datetime.now()
recruit_timeout_limit = 300 # 获取超时限制 300s
from arknights_mower.solvers.recruit import RecruitSolver

while retry_times > 0:
try:
if isinstance(self, RecruitSolver):
if datetime.now() - start_time > timedelta(
seconds=recruit_timeout_limit
):
raise Exception("任务超时,强制停止")
result = self.transition()
if result:
return result
Expand Down

0 comments on commit 67b29b2

Please sign in to comment.