Skip to content

Commit

Permalink
新增2设置
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawnsdaddy committed Feb 1, 2025
1 parent 910bdbf commit d8e776f
Show file tree
Hide file tree
Showing 12 changed files with 220 additions and 37 deletions.
2 changes: 2 additions & 0 deletions arknights_mower/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def initialize(
ling_xi=config.plan.conf.ling_xi,
workaholic=config.plan.conf.workaholic,
free_blacklist=conf.free_blacklist,
ope_resting_priority=conf.ope_resting_priority,
resting_threshold=conf.resting_threshold,
refresh_trading_config=config.plan.conf.refresh_trading,
refresh_drained=config.plan.conf.refresh_drained,
Expand Down Expand Up @@ -90,6 +91,7 @@ def initialize(
ling_xi=i["conf"]["ling_xi"],
workaholic=i["conf"]["workaholic"],
free_blacklist=i["conf"]["free_blacklist"],
ope_resting_priority=i["conf"]["ope_resting_priority"],
resting_threshold=conf.resting_threshold,
refresh_trading_config=i["conf"]["refresh_trading"],
refresh_drained=i["conf"]["refresh_drained"],
Expand Down
3 changes: 2 additions & 1 deletion arknights_mower/tests/scheduler_task_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def test_reorder_1(self):
op_data.operators["凯尔希"].current_index = 2
op_data.dorm[2].name = "夕"
plan = try_reorder(op_data)
self.assertEqual(len(plan), 2)
self.assertEqual(plan['dormitory_1'][2], "夕")
tasks = [SchedulerTask(task_plan=plan, task_type=TaskTypes.SHIFT_OFF)]
check_dorm_ordering(tasks, op_data)
self.assertEqual(len(tasks), 2)
Expand All @@ -391,6 +391,7 @@ def test_reorder_2(self):
op_data.dorm[2].name = "夕"
op_data.dorm[3].name = "见行者"
op_data.dorm[4].name = "森蚺"
# op_data.config.ope_resting_priority=["森蚺","夕"]
plan = try_reorder(op_data)
self.assertEqual(len(plan), 3)
self.assertEqual(plan["dormitory_1"][2], "夕")
Expand Down
4 changes: 2 additions & 2 deletions arknights_mower/utils/config/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ class RunOrderGrandetModeConf(ConfModel):
"替换组心情监视"
merge_interval: float = 10
"不养闲人合并间隔"
flexible_shift_mode: bool = False
"弹性休息模式"
dorm_order: str = ""
"宿舍优先级"


class SimulatorPart(ConfModel):
Expand Down
2 changes: 2 additions & 0 deletions arknights_mower/utils/config/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class PlanConf(BaseModel):
"跑单时间刷新干员"
refresh_drained: str = ""
"用尽时间刷新干员"
ope_resting_priority: str = ""
"休息排序优先级"


class BackupPlanConf(PlanConf):
Expand Down
28 changes: 28 additions & 0 deletions arknights_mower/utils/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from evalidate import Expr, base_eval_model

from arknights_mower.utils import config
from arknights_mower.utils.plan import BaseProduct, PlanConfig

from ..data import agent_arrange_order, agent_list, base_room_list
Expand Down Expand Up @@ -263,6 +264,32 @@ def init_and_validate(self, update=False):
if _dorm.agent == "Free" and (dorm + str(_idx)) not in added:
self.dorm.append(Dormitory((dorm, _idx)))
added.append(dorm + str(_idx))
if config.conf.dorm_order == "":
logger.info(self.dorm)
config.conf.dorm_order = ",".join(
[
dorm.position[0] + "_" + str(dorm.position[1])
for dorm in self.dorm
]
)
logger.info(config.conf.dorm_order)
config.save_conf() # 保存配置
else:
dorm_order = config.conf.dorm_order.split(",")
current_dorm_names = {
dorm.position[0] + "_" + str(dorm.position[1]) for dorm in self.dorm
}
saved_dorm_names = set(dorm_order)
if saved_dorm_names == current_dorm_names:
self.dorm.sort(
key=lambda dorm: dorm_order.index(
dorm.position[0] + "_" + str(dorm.position[1])
)
)
else:
return (
"宿舍优先级和当前宿舍不匹配,请清除优先级自动排序或者自己更正"
)
else:
for key, value in self.shadow_copy.items():
if key not in self.operators:
Expand Down Expand Up @@ -748,6 +775,7 @@ def __init__(
self.time_stamp = time_stamp
self.workaholic = False
self.arrange_order = [2, "false"]
self.exhaust_time = None

@property
def current_room(self):
Expand Down
3 changes: 3 additions & 0 deletions arknights_mower/utils/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(
refresh_trading_config: str = "",
free_room: bool = False,
refresh_drained: str = "",
ope_resting_priority: str = "",
):
"""排班的设置
Expand Down Expand Up @@ -77,6 +78,7 @@ def __init__(
# 夕(room_3_1,room_1_3),令(room_3_1)
self.refresh_trading_config = to_list(refresh_trading_config)
self.refresh_drained = to_list(refresh_drained)
self.ope_resting_priority = to_list(ope_resting_priority)

def is_rest_in_full(self, agent_name) -> bool:
return agent_name in self.rest_in_full
Expand Down Expand Up @@ -119,6 +121,7 @@ def merge_config(self, target: Self) -> Self:
"free_blacklist",
"refresh_trading_config",
"refresh_drained",
"ope_resting_priority",
]:
p_dict = set(getattr(n, p))
target_p = set(getattr(target, p))
Expand Down
73 changes: 44 additions & 29 deletions arknights_mower/utils/scheduler_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,35 +387,50 @@ def plan_metadata(op_data, tasks):
def try_reorder(op_data):
# 复制副本,防止原本的dorm错误触发纠错
dorm = copy.deepcopy(op_data.dorm)
# 如果当前高优有空位(非高优人员),则重新排序,正在休息的人逐个往前挤
priority_list = op_data.config.ope_resting_priority
vip = sum(1 for key in op_data.plan.keys() if key.startswith("dorm"))
logger.debug(f"当前vip个数{vip}")
if vip == 0:
return
ready_index = 0
for idx, room in enumerate(dorm):
logger.debug(room)
if not room.name:
continue
op = op_data.operators[room.name]
if op.operator_type == "high" and idx >= vip and op.resting_priority != "high":
if idx == ready_index:
ready_index += 1
elif ready_index >= vip:
dorm[ready_index].name, room.name = (
room.name,
dorm[ready_index].name,
)
room.time = None
ready_index += 1
elif op.operator_type == "high":
if idx != ready_index:
dorm[ready_index].name, room.name = (
room.name,
dorm[ready_index].name,
)
room.time = None
ready_index += 1

def get_ranking(name):
if name in op_data.operators:
op = op_data.operators[name]
if op.operator_type == "high" and op.resting_priority == "high":
return "high"
elif op.operator_type == "high":
return "normal"
return "low"

dorm_info = [
{
"name": room.name,
"index": idx,
"time": room.time,
"priority": get_ranking(room.name),
}
for idx, room in enumerate(dorm) # **跳过 name 为空的 dorm**
]

def sort_key(op):
length = len(priority_list)
priority_order = {
"high": length,
"normal": length + 1,
"low": length + 2,
} # **先排 priority_list,再按 high > normal > low**
return (
priority_list.index(op["name"])
if op["name"] in priority_list and op["name"] != ""
else priority_order[op["priority"]],
op["index"],
)

dorm_info.sort(key=sort_key)
for idx in range(len(dorm)):
if dorm[idx].name: # **只修改非空 dorm**
dorm[idx].name = dorm_info[idx]["name"]
dorm[idx].time = dorm_info[idx]["time"]
plan = {}
logger.debug(f"更新房间信息{dorm}")
for room in dorm:
Expand Down Expand Up @@ -549,10 +564,10 @@ def check_dorm_ordering(tasks, op_data):
else:
logger.debug(f"检测到干员{current.name}已经上班")
v[idx] = "Free"
if room not in extra_plan:
extra_plan[room] = copy.deepcopy(v)
# 新生成移除任务 --> 换成移除
extra_plan[room][idx] = ""
if room not in extra_plan:
extra_plan[room] = copy.deepcopy(v)
# 新生成移除任务 --> 换成移除
extra_plan[room][idx] = ""
if "Free" == plan[room][idx].agent and not pass_first_free:
pass_first_free = True
if agent != "Current":
Expand Down
95 changes: 95 additions & 0 deletions ui/src/components/SlickDormSelect.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<template>
<slick-list
v-model:list="dormitoryValue"
axis="xy"
appendTo=".n-select"
:distance="5"
class="width100"
group="dormitory"
:accept="!props.disabled"
@update:list="deleteRepeat"
>
<n-select
:disabled="props.disabled"
multiple
filterable
:options="dormitories"
placeholder="选择宿舍位置"
v-model:value="dormitoryValue"
:filter="(p, o) => o.label.includes(p)"
:render-label="render_dorm_label"
:render-tag="render_dorm_slick_tag"
/>
</slick-list>
</template>

<script setup>
import { ref, h, computed } from 'vue'
import { SlickList, SlickItem } from 'vue-slicksort'
import { NTag } from 'naive-ui'
const dormitoryValue = defineModel() // 绑定 v-model:value
const props = defineProps({
disabled: {
type: Boolean,
default: false
}
})
// 生成宿舍列表 dormitory_x_y (x: 1-5, y: 2-5)
const dormitories = computed(() => {
let options = []
for (let x = 1; x <= 5; x++) {
for (let y = 2; y <= 5; y++) {
const value = `dormitory_${x}_${y}`
options.push({ label: `宿舍 ${x}-${y}`, value })
}
}
return options
})
// 渲染宿舍标签
const render_dorm_label = (option) => {
return h('div', {}, option.label)
}
// 渲染拖拽排序的标签
const render_dorm_slick_tag = ({ option, handleClose }) => {
return h(
SlickItem,
{
key: option.value,
index: dormitoryValue.value.findIndex((value) => value == option.value),
disabled: props.disabled,
style: 'z-index: 999; display: inline;'
},
() =>
h(
NTag,
{
closable: !props.disabled,
onClose: () => handleClose()
},
{ default: () => option.label }
)
)
}
// 去除重复选择
const deleteRepeat = function (dormList) {
for (let i = 0; i < dormList.length; i++) {
for (let j = i + 1; j < dormList.length; j++) {
if (dormList[i] === dormList[j]) {
dormList.splice(j--, 1)
}
}
}
}
</script>

<style scoped>
.width100 {
width: 100%;
}
</style>
24 changes: 20 additions & 4 deletions ui/src/pages/Plan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const {
backup_plans,
sub_plan,
refresh_trading,
refresh_drained
refresh_drained,
ope_resting_priority
} = storeToRefs(plan_store)
const { load_plan, fill_empty } = plan_store
Expand Down Expand Up @@ -105,7 +106,8 @@ function create_sub_plan() {
resting_priority: [],
workaholic: [],
refresh_trading: [],
refresh_drained: []
refresh_drained: [],
ope_resting_priority: []
},
plan: fill_empty({}),
trigger: {
Expand Down Expand Up @@ -144,7 +146,8 @@ watchEffect(() => {
exhaust_require: exhaust_require.value,
refresh_trading: refresh_trading.value,
free_blacklist: free_blacklist.value,
refresh_drained: refresh_drained.value
refresh_drained: refresh_drained.value,
ope_resting_priority: ope_resting_priority.value
}
} else {
current_conf.value = backup_plans.value[sub_plan.value].conf
Expand All @@ -161,6 +164,7 @@ watchEffect(() => {
refresh_trading.value = current_conf.value.refresh_trading
free_blacklist.value = current_conf.value.free_blacklist
refresh_drained.value = current_conf.value.refresh_drained
ope_resting_priority.value = current_conf.value.ope_resting_priority
} else {
backup_plans.value[sub_plan.value].conf = current_conf.value
}
Expand Down Expand Up @@ -265,7 +269,9 @@ function movePlanForward() {
<n-select v-model:value="sub_plan" :style="{ width: '150px' }" :options="sub_plan_options" />
<n-button :disabled="sub_plan == 'main'" @click="show_name_editor = true">
<template #icon>
<n-icon><Pencil /></n-icon>
<n-icon>
<Pencil />
</n-icon>
</template>
</n-button>
</n-button-group>
Expand Down Expand Up @@ -399,6 +405,16 @@ function movePlanForward() {
</template>
<slick-operator-select v-model="current_conf.free_blacklist"></slick-operator-select>
</n-form-item>
<n-form-item>
<template #label>
<span>干员休息优先级</span>
<help-text>
<p>会按照优先级放入宿舍的时候重新排序</p>
<p>宿舍重新排序触发此设置优先级最高,所以非高效组谨慎填写</p>
</help-text>
</template>
<slick-operator-select v-model="current_conf.ope_resting_priority"></slick-operator-select>
</n-form-item>
</n-form>
</template>
Expand Down
Loading

0 comments on commit d8e776f

Please sign in to comment.