Skip to content

Commit

Permalink
Merge branch 'release/2.1.4' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Konano committed Jun 9, 2022
2 parents dc43270 + fa4c613 commit b52f980
Show file tree
Hide file tree
Showing 46 changed files with 223 additions and 234 deletions.
4 changes: 2 additions & 2 deletions arknights_mower/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path
import platform
import sys
from pathlib import Path

# Use sys.frozen to check if run through pyinstaller frozen exe, and sys._MEIPASS to get temp path.
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
Expand All @@ -15,4 +15,4 @@
__cli__ = not (__pyinstall__ and not sys.argv[1:])

__system__ = platform.system().lower()
__version__ = '2.1.3'
__version__ = '2.1.4'
5 changes: 2 additions & 3 deletions arknights_mower/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import traceback
from pathlib import Path

from . import __rootdir__, __pyinstall__
from . import __pyinstall__, __rootdir__
from .command import *
from .utils import config
from .utils.device import Device
Expand Down Expand Up @@ -38,8 +38,7 @@ def main(module: bool = True) -> None:
config.build_config(config_path, module)
else:
if not config_path.exists():
logger.error(
f'The configuration file does not exist: {config_path}')
logger.error(f'The configuration file does not exist: {config_path}')
return
try:
logger.info(f'Loading the configuration file: {config_path}')
Expand Down
2 changes: 1 addition & 1 deletion arknights_mower/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from . import __version__
from .solvers import *
from .utils import config
from .utils.log import logger
from .utils.device import Device
from .utils.log import logger
from .utils.param import ParamError, parse_operation_params


Expand Down
1 change: 0 additions & 1 deletion arknights_mower/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from .. import __rootdir__


# agents list in Arknights
agent_list = json.loads(
Path(f'{__rootdir__}/data/agent.json').read_text('utf-8'))
Expand Down
3 changes: 3 additions & 0 deletions arknights_mower/data/agent.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"图耶",
"桑葚",
"蜜莓",
"濯尘芙蓉",
"临光",
"",
"",
Expand All @@ -141,6 +142,7 @@
"火神",
"石棉",
"暮落",
"车尔尼",
"闪击",
"暴雨",
"灰毫",
Expand Down Expand Up @@ -193,6 +195,7 @@
"异客",
"卡涅利安",
"澄闪",
"黑键",
"灵知",
"安洁莉娜",
"铃兰",
Expand Down
Binary file modified arknights_mower/fonts/SourceHanSansSC-Bold.otf
Binary file not shown.
12 changes: 7 additions & 5 deletions arknights_mower/ocr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from .model import OcrHandle
from .ocrspace import API, Language
from ..data import ocr_error
from ..utils import config
from ..utils.log import logger
from ..data import ocr_error
from .model import OcrHandle
from .ocrspace import API, Language

ocrhandle = OcrHandle()
ocronline = API(api_key=config.OCR_APIKEY,
language=Language.Chinese_Simplified)


def ocr_rectify(img, pre, valid, text=''):
Expand All @@ -22,6 +20,10 @@ def ocr_rectify(img, pre, valid, text=''):
:return res: str | None, 识别的结果
"""
logger.warning(f'{text}识别异常:正在调用在线 OCR 处理异常结果……')

global ocronline
ocronline = API(api_key=config.OCR_APIKEY,
language=Language.Chinese_Simplified)
pre_res = pre[1]
res = ocronline.predict(img, pre[2])
if res is None or res == pre_res:
Expand Down
4 changes: 2 additions & 2 deletions arknights_mower/ocr/crnn.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import numpy as np
from PIL import Image
import onnxruntime as rt
from PIL import Image

from .utils import strLabelConverter, resizeNormalize
from .keys import alphabetChinese as alphabet
from .utils import resizeNormalize, strLabelConverter

converter = strLabelConverter(''.join(alphabet))

Expand Down
2 changes: 1 addition & 1 deletion arknights_mower/ocr/decode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import cv2
import pyclipper
import numpy as np
import pyclipper
from shapely.geometry import Polygon


Expand Down
9 changes: 5 additions & 4 deletions arknights_mower/ocr/model.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import cv2
import copy
import traceback

import cv2
import numpy as np
from PIL import Image

from .config import dbnet_model_path, crnn_model_path
from .dbnet import DBNET
from ..utils.log import logger
from .config import crnn_model_path, dbnet_model_path
from .crnn import CRNNHandle
from .dbnet import DBNET
from .utils import fix
from ..utils.log import logger


def sorted_boxes(dt_boxes):
Expand Down
5 changes: 3 additions & 2 deletions arknights_mower/ocr/ocrspace.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import base64
import traceback

import cv2
import numpy
import base64
import requests

from .utils import fix
from ..utils.log import logger
from ..utils.recognize import RecognizeError
from .utils import fix


class Language:
Expand Down
5 changes: 3 additions & 2 deletions arknights_mower/ocr/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from PIL import Image
import numpy as np
import re

import numpy as np
from PIL import Image

from ..data import ocr_error
from ..utils.log import logger

Expand Down
Binary file added arknights_mower/resources/arrange_empty_room.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion arknights_mower/solvers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
from .mission import MissionSolver
from .operation import OpeSolver
from .recruit import RecruitSolver
from .shop import ShopSolver
from .schedule import ScheduleSolver
from .shop import ShopSolver
109 changes: 34 additions & 75 deletions arknights_mower/solvers/base_construct.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from __future__ import annotations

import numpy as np
from enum import Enum

from ..utils import detector, segment, character_recognize
import numpy as np

from ..data import base_room_list
from ..utils import character_recognize, detector, segment
from ..utils import typealias as tp
from ..utils.device import Device
from ..utils.log import logger
from ..utils.recognize import Recognizer, Scene, RecognizeError
from ..utils.recognize import RecognizeError, Recognizer, Scene
from ..utils.solver import BaseSolver
from ..data import base_room_list


class ArrangeOrder(Enum):
Expand Down Expand Up @@ -66,7 +67,7 @@ def transition(self) -> None:
elif self.get_navigation():
self.tap_element('nav_infrastructure')
elif self.scene() == Scene.INFRA_ARRANGE_ORDER:
self.sleep(3)
self.tap_element('arrange_blue_yes')
elif self.scene() != Scene.UNKNOWN:
self.back_to_index()
else:
Expand Down Expand Up @@ -382,7 +383,7 @@ def drone(self, room: str):
self.tap(accelerate)
self.tap_element('all_in')
self.tap(accelerate, y_rate=1)

else:
accelerate = self.find('bill_accelerate')
while accelerate:
Expand All @@ -394,7 +395,7 @@ def drone(self, room: str):
st = accelerate[1] # 起点
ed = accelerate[0] # 终点
# 0.95, 1.05 are offset compensations
self.swipe_noinertia(st, (ed[0]*0.95-st[0]*1.05, 0), rebuild=True)
self.swipe_noinertia(st, (ed[0]*0.95-st[0]*1.05, 0), rebuild=True)
accelerate = self.find('bill_accelerate')

logger.info('返回基建主界面')
Expand All @@ -407,6 +408,8 @@ def get_arrange_order(self) -> ArrangeOrder:
score = self.recog.score(arrange_order_res[order][0])
if score is not None and score[0] > best_score:
best_score, best_order = score[0], order
# if best_score < 0.6:
# raise RecognizeError
logger.debug((best_score, best_order))
return best_order

Expand Down Expand Up @@ -482,22 +485,22 @@ def choose_agent(self, agent: list[str], skip_free: int = 0, order: ArrangeOrder
if y[0] == '菲亚梅塔':
self.tap((y[1][0]), interval=0, rebuild=False)
break
agent.remove('菲亚梅塔')
agent.remove('菲亚梅塔')

# 如果菲亚梅塔是 the only one
if len(agent) == 0:
break
# 否则滑动到最左边
for _ in range(9):
self.swipe((w//2, h//2), (w//2, 0), interval=0.5)
self.swipe((w//2, h//2), (w//2, 0), interval=3, rebuild=False)

# reset the statuses and cancel the rightward-swiping
checked = set()
pre = set()
pre = set()
error_count = 0
continue

else:
for name in agent_name & agent:
for y in ret:
Expand Down Expand Up @@ -564,56 +567,6 @@ def agent_arrange(self, plan: tp.BasePlan) -> None:
# 进入进驻总览
self.tap_element('infra_overview', interval=2)

# 滑动到最顶(从首页进入默认最顶无需滑动)
# h, w = self.recog.h, self.recog.w
# for _ in range(4):
# self.swipe((w//2, h//2), (0, h//2), interval=0)
# self.swipe((w//2, h//2), (0, h//2), rebuild=False)

logger.info('撤下干员中……')
idx = 0
room_total = len(base_room_list)
need_empty = set(list(plan.keys()))
while idx < room_total:
# switch: 撤下干员按钮
ret, switch, mode = segment.worker(self.recog.img)

# 点击撤下干员按钮
if not mode:
self.tap((switch[0][0]+5, switch[0][1]+5), rebuild=False)
continue

if room_total-idx < len(ret):
# 已经滑动到底部
ret = ret[-(room_total-idx):]

for block in ret:
# 清空在换班计划中的房间
if base_room_list[idx] in need_empty:
need_empty.remove(base_room_list[idx])
self.tap((block[2][0]-5, block[2][1]-5))
dc = self.find('double_confirm')
if dc is not None:
self.tap((dc[1][0], (dc[0][1]+dc[1][1]) // 2))
while self.scene() == Scene.CONNECTING:
self.sleep(3)
if self.scene() != Scene.INFRA_ARRANGE:
raise RecognizeError
idx += 1

# 如果全部需要清空的房间都清空了就
if idx == room_total or len(need_empty) == 0:
break
block = ret[-1]
top = switch[2][1]
self.swipe_noinertia(tuple(block[1]), (0, top-block[1][1]))

# 滑动到顶部
h, w = self.recog.h, self.recog.w
for _ in range(4):
self.swipe((w//2, h//2), (0, h//2), interval=0.5)
self.swipe((w//2, h//2), (0, h//2), rebuild=False)

logger.info('安排干员工作……')
idx = 0
room_total = len(base_room_list)
Expand Down Expand Up @@ -643,6 +596,15 @@ def agent_arrange(self, plan: tp.BasePlan) -> None:
x = (7*block[0][0]+3*block[2][0])//10
y = (block[0][1]+block[2][1])//2
self.tap((x, y))

# 若不是空房间,则清空工作中的干员
if self.find('arrange_empty_room') is None:
if self.find('arrange_clean') is not None:
self.tap_element('arrange_clean')
else:
# 对于只有一个干员的房间,没有清空按钮,需要点击干员清空
self.tap((self.recog.w*0.38, self.recog.h*0.3), interval=0)

try:
if base_room_list[idx].startswith('dormitory'):
default_order = ArrangeOrder.FEELING
Expand All @@ -668,13 +630,10 @@ def agent_arrange(self, plan: tp.BasePlan) -> None:
self.tap_element(
'comfirm_blue', detected=True, judge=False, interval=3)
if self.scene() == Scene.INFRA_ARRANGE_CONFIRM:
x = self.recog.w // 3
x = self.recog.w // 3 * 2 # double confirm
y = self.recog.h - 10
self.tap((x, y), rebuild=False)
skip_free += plan[base_room_list[idx]].count('Free')
self.back()
else:
finished = True
self.tap((x, y), rebuild=True)
finished = True
while self.scene() == Scene.CONNECTING:
self.sleep(3)
idx += 1
Expand All @@ -690,9 +649,9 @@ def agent_arrange(self, plan: tp.BasePlan) -> None:
self.back()

def choose_agent_in_order(self, agent: list[str], exclude: list[str] = None, exclude_checked_in: bool = False, dormitory: bool = False):
"""
按照顺序选择干员,只选择未在工作、未注意力涣散、未在休息的空闲干员
"""
按照顺序选择干员,只选择未在工作、未注意力涣散、未在休息的空闲干员
:param agent: 指定入驻干员列表
:param exclude: 排除干员列表,不选择这些干员
:param exclude_checked_in: 是否仅选择未进驻干员
Expand Down Expand Up @@ -726,7 +685,7 @@ def choose_agent_in_order(self, agent: list[str], exclude: list[str] = None, exc
if not (self.find('agent_on_shift', scope=(x[1][0], x[1][2]))
or self.find('agent_resting', scope=(x[1][0], x[1][2]))
or (not dormitory and self.find('distracted', scope=(x[1][0], x[1][2])))):
if not x[0] in agent and not x[0] in exclude:
if x[0] not in agent and x[0] not in exclude:
self.tap(x[1], x_rate=0.5, y_rate=0.5, interval=0)
agent[idx] = x[0]
_free = x[0]
Expand Down Expand Up @@ -762,7 +721,7 @@ def choose_agent_in_order(self, agent: list[str], exclude: list[str] = None, exc
return _free

def fia(self, room: str):
"""
"""
使用菲亚梅塔恢复指定房间心情最差的干员的心情,同时保持工位顺序不变
目前仅支持制造站、贸易站、发电站 (因为其他房间在输入命令时较为繁琐,且需求不大)
使用前需要菲亚梅塔位于任意一间宿舍
Expand Down Expand Up @@ -843,7 +802,7 @@ def fia(self, room: str):
self.tap((self.recog.w*BY_EMO[0], self.recog.h*BY_EMO[1]), interval=0.1)
# 寻找这个房间里心情最低的干员,
_temp_on_shift_agents = on_shift_agents.copy()
while not 'Free' in _temp_on_shift_agents:
while 'Free' not in _temp_on_shift_agents:
ret = character_recognize.agent(self.recog.img)
ret = np.array(ret, dtype=object).reshape(-1, 2, 2).reshape(-1, 2)
for x in ret:
Expand Down Expand Up @@ -900,7 +859,7 @@ def fia(self, room: str):
self.tap((self.recog.w*0.82, self.recog.h*0.25), interval=2)
self.choose_agent_in_order(on_shift_agents)
self.tap_element('comfirm_blue', detected=True, judge=False, interval=3)

self.back(interval=2)

# def clue_statis(self):
Expand Down
Loading

0 comments on commit b52f980

Please sign in to comment.