Skip to content

Commit d113aa4

Browse files
committed
code clean up
1 parent d8e776f commit d113aa4

File tree

6 files changed

+95
-327
lines changed

6 files changed

+95
-327
lines changed

arknights_mower/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33
from pathlib import Path
44

5-
__version__ = "2025.1.2"
5+
__version__ = "2025.2.1"
66

77
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
88
__rootdir__ = Path(sys._MEIPASS).joinpath("arknights_mower").resolve()

arknights_mower/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def initialize(
4949
ling_xi=config.plan.conf.ling_xi,
5050
workaholic=config.plan.conf.workaholic,
5151
free_blacklist=conf.free_blacklist,
52-
ope_resting_priority=conf.ope_resting_priority,
52+
ope_resting_priority=config.plan.conf.ope_resting_priority,
5353
resting_threshold=conf.resting_threshold,
5454
refresh_trading_config=config.plan.conf.refresh_trading,
5555
refresh_drained=config.plan.conf.refresh_drained,

arknights_mower/solvers/base_schedule.py

Lines changed: 1 addition & 231 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from arknights_mower.utils.datetime import (
2929
format_time,
3030
get_server_weekday,
31-
pass_deadline,
3231
)
3332
from arknights_mower.utils.device.device import Device
3433
from arknights_mower.utils.digit_reader import DigitReader
@@ -43,10 +42,8 @@
4342
from arknights_mower.utils.scheduler_task import (
4443
SchedulerTask,
4544
TaskTypes,
46-
add_release_dorm,
4745
check_dorm_ordering,
4846
find_next_task,
49-
merge_release_dorm,
5047
plan_metadata,
5148
scheduling,
5249
try_add_release_dorm,
@@ -386,234 +383,7 @@ def plan_fia(self):
386383
self.tasks.sort(key=lambda task: task.time)
387384

388385
def plan_metadata(self):
389-
if config.conf.flexible_shift_mode or pass_deadline():
390-
self.tasks = plan_metadata(self.op_data, self.tasks)
391-
else:
392-
planned_index = []
393-
# 移除当前 SHIFT_ON 重新刷新
394-
for t in self.tasks:
395-
if "dorm" in t.meta_data:
396-
planned_index.extend([int(w[4:]) for w in t.meta_data.split(",")])
397-
_time = datetime.max
398-
min_resting_time = datetime.max
399-
_plan = {}
400-
_type = []
401-
# 第一个心情低的且小于3 则只休息半小时
402-
short_rest = False
403-
self.total_agent = list(
404-
v
405-
for k, v in self.op_data.operators.items()
406-
if v.is_high() and not v.room.startswith("dorm") and not v.is_resting()
407-
)
408-
self.total_agent.sort(
409-
key=lambda x: x.current_mood() - x.lower_limit, reverse=False
410-
)
411-
if (
412-
next(
413-
(
414-
a
415-
for a in self.total_agent
416-
if (a.name not in self.op_data.exhaust_agent)
417-
and not a.workaholic
418-
and a.current_mood() <= 3
419-
),
420-
None,
421-
)
422-
is not None
423-
):
424-
short_rest = True
425-
if not short_rest:
426-
for x in self.total_agent:
427-
if (
428-
not x.workaholic
429-
and not x.exhaust_require
430-
and x.room not in ["factory", "train"]
431-
):
432-
min_resting_time = min(min_resting_time, x.predict_exhaust())
433-
logger.debug(f"预测最低休息时间为:{min_resting_time}")
434-
low_priority = []
435-
for idx, dorm in enumerate(self.op_data.dorm):
436-
logger.debug(f"开始计算{dorm}")
437-
# 如果已经plan了,则跳过
438-
if idx in planned_index or idx in low_priority:
439-
continue
440-
_name = dorm.name
441-
if _name == "":
442-
continue
443-
# 如果是rest in full,则新增单独任务..
444-
if (
445-
_name in self.op_data.operators.keys()
446-
and self.op_data.operators[_name].is_high()
447-
and self.op_data.operators[_name].rest_in_full
448-
):
449-
__plan = {}
450-
__rest_agent = []
451-
__type = []
452-
if self.op_data.operators[dorm.name].group == "":
453-
__rest_agent.append(dorm.name)
454-
else:
455-
__rest_agent.extend(
456-
self.op_data.groups[self.op_data.operators[dorm.name].group]
457-
)
458-
if dorm.time is not None:
459-
__time = dorm.time
460-
else:
461-
__time = datetime.max
462-
need_early = True
463-
for x in __rest_agent:
464-
# 如果小组内没有耗尽,则提前8分钟上班
465-
if self.op_data.operators[x].exhaust_require:
466-
need_early = False
467-
# 如果同小组也是rest_in_full则取最大休息时间 否则忽略
468-
if x in low_priority:
469-
logger.debug("检测到回满组已经安排")
470-
_plan = {}
471-
_idx, __dorm = self.op_data.get_dorm_by_name(x)
472-
if (
473-
x in self.op_data.operators.keys()
474-
and self.op_data.operators[x].rest_in_full
475-
):
476-
if __dorm is not None and __dorm.time is not None:
477-
if (
478-
__dorm.time > __time
479-
and self.op_data.operators[x].resting_priority
480-
== "high"
481-
):
482-
__time = __dorm.time
483-
if _idx is not None:
484-
__type.append("dorm" + str(_idx))
485-
planned_index.append(_idx)
486-
logger.debug(f"计划干员为{x}")
487-
__room = self.op_data.operators[x].room
488-
if __room not in __plan.keys():
489-
__plan[__room] = ["Current"] * len(
490-
self.op_data.plan[__room]
491-
)
492-
__plan[__room][self.op_data.operators[x].index] = x
493-
if __time < datetime.now():
494-
__time = datetime.now()
495-
if __time != datetime.max:
496-
if need_early:
497-
__time -= timedelta(minutes=8)
498-
logger.info("全组无耗尽,提前8分钟上班")
499-
self.tasks.append(
500-
SchedulerTask(
501-
time=__time,
502-
task_type=TaskTypes.SHIFT_ON,
503-
task_plan=__plan,
504-
meta_data=",".join(__type),
505-
)
506-
)
507-
try_add_release_dorm(__plan, __time, self.op_data, self.tasks)
508-
else:
509-
self.op_data.reset_dorm_time()
510-
self.error = True
511-
# 如果非 rest in full, 则同组取时间最小值
512-
elif (
513-
_name in self.op_data.operators.keys()
514-
and not self.op_data.operators[_name].is_high()
515-
and self.op_data.config.free_room
516-
):
517-
# 释放满心情其他干员
518-
add_release_dorm(self.tasks, self.op_data, _name)
519-
elif self.op_data.operators[_name].is_high():
520-
if dorm.time is not None and dorm.time < _time:
521-
logger.debug(f"更新任务时间{dorm.time}")
522-
_time = dorm.time
523-
__room = self.op_data.operators[_name].room
524-
__rest_agent = []
525-
if self.op_data.operators[_name].group == "":
526-
__rest_agent.append(_name)
527-
else:
528-
__rest_agent.extend(
529-
self.op_data.groups[self.op_data.operators[_name].group]
530-
)
531-
logger.debug(f"小组分组为{__rest_agent}")
532-
# 如果小组有其他人是rest_in_full则跳过
533-
if next(
534-
(
535-
d
536-
for d in __rest_agent
537-
if d in self.op_data.operators.keys()
538-
and self.op_data.operators[d].rest_in_full
539-
),
540-
None,
541-
):
542-
continue
543-
for x in __rest_agent:
544-
if x in low_priority:
545-
continue
546-
__room = self.op_data.operators[x].room
547-
if __room not in base_room_list:
548-
continue
549-
if __room not in _plan.keys():
550-
_plan[__room] = ["Current"] * len(self.op_data.plan[__room])
551-
_plan[__room][self.op_data.operators[x].index] = x
552-
_dorm_idx, __dorm = self.op_data.get_dorm_by_name(x)
553-
if __dorm is not None:
554-
_type.append("dorm" + str(_dorm_idx))
555-
planned_index.append(_dorm_idx)
556-
if (
557-
__dorm.time is not None
558-
and __dorm.time < _time
559-
and self.op_data.operators[x].resting_priority == "high"
560-
):
561-
logger.debug(f"更新任务时间{dorm.time}")
562-
_time = __dorm.time
563-
564-
if x not in low_priority:
565-
low_priority.append(x)
566-
# 生成单个任务
567-
if len(_plan.items()) > 0:
568-
if _time != datetime.max:
569-
_time = min(_time, min_resting_time)
570-
_time -= timedelta(minutes=8)
571-
if _time < datetime.now():
572-
_time = datetime.now()
573-
_time = (
574-
_time
575-
if not short_rest
576-
else (datetime.now() + timedelta(hours=0.5))
577-
)
578-
self.tasks.append(
579-
SchedulerTask(
580-
time=_time,
581-
task_plan=_plan,
582-
task_type=TaskTypes.SHIFT_ON,
583-
meta_data=",".join(_type),
584-
)
585-
)
586-
try_add_release_dorm(_plan, _time, self.op_data, self.tasks)
587-
else:
588-
logger.debug("检测到时间数据不存在")
589-
self.op_data.reset_dorm_time()
590-
self.error = True
591-
# 最后再做不养闲人刷新
592-
if self.op_data.config.free_room:
593-
594-
def should_keep(task):
595-
if task.type != TaskTypes.RELEASE_DORM:
596-
return True
597-
elif len(task.plan) == 0:
598-
return False
599-
name = task.meta_data
600-
free_room = list(task.plan.keys())[0]
601-
free_op = task.plan[free_room]
602-
if (
603-
self.op_data.operators[name].current_room != free_room
604-
or free_op[self.op_data.operators[name].current_index] != "Free"
605-
):
606-
logger.info(f"检测到{task.meta_data}不在对应位置,移除相关任务")
607-
return False
608-
i, d = self.op_data.get_dorm_by_name(task.meta_data)
609-
if i is None:
610-
logger.info(f"检测到{task.meta_data}不在宿舍,移除相关任务")
611-
return False
612-
return True
613-
614-
self.tasks = [t for t in self.tasks if should_keep(t)]
615-
merge_interval = config.conf.merge_interval
616-
merge_release_dorm(self.tasks, merge_interval)
386+
self.tasks = plan_metadata(self.op_data, self.tasks)
617387

618388
def infra_main(self):
619389
"""位于基建首页"""

arknights_mower/tests/scheduler_task_tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def test_reorder_1(self):
378378
op_data.operators["凯尔希"].current_index = 2
379379
op_data.dorm[2].name = "夕"
380380
plan = try_reorder(op_data)
381-
self.assertEqual(plan['dormitory_1'][2], "夕")
381+
self.assertEqual(plan["dormitory_1"][2], "夕")
382382
tasks = [SchedulerTask(task_plan=plan, task_type=TaskTypes.SHIFT_OFF)]
383383
check_dorm_ordering(tasks, op_data)
384384
self.assertEqual(len(tasks), 2)
@@ -391,6 +391,7 @@ def test_reorder_2(self):
391391
op_data.dorm[2].name = "夕"
392392
op_data.dorm[3].name = "见行者"
393393
op_data.dorm[4].name = "森蚺"
394+
394395
# op_data.config.ope_resting_priority=["森蚺","夕"]
395396
plan = try_reorder(op_data)
396397
self.assertEqual(len(plan), 3)

arknights_mower/utils/datetime.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ def get_server_time():
2323
return datetime.now(pytz.timezone("Asia/Dubai"))
2424

2525

26-
def pass_deadline():
27-
return get_server_time() > datetime(2025, 1, 1, tzinfo=pytz.timezone("Asia/Dubai"))
28-
29-
3026
# newbing说用这个来定义休息时间省事
3127
def format_time(seconds):
3228
if seconds < 0: # 权宜之计 配合刷生息演算

0 commit comments

Comments
 (0)