From 67b29b2706b7a5f69ae2ab04e554083a2cf2e0cb Mon Sep 17 00:00:00 2001 From: Shawnsdaddy Date: Mon, 28 Oct 2024 15:41:49 -0700 Subject: [PATCH] =?UTF-8?q?log=20=E4=BC=98=E5=8C=96=EF=BC=8C=E5=85=AC?= =?UTF-8?q?=E6=8B=9B=E9=99=90=E6=97=B6=EF=BC=8Cmaa=E5=AF=BC=E8=88=AA?= =?UTF-8?q?=E6=96=B0=E5=A2=9Etimout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arknights_mower/solvers/base_schedule.py | 5 ++--- arknights_mower/utils/operators.py | 19 ++++++++++++++----- arknights_mower/utils/solver.py | 9 +++++++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/arknights_mower/solvers/base_schedule.py b/arknights_mower/solvers/base_schedule.py index ce777003..f17ceca7 100644 --- a/arknights_mower/solvers/base_schedule.py +++ b/arknights_mower/solvers/base_schedule.py @@ -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 @@ -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) diff --git a/arknights_mower/utils/operators.py b/arknights_mower/utils/operators.py index 1eb3dd61..69a05722 100644 --- a/arknights_mower/utils/operators.py +++ b/arknights_mower/utils/operators.py @@ -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 ( @@ -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 ( diff --git a/arknights_mower/utils/solver.py b/arknights_mower/utils/solver.py index 00514f0c..d0cc77a5 100644 --- a/arknights_mower/utils/solver.py +++ b/arknights_mower/utils/solver.py @@ -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