perf.添加一些日志,优化部分简单逻辑

This commit is contained in:
MistEO
2021-11-05 00:31:48 +08:00
parent 7f1eff2188
commit 09cb5b271a
12 changed files with 93 additions and 16 deletions

View File

@@ -1345,6 +1345,12 @@
"maskRange": [
1,
255
],
"roi": [
800,
0,
480,
720
]
},
"InfrastClueOnTheRightSwipeBegin": {
@@ -1356,8 +1362,8 @@
300,
100
],
"preDelay": 1000,
"rearDelay": 1000,
"preDelay": 500,
"rearDelay": 500,
"maxTimes": 1,
"Doc": "这里的preDelay作为滑动duration使用rearDelay作为滑动额外延时使用maxTimes作为重复次数使用"
},

View File

@@ -42,7 +42,7 @@ namespace asst {
OpersDetected = 4000, // 识别到了干员s
OpersIdtfResult, // 干员识别结果(总的)
InfrastComb, // 当前房间的最优干员组合
EnterStation, // 进入某个房间
EnterFacility, // 进入某个房间
StationInfo, // 当前房间信息
ReadyToShift, // 准备换班
ShiftCompleted, // 换班完成(单个房间)
@@ -80,7 +80,7 @@ namespace asst {
{AsstMsg::OpersDetected, "OpersDetected"},
{AsstMsg::OpersIdtfResult, "OpersIdtfResult"},
{AsstMsg::InfrastComb, "InfrastComb"},
{AsstMsg::EnterStation, "EnterStation"},
{AsstMsg::EnterFacility, "EnterFacility"},
{AsstMsg::StationInfo, "StationInfo"},
{AsstMsg::ReadyToShift, "ReadyToShift"},
{AsstMsg::ShiftCompleted, "ShiftCompleted"},

View File

@@ -5,18 +5,29 @@
#include "InfrastFacilityImageAnalyzer.h"
#include "Controller.h"
#include "Resource.h"
#include "Logger.hpp"
#include "AsstMsg.h"
bool asst::InfrastAbstractTask::enter_facility(const std::string& facility, int index)
{
LogTraceFunction;
json::value enter_json = json::object{
{ "facility", facility },
{ "index", index}
};
m_callback(AsstMsg::EnterFacility, enter_json, m_callback_arg);
const auto& image = ctrler.get_image();
InfrastFacilityImageAnalyzer analyzer(image);
analyzer.set_to_be_analyzed({ facility });
if (!analyzer.analyze()) {
log.trace("result is empty");
return false;
}
Rect rect = analyzer.get_rect(facility, index);
if (rect.empty()) {
log.trace("facility index is out of range");
return false;
}
@@ -30,6 +41,8 @@ bool asst::InfrastAbstractTask::enter_facility(const std::string& facility, int
bool asst::InfrastAbstractTask::enter_oper_list_page()
{
LogTraceFunction;
auto image = ctrler.get_image();
// 识别右边的“进驻”按钮
@@ -40,25 +53,30 @@ bool asst::InfrastAbstractTask::enter_oper_list_page()
// 如果没找到,说明“进驻信息”这个按钮没有被点开,那就点开它
if (!enter_analyzer.analyze()) {
log.trace("ready to analyze the stationed info button");
OcrImageAnalyzer station_analyzer(image);
const auto stationedinfo_task_ptr = std::dynamic_pointer_cast<OcrTaskInfo>(
resource.task().task_ptr("InfrastStationedInfo"));
station_analyzer.set_task_info(*stationedinfo_task_ptr);
if (station_analyzer.analyze()) {
log.trace("the stationed info button found");
ctrler.click(station_analyzer.get_result().front().rect);
sleep(stationedinfo_task_ptr->rear_delay);
// 点开了按钮之后,再识别一次右边的
image = ctrler.get_image();
enter_analyzer.set_image(image);
if (!enter_analyzer.analyze()) {
log.error("no enterlist button");
return false;
}
}
else {
log.error("no stationed info button");
return false;
}
}
log.trace("ready to click the enterlist button");
ctrler.click(enter_analyzer.get_result().front().rect);
sleep(enter_task_ptr->rear_delay);
@@ -67,6 +85,7 @@ bool asst::InfrastAbstractTask::enter_oper_list_page()
void asst::InfrastAbstractTask::async_swipe_of_operlist(bool reverse)
{
LogTraceFunction;
static Rect begin_rect = resource.task().task_ptr("InfrastOperListSwipeBegin")->specific_rect;
static Rect end_rect = resource.task().task_ptr("InfrastOperListSwipeEnd")->specific_rect;
static int duration = resource.task().task_ptr("InfrastOperListSwipeBegin")->pre_delay;
@@ -81,6 +100,7 @@ void asst::InfrastAbstractTask::async_swipe_of_operlist(bool reverse)
void asst::InfrastAbstractTask::await_swipe()
{
LogTraceFunction;
static int extra_delay = resource.task().task_ptr("InfrastOperListSwipeBegin")->rear_delay;
ctrler.wait(m_last_swipe_id);
@@ -89,6 +109,7 @@ void asst::InfrastAbstractTask::await_swipe()
bool asst::InfrastAbstractTask::click_bottomleft_tab()
{
LogTraceFunction;
const auto task_ptr = resource.task().task_ptr("InfrastBottomLeftTab");
ctrler.click(task_ptr->specific_rect);
sleep(task_ptr->rear_delay);
@@ -97,6 +118,7 @@ bool asst::InfrastAbstractTask::click_bottomleft_tab()
bool asst::InfrastAbstractTask::click_clear_button()
{
LogTraceFunction;
const auto task_ptr = resource.task().task_ptr("InfrastClearButton");
ctrler.click(task_ptr->specific_rect);
sleep(task_ptr->rear_delay);
@@ -105,6 +127,7 @@ bool asst::InfrastAbstractTask::click_clear_button()
bool asst::InfrastAbstractTask::click_confirm_button()
{
LogTraceFunction;
const auto task_ptr = std::dynamic_pointer_cast<OcrTaskInfo>(
resource.task().task_ptr("InfrastConfirmButton"));
ctrler.click(task_ptr->specific_rect);
@@ -136,6 +159,7 @@ void asst::InfrastAbstractTask::sync_swipe_of_operlist(bool reverse)
void asst::InfrastAbstractTask::swipe_to_the_left_of_operlist()
{
LogTraceFunction;
static Rect begin_rect = resource.task().task_ptr("InfrastOperListSwipeToTheLeftBegin")->specific_rect;
static Rect end_rect = resource.task().task_ptr("InfrastOperListSwipeToTheLeftEnd")->specific_rect;
static int duration = resource.task().task_ptr("InfrastOperListSwipeToTheLeftBegin")->pre_delay;
@@ -153,6 +177,7 @@ void asst::InfrastAbstractTask::swipe_to_the_left_of_operlist()
void asst::InfrastAbstractTask::swipe_to_the_left_of_main_ui()
{
LogTraceFunction;
static Rect begin_rect = resource.task().task_ptr("InfrastOperListSwipeToTheLeftBegin")->specific_rect;
static Rect end_rect = resource.task().task_ptr("InfrastOperListSwipeToTheLeftEnd")->specific_rect;
static int duration = resource.task().task_ptr("InfrastOperListSwipeToTheLeftBegin")->pre_delay;
@@ -163,6 +188,7 @@ void asst::InfrastAbstractTask::swipe_to_the_left_of_main_ui()
void asst::InfrastAbstractTask::swipe_to_the_right_of_main_ui()
{
LogTraceFunction;
static Rect begin_rect = resource.task().task_ptr("InfrastOperListSwipeToTheLeftBegin")->specific_rect;
static Rect end_rect = resource.task().task_ptr("InfrastOperListSwipeToTheLeftEnd")->specific_rect;
static int duration = resource.task().task_ptr("InfrastOperListSwipeToTheLeftBegin")->pre_delay;

View File

@@ -3,6 +3,7 @@
#include "MatchImageAnalyzer.h"
#include "Resource.h"
#include "AsstUtils.hpp"
#include "Logger.hpp"
bool asst::InfrastClueVacancyImageAnalyzer::analyze()
{
@@ -14,9 +15,11 @@ bool asst::InfrastClueVacancyImageAnalyzer::analyze()
resource.task().task_ptr(clue_vacancy + suffix));
analyzer.set_task_info(*task_ptr);
if (!analyzer.analyze()) {
log.trace("no", clue_vacancy, suffix);
continue;
}
Rect rect = analyzer.get_result().rect;
log.trace("has", clue_vacancy, suffix);
#ifdef LOG_TRACE
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(rect), cv::Scalar(0, 0, 255), 2);
cv::putText(m_image_draw, suffix, cv::Point(rect.x, rect.y + 1), 0, 1, cv::Scalar(0, 0, 255), 2);

View File

@@ -5,6 +5,7 @@
#include "InfrastMoodImageAnalyzer.h"
#include "Resource.h"
#include "Controller.h"
#include "Logger.hpp"
const std::string asst::InfrastDormTask::FacilityName = "Dorm";
@@ -35,6 +36,7 @@ bool asst::InfrastDormTask::run()
const auto& image = ctrler.get_image();
InfrastMoodImageAnalyzer mood_analyzer(image);
if (!mood_analyzer.analyze()) {
log.error("mood analyze faild!");
return false;
}
mood_analyzer.sort_result();
@@ -46,6 +48,7 @@ bool asst::InfrastDormTask::run()
return false;
}
if (quantity_selected >= MaxNumOfOpers) {
log.trace("quantity_selected:", quantity_selected, ", just break");
break;
}
switch (mood_info.smiley.type)
@@ -53,6 +56,7 @@ bool asst::InfrastDormTask::run()
case InfrastSmileyType::Rest:
// 如果当前页面休息完成的人数超过5个说明已经已经把所有心情不满的滑过一遍、没有更多的了直接退出即可
if (++quantity_resting > MaxNumOfOpers) {
log.trace("quantity_resting:", quantity_resting, ", confirm");
click_confirm_button();
return true;
}
@@ -66,6 +70,7 @@ bool asst::InfrastDormTask::run()
{
ctrler.click(mood_info.rect);
if (++quantity_selected >= MaxNumOfOpers) {
log.trace("quantity_selected:", quantity_selected, ", just break");
break;
}
}
@@ -75,6 +80,7 @@ bool asst::InfrastDormTask::run()
}
}
if (quantity_selected >= MaxNumOfOpers) {
log.trace("quantity_selected:", quantity_selected, ", just break");
break;
}
sync_swipe_of_operlist();
@@ -87,6 +93,8 @@ bool asst::InfrastDormTask::run()
bool asst::InfrastDormTask::click_confirm_button()
{
LogTraceFunction;
const auto task_ptr = std::dynamic_pointer_cast<OcrTaskInfo>(
resource.task().task_ptr("InfrastConfirmButton"));
ctrler.click(task_ptr->specific_rect);

View File

@@ -3,6 +3,7 @@
#include "Resource.h"
#include "MultiMatchImageAnalyzer.h"
#include "AsstUtils.hpp"
#include "Logger.hpp"
bool asst::InfrastFacilityImageAnalyzer::analyze()
{
@@ -32,13 +33,13 @@ bool asst::InfrastFacilityImageAnalyzer::analyze()
int cor_suffix_index = -1;
for (const auto& [key, task_name] : facility_task_name) {
if (!m_to_be_analyzed.empty()) { // 若为空,则分析所有设施
if (std::find(m_to_be_analyzed.cbegin(), m_to_be_analyzed.cend(), key)
== m_to_be_analyzed.cend()) {
continue;
}
for (const auto& key : m_to_be_analyzed) {
auto find_iter = facility_task_name.find(key);
if (find_iter == facility_task_name.cend()) {
log.error("facility name error", key);
continue;
}
std::string task_name = find_iter->second;
std::vector<MatchRect> cur_facility_result;
// 已知基建缩放状态的时候,只识别这个缩放状态下的就行了
// 否则识别所有状态,直到找出正确的当前缩放状态

View File

@@ -11,7 +11,6 @@ namespace asst {
virtual bool analyze() override;
// 若为空,则分析所有设施
void set_to_be_analyzed(std::vector<std::string> facilities) noexcept {
m_to_be_analyzed = std::move(facilities);
}
@@ -53,7 +52,7 @@ namespace asst {
// key设施名value所有这种设施的当前Rect例如所有制造站的位置
std::unordered_map<std::string, std::vector<MatchRect>> m_result;
// 需要识别的设施名,若为空,则分析所有设施
// 需要识别的设施名
std::vector<std::string> m_to_be_analyzed;
};
}

View File

@@ -17,10 +17,7 @@ bool asst::InfrastInfoTask::run()
const auto& image = ctrler.get_image();
InfrastFacilityImageAnalyzer analyzer(image);
std::vector<std::string> all_facilities;
for (auto&& [key, _value] : resource.infrast().get_facility_info()) {
all_facilities.emplace_back(key);
}
analyzer.set_to_be_analyzed({ "Mfg", "Trade", "Power" });
if (!analyzer.analyze()) {
return false;
}

View File

@@ -8,12 +8,20 @@
bool asst::InfrastMoodImageAnalyzer::analyze()
{
LogTraceFunction;
mood_detect();
mood_analyze();
hash_calc();
selected_analyze();
working_analyze();
for (auto&& info : m_result) {
log.trace(info.hash, info.rect.to_string(),
"smiley:", (int)info.smiley.type, "mood:", info.percentage,
"selected:", info.selected, "working:", info.working);
}
return true;
}

View File

@@ -35,6 +35,7 @@
bool asst::InfrastProductionTask::shift_facility_list()
{
LogTraceFunction;
facility_list_detect();
if (need_exit()) {
return false;
@@ -57,6 +58,7 @@ bool asst::InfrastProductionTask::shift_facility_list()
const auto& image = ctrler.get_image();
add_analyzer.set_image(image);
if (!add_analyzer.analyze()) {
log.info("no add button, just continue");
continue;
}
Rect add_button = add_analyzer.get_result().rect;
@@ -76,6 +78,7 @@ bool asst::InfrastProductionTask::shift_facility_list()
}
}
set_product(cur_product);
log.info("cur product", cur_product);
/* 进入干员选择页面 */
ctrler.click(add_button);
sleep(add_task_ptr->rear_delay);
@@ -110,6 +113,7 @@ bool asst::InfrastProductionTask::shift_facility_list()
bool asst::InfrastProductionTask::opers_detect_with_swipe()
{
LogTraceFunction;
m_all_available_opers.clear();
int first_number = 0;
@@ -118,6 +122,7 @@ bool asst::InfrastProductionTask::opers_detect_with_swipe()
return false;
}
size_t num = opers_detect();
log.trace("opers_detect return", num);
// 这里本来是判断不相等就可以退出循环。
// 但是有时候滑动会把一个干员挡住一半一个页面完整的干员真的只有10个所以加个2的差值
@@ -137,6 +142,7 @@ bool asst::InfrastProductionTask::opers_detect_with_swipe()
size_t asst::InfrastProductionTask::opers_detect()
{
LogTraceFunction;
const auto& image = ctrler.get_image();
InfrastSkillsImageAnalyzer skills_analyzer(image);
@@ -187,6 +193,7 @@ size_t asst::InfrastProductionTask::opers_detect()
bool asst::InfrastProductionTask::optimal_calc()
{
LogTraceFunction;
auto& facility_info = resource.infrast().get_facility_info(m_facility);
int max_num_of_opers = facility_info.max_num_of_opers;
@@ -333,6 +340,7 @@ bool asst::InfrastProductionTask::optimal_calc()
bool asst::InfrastProductionTask::opers_choose()
{
LogTraceFunction;
bool has_error = false;
while (true) {
if (need_exit()) {
@@ -403,6 +411,7 @@ bool asst::InfrastProductionTask::opers_choose()
bool asst::InfrastProductionTask::facility_list_detect()
{
LogTraceFunction;
m_facility_list_tabs.clear();
const auto& image = ctrler.get_image();

View File

@@ -38,6 +38,7 @@ bool asst::InfrastReceptionTask::run()
bool asst::InfrastReceptionTask::harvest_clue()
{
LogTraceFunction;
std::vector<std::string> tasks_vec = { "InfrastClueNew" };
while (!tasks_vec.empty()) {
if (need_exit()) {
@@ -74,6 +75,7 @@ bool asst::InfrastReceptionTask::harvest_clue()
bool asst::InfrastReceptionTask::proc_clue()
{
LogTraceFunction;
const static std::string clue_vacancy = "InfrastClueVacancy";
const static std::vector<std::string> clue_suffix = {
"No1", "No2", "No3", "No4", "No5", "No6", "No7" };
@@ -119,6 +121,7 @@ bool asst::InfrastReceptionTask::proc_clue()
bool asst::InfrastReceptionTask::proc_vacancy()
{
LogTraceFunction;
const static std::string clue_vacancy = "InfrastClueVacancy";
const static std::vector<std::string> clue_suffix = {
"No1", "No2", "No3", "No4", "No5", "No6", "No7" };
@@ -155,6 +158,7 @@ bool asst::InfrastReceptionTask::proc_vacancy()
bool asst::InfrastReceptionTask::shift()
{
LogTraceFunction;
const auto& image = ctrler.get_image();
MatchImageAnalyzer add_analyzer(image);
@@ -193,6 +197,7 @@ bool asst::InfrastReceptionTask::shift()
bool asst::InfrastReceptionTask::swipe_to_the_bottom_of_clue_list_on_the_right()
{
LogTraceFunction;
static Rect begin_rect = resource.task().task_ptr("InfrastClueOnTheRightSwipeBegin")->specific_rect;
static Rect end_rect = resource.task().task_ptr("InfrastClueOnTheRightSwipeEnd")->specific_rect;
static int duration = resource.task().task_ptr("InfrastClueOnTheRightSwipeBegin")->pre_delay;

View File

@@ -8,6 +8,8 @@
bool asst::InfrastSkillsImageAnalyzer::analyze()
{
LogTraceFunction;
m_skills_detected.clear();
m_skills_splited.clear();
m_result.clear();
@@ -18,11 +20,20 @@ bool asst::InfrastSkillsImageAnalyzer::analyze()
skill_analyze();
for (auto&& info : m_result) {
std::string skill_str;
for (auto&& skill : info.skills_comb.skills) {
skill_str += skill.names.front() + " ";
}
log.trace(info.hash, info.rect.to_string(), skill_str);
}
return true;
}
void asst::InfrastSkillsImageAnalyzer::sort_result()
{
LogTraceFunction;
// 按位置排个序
std::sort(m_result.begin(), m_result.end(),
[](const auto& lhs, const auto& rhs) -> bool {
@@ -38,6 +49,7 @@ void asst::InfrastSkillsImageAnalyzer::sort_result()
bool asst::InfrastSkillsImageAnalyzer::skills_detect()
{
LogTraceFunction;
const auto upper_task_ptr = resource.task().task_ptr("InfrastSkillsUpper");
const auto lower_task_ptr = resource.task().task_ptr("InfrastSkillsLower");
const auto hash_task_ptr = resource.task().task_ptr("InfrastSkillsHash");
@@ -98,6 +110,7 @@ bool asst::InfrastSkillsImageAnalyzer::skills_detect()
bool asst::InfrastSkillsImageAnalyzer::skills_split()
{
LogTraceFunction;
const auto task_ptr = std::dynamic_pointer_cast<MatchTaskInfo>(
resource.task().task_ptr("InfrastSkills"));
const auto thres = task_ptr->hist_threshold;
@@ -144,6 +157,7 @@ bool asst::InfrastSkillsImageAnalyzer::skills_split()
bool asst::InfrastSkillsImageAnalyzer::skill_analyze()
{
LogTraceFunction;
const auto task_ptr = std::dynamic_pointer_cast<MatchTaskInfo>(
resource.task().task_ptr("InfrastSkills"));
@@ -240,6 +254,7 @@ bool asst::InfrastSkillsImageAnalyzer::skill_analyze()
bool asst::InfrastSkillsImageAnalyzer::selected_analyze(int smiley_x, int smiley_y)
{
LogTraceFunction;
const auto selected_task_ptr = std::dynamic_pointer_cast<MatchTaskInfo>(
resource.task().task_ptr("InfrastOperSelected"));
cv::Rect selected_rect = utils::make_rect<cv::Rect>(selected_task_ptr->rect_move);