|
28 | 28 | from arknights_mower.utils.datetime import (
|
29 | 29 | format_time,
|
30 | 30 | get_server_weekday,
|
31 |
| - pass_deadline, |
32 | 31 | )
|
33 | 32 | from arknights_mower.utils.device.device import Device
|
34 | 33 | from arknights_mower.utils.digit_reader import DigitReader
|
|
43 | 42 | from arknights_mower.utils.scheduler_task import (
|
44 | 43 | SchedulerTask,
|
45 | 44 | TaskTypes,
|
46 |
| - add_release_dorm, |
47 | 45 | check_dorm_ordering,
|
48 | 46 | find_next_task,
|
49 |
| - merge_release_dorm, |
50 | 47 | plan_metadata,
|
51 | 48 | scheduling,
|
52 | 49 | try_add_release_dorm,
|
@@ -386,234 +383,7 @@ def plan_fia(self):
|
386 | 383 | self.tasks.sort(key=lambda task: task.time)
|
387 | 384 |
|
388 | 385 | 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) |
617 | 387 |
|
618 | 388 | def infra_main(self):
|
619 | 389 | """位于基建首页"""
|
|
0 commit comments