Skip to content

Commit

Permalink
Merge pull request #386 from EightyDollars/dev_shawn
Browse files Browse the repository at this point in the history
add:增加基报相关控件
  • Loading branch information
ZhaoZuohong authored Nov 13, 2023
2 parents 6c6a1c8 + 9bbc40d commit 7173b36
Show file tree
Hide file tree
Showing 58 changed files with 662 additions and 109 deletions.
5 changes: 2 additions & 3 deletions arknights_mower/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ def set_recruit_options(base_scheduler, conf):
recruit_config["permit_target"] = conf["recruitment_permit"]
recruit_config["recruit_robot"] = conf["recruit_robot"]
recruit_config["recruitment_time"] = conf["recruitment_time"]
recruit_config["recruit_execution_gap"] = conf["recruit_gap"]
base_scheduler.recruit_config = recruit_config

logger.debug(f"更新公招设置:{base_scheduler.recruit_config}")


Expand Down Expand Up @@ -352,12 +352,11 @@ def simulate():
if sleep_time > 540:
# 刷新时间以鹰历为准
if base_scheduler.daily_mission != (datetime.now() - timedelta(hours=4)).date():

base_scheduler.mail_plan_solver()
if base_scheduler.report_plan_solver():
base_scheduler.daily_mission = (datetime.now() - timedelta(hours=4)).date()
if base_scheduler.skland_config["skland_enable"] == 1:
base_scheduler.skland_plan_solover()
base_scheduler.mail_plan_solver()
if base_scheduler.recruit_config['recruit_enable'] == 1:
base_scheduler.recruit_plan_solver()
if base_scheduler.maa_config["maa_enable"] == 1:
Expand Down
Binary file added arknights_mower/resources/recruit_ticket/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/recruit_ticket/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/recruit_ticket/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/recruit_ticket/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/recruit_ticket/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/recruit_ticket/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/recruit_ticket/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/recruit_ticket/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/recruit_ticket/8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/recruit_ticket/9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/refresh_time/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/refresh_time/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/report_number/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/report_number/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/report_number/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/report_number/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/report_number/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/report_number/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/report_number/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/report_number/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/report_number/8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/report_number/9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/report_number_white/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/report_number_white/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/report_number_white/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arknights_mower/resources/report_number_white/3.png
Binary file added arknights_mower/resources/report_number_white/4.png
Binary file added arknights_mower/resources/report_number_white/5.png
Binary file added arknights_mower/resources/report_number_white/6.png
Binary file added arknights_mower/resources/report_number_white/7.png
Binary file added arknights_mower/resources/report_number_white/8.png
Binary file added arknights_mower/resources/report_number_white/9.png
Binary file added arknights_mower/resources/shop_discount/50.png
Binary file added arknights_mower/resources/shop_discount/75.png
Binary file added arknights_mower/resources/sold_out.png
Binary file modified arknights_mower/resources/stone.png
3 changes: 2 additions & 1 deletion arknights_mower/solvers/base_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2265,9 +2265,10 @@ def skland_plan_solover(self):
def recruit_plan_solver(self):
if ('last_execution' not in self.recruit_config
or self.recruit_config['last_execution'] is None
or self.recruit_config['last_execution'] <= (datetime.now() - timedelta(hours=9))):
or self.recruit_config['last_execution'] <= (datetime.now() - timedelta(seconds=self.recruit_config['recruit_execution_gap'] * 3600))):
recruit([], self.send_message_config, self.recruit_config)
self.recruit_config['last_execution'] = datetime.now()
logger.info("下一次公开招募执行时间在{}小时之后".format(self.recruit_config['recruit_execution_gap']))

def mail_plan_solver(self):
if self.check_mail_enable:
Expand Down
53 changes: 30 additions & 23 deletions arknights_mower/solvers/recruit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
from typing import Tuple, Dict, Any
import re
import cv2
import numpy as np

from ..data import recruit_agent, agent_with_tags, recruit_tag, result_template_list
from ..ocr import ocr_rectify, ocrhandle
from ..utils import segment, rapidocr
from .. import __rootdir__
from ..utils.device import Device
from ..utils.digit_reader import DigitReader
from ..utils.email import recruit_template, recruit_rarity
from ..utils.image import cropimg, bytes2img
from ..utils.image import cropimg, bytes2img, loadimg
from ..utils.log import logger
from ..utils.recognize import RecognizeError, Recognizer, Scene
from ..utils.solver import BaseSolver
Expand Down Expand Up @@ -41,7 +43,7 @@ def __init__(self, device: Device = None, recog: Recognizer = None) -> None:
self.permit_count = None
self.can_refresh = None
self.enough_lmb = True

self.digitReader = DigitReader()
self.recruit_order = [6, 5, 1, 4, 3, 2]

def run(self, priority: list[str] = None, send_message_config={}, recruit_config={}):
Expand Down Expand Up @@ -124,23 +126,29 @@ def transition(self) -> bool:

logger.info(f"刷新次数:{refresh_res}")

if self.permit_count is None:
p0, p1 = self.find("recruit_ticket")
p2, p3 = self.find("stone")
recruit_ticket_img = self.recog.img[p0[1]:p1[1], p1[0]:p2[0]]
recruit_ticket_gray = cv2.cvtColor(recruit_ticket_img, cv2.COLOR_BGR2GRAY)
try:
res = rapidocr.engine(recruit_ticket_gray, use_det=False, use_cls=False, use_rec=True)[0][0][0]
if res == 'o' or res == 'O':
res = '0'
res = re.sub("\D", "", res)
try:
if self.permit_count is None:
template_ticket = loadimg(f"{__rootdir__}/resources/recruit_ticket.png")
img = self.recog.img
res = cv2.matchTemplate(img, template_ticket, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
h, w = template_ticket.shape[:-1]
p0 = max_loc
p1 = (p0[0] + w, p0[1] + h)

template_stone = loadimg(f"{__rootdir__}/resources/stone.png")
res = cv2.matchTemplate(img, template_stone, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
p2 = max_loc

res = self.digitReader.get_recruit_ticket(img[p2[1]:p1[1], p1[0]:p2[0]])
if str(res).isdigit():
self.permit_count = int(res)
logger.info(f"招募券数量:{res}")
except:
# 设置为1 先保证后续流程能正常进行
self.permit_count = 1
logger.error("招募券数量读取失败")
except:
# 设置为1 先保证后续流程能正常进行
self.permit_count = 1
logger.error("招募券数量读取失败")

if self.can_refresh is False and self.permit_count <= 0:
logger.info("无招募券和刷新次数,结束公招")
Expand Down Expand Up @@ -193,7 +201,7 @@ def transition(self) -> bool:
else:
raise RecognizeError('Unknown scene')

def recruit_tags(self) -> bool:
def recruit_tags(self):
""" 识别公招标签的逻辑 """
if self.find('recruit_no_ticket') is not None:
self.has_ticket = False
Expand Down Expand Up @@ -231,7 +239,7 @@ def recruit_tags(self) -> bool:
"html")
logger.info('稀有tag,发送邮件')
self.back()
return True
return

if recruit_cal_result[0][1][0]['star'] == 3:
# refresh
Expand All @@ -245,19 +253,19 @@ def recruit_tags(self) -> bool:
if not self.enough_lmb:
logger.info('龙门币不足 结束公招')
self.back()
return False
return
# 如果没有招募券则只刷新标签不选人
if not self.has_ticket:
logger.info('无招募券')
self.back()
return False
return

# best为空说明这次大概率三星
# 券数量少于预期值,仅招募四星或者停止招募,只刷新标签
if self.permit_count <= self.recruit_config["permit_target"] and recruit_result_level == 3:
logger.info('不招三星')
self.back()
return False
return

choose = []
if recruit_result_level > 3:
Expand Down Expand Up @@ -325,8 +333,7 @@ def recruit_result(self):

for template_name in result_template_list:
tem_path = f"{__rootdir__}/resources/agent_name/{template_name}.png"
template_ = cv2.imread(tem_path.__str__())
template_ = cv2.cvtColor(template_, cv2.COLOR_BGR2GRAY)
template_ = cv2.imdecode(np.fromfile(tem_path.__str__(), dtype=np.uint8), cv2.IMREAD_GRAYSCALE)
res = cv2.matchTemplate(img_binary, template_, cv2.TM_CCORR_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
if max < max_val:
Expand Down
89 changes: 40 additions & 49 deletions arknights_mower/solvers/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@
import os
import datetime

import numpy as np
import pandas as pd
import cv2

from ..utils import rapidocr
from ..utils.device import Device
from ..data import __rootdir__
from ..utils.log import logger
from ..utils.path import get_path
from ..utils.recognize import RecognizeError, Recognizer, Scene
from ..utils.solver import BaseSolver
from arknights_mower.utils.device import Device
from arknights_mower.data import __rootdir__
from arknights_mower.utils.digit_reader import DigitReader
from arknights_mower.utils.image import loadimg
from arknights_mower.utils.log import logger
from arknights_mower.utils.path import get_path
from arknights_mower.utils.recognize import RecognizeError, Recognizer, Scene
from arknights_mower.utils.solver import BaseSolver


def remove_blank(target: str):
if target is None or target is "":
if target is None or target == "":
return target

target.strip()
Expand All @@ -33,9 +35,11 @@ def __init__(self, device: Device = None, recog: Recognizer = None) -> None:
self.low_range_gray = (100, 100, 100)
self.high_range_gray = (255, 255, 255)
self.date = (datetime.datetime.now() - datetime.timedelta(hours=4)).date().__str__()
self.digitReader = DigitReader()
self.report_res = {
"作战录像": None,
"赤金": None,
"赤金数量": 0,
"龙门币订单": None,
"龙门币订单数": None,
"合成玉": None,
Expand Down Expand Up @@ -81,44 +85,25 @@ def read_report(self):
img = cv2.cvtColor(self.recog.img[0:1080, 1280:1920], cv2.COLOR_BGR2RGB)
p0, p1 = self.locate_report(img, 'riic_exp')
p2, p3 = self.locate_report(img, 'riic_exp_text')
self.report_res['作战录像'] = \
rapidocr.engine(img[p2[1]:p1[1], p1[0]:p2[0]], use_det=False, use_cls=False, use_rec=True)[0][0][0]
self.report_res['作战录像'] = self.digitReader.get_report_number(img[p2[1]:p1[1], p1[0]:p2[0]])

p0, p1 = self.locate_report(img, 'riic_iron')
p2, p3 = self.locate_report(img, 'riic_iron_text')
self.report_res['赤金'] = \
rapidocr.engine(img[p2[1]:p1[1], p1[0]:p2[0]], use_det=False, use_cls=False, use_rec=True)[0][0][0]
self.report_res['赤金'] = self.digitReader.get_report_number(img[p2[1]:p1[1], p1[0]:p2[0]])

p0, p1 = self.locate_report(img, 'riic_iron_order')
p2, p3 = self.locate_report(img, 'riic_order')
self.report_res['龙门币订单'] = \
rapidocr.engine(img[p2[1]:p1[1], p1[0]:p2[0]], use_det=False, use_cls=False, use_rec=True)[0][0][0]
iron_threshold_gray = cv2.inRange(img[p2[1]:p3[1], p3[0]:img.shape[1] - 40], self.low_range_gray,
self.high_range_gray)
iron_padded_img = cv2.resize(iron_threshold_gray,
[iron_threshold_gray.shape[0] * 4, iron_threshold_gray.shape[1] * 2])
self.report_res['龙门币订单数'] = \
rapidocr.engine(iron_padded_img, use_det=False, use_cls=False, use_rec=True)[0][0][0]

img = img[p3[1]:img.shape[0], 0:img.shape[1] - 40]
self.report_res['龙门币订单'] = self.digitReader.get_report_number(img[p2[1]:p1[1], p1[0]:p2[0]])
self.report_res['龙门币订单数'] = self.digitReader.get_report_number_white(
img[p2[1]:p3[1], p3[0]:img.shape[1] - 20])

img = img[p3[1]:img.shape[0], 0:img.shape[1] - 20]
p0, p1 = self.locate_report(img, 'riic_orundum')
p2, p3 = self.locate_report(img, 'riic_order')
self.report_res['合成玉'] = \
rapidocr.engine(img[p2[1]:p1[1], p1[0]:p2[0]], use_det=False, use_cls=False, use_rec=True)[0][0][0]
if self.report_res['合成玉'] is None or str(self.report_res['合成玉']).isdigit() is False:
orundum_padded_img = cv2.resize(img[p2[1]:p1[1], p1[0]:p1[0] + 50],
[img[p2[1]:p1[1], p1[0]:p1[0] + 50].shape[0] * 6,
img[p2[1]:p1[1], p1[0]:p1[0] + 50].shape[1] * 3])
self.report_res['合成玉'] = \
rapidocr.engine(orundum_padded_img, use_det=False, use_cls=False, use_rec=True)[0][0][0]
orundum_threshold_gray = cv2.inRange(img[p2[1]:p3[1], p3[0]:img.shape[1] - 40], self.low_range_gray,
self.high_range_gray)
orundum_padded_img = cv2.resize(orundum_threshold_gray,
[orundum_threshold_gray.shape[0] * 3, iron_threshold_gray.shape[1] * 2])
self.report_res['合成玉订单数量'] = \
rapidocr.engine(orundum_padded_img, use_det=False, use_cls=False, use_rec=True)[0][0][0]

self.adjust_result()
self.report_res['合成玉'] = self.digitReader.get_report_number(img[p2[1]:p1[1], p1[0]:p2[0]])
self.report_res['合成玉订单数量'] = self.digitReader.get_report_number_white(
img[p2[1]:p3[1], p3[0]:img.shape[1]])

self.record_report()
except:
logger.info("基报识别失败 润")
Expand All @@ -128,7 +113,7 @@ def locate_report(self, img, template_name):
try:
template_path = "{}/resources/{}.png".format(__rootdir__, template_name)
logger.debug("待匹配模板图片{}的路径为{}".format(template_name, template_path))
template = cv2.imread(template_path.__str__())
template = cv2.imdecode(np.fromfile(template_path.__str__(), dtype=np.uint8), cv2.IMREAD_COLOR)
logger.debug("待匹配模板图片{}读取成功".format(template_name))
res = cv2.matchTemplate(img, template, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
Expand All @@ -142,16 +127,6 @@ def locate_report(self, img, template_name):
except:
logger.error("{}匹配失败".format(template_name))

def adjust_result(self):
logger.debug("调整基报读取数据 {}".format(self.report_res))
for key in self.report_res:
if self.report_res[key]:
self.report_res[key].strip()
if self.report_res[key] == "o" or self.report_res[key] == "O":
self.report_res[key] = 0
if str(self.report_res[key]).isdigit() is False:
self.report_res[key] = None

def record_report(self):
logger.info(f"存入{self.date}的数据{self.report_res}")
res_df = pd.DataFrame(self.report_res, index=[self.date])
Expand All @@ -169,3 +144,19 @@ def has_record(self):
return False
except PermissionError:
logger.info("report.csv正在被占用")


def get_report_data():
record_path = get_path("@app/tmp/report.csv")
try:
data = {}
if os.path.exists(record_path) is False:
logger.debug("基报不存在")
return False
df = pd.read_csv(record_path, encoding='gbk')
data = df.to_dict('dict')
print(data)
except PermissionError:
logger.info("report.csv正在被占用")


3 changes: 2 additions & 1 deletion arknights_mower/templates/conf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,5 @@ run_order_grandet_mode:
enable: true
buffer_time: 30
server_push_enable: false
sendKey: ''
sendKey: ''
recruit_gap: 9
Loading

0 comments on commit 7173b36

Please sign in to comment.