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

This commit is contained in:
MistEO
2021-11-05 00:31:48 +08:00
parent d0412306e6
commit 33e2556a56
12 changed files with 93 additions and 16 deletions

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;