mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-19 18:47:55 +08:00
feat.完成企鹅物流上传功能
This commit is contained in:
@@ -9,8 +9,10 @@
|
||||
"taskDelay_Doc": "识别的延迟:越快识别频率越快,但会增加CPU消耗。单位毫秒,默认1000",
|
||||
"printWindow": true,
|
||||
"printWindow_Doc": "截图功能:开启后每次结算界面会截图到screenshot目录下。true-开启,false-关闭,默认true",
|
||||
"printWindowDelay": 3000,
|
||||
"printWindowDelay_Doc": "截图延时:每次到结算界面,掉落物品不是一次性出来的,有个动画,所以需要等一会再截图。单位毫秒,默认3000,仅在printWindow为true时生效",
|
||||
"uploadToPenguin": true,
|
||||
"uploadToPenguin_Doc": "上传企鹅物流https://penguin-stats.cn/:每次到结算界面,是否上传企鹅物流数据统计网站。true-开启,false-关闭,默认true",
|
||||
"penguinApi": "https://penguin-stats.io/PenguinStats/api/v2/report",
|
||||
"penguinApi_Doc": "企鹅物流汇报接口",
|
||||
"controlDelayRange": [
|
||||
0,
|
||||
0
|
||||
|
||||
@@ -105,7 +105,7 @@
|
||||
"text": [
|
||||
"行动结束"
|
||||
],
|
||||
"preDelay": 3000,
|
||||
"preDelay": 5000,
|
||||
"action": "printWindow",
|
||||
"next": [
|
||||
"ClickCorner"
|
||||
|
||||
@@ -59,22 +59,13 @@ bool AbstractTask::sleep(unsigned millisecond)
|
||||
return !need_exit();
|
||||
}
|
||||
|
||||
bool AbstractTask::print_window(const std::string& dir, bool raw)
|
||||
bool AbstractTask::save_image(const cv::Mat& image, const std::string& dir)
|
||||
{
|
||||
//const cv::Mat& image = m_controller_ptr->get_image(true);
|
||||
//if (image.empty()) {
|
||||
// return false;
|
||||
//}
|
||||
// 现在用adb直接截图了,不用裁剪了
|
||||
//// 保存的截图额外再裁剪掉一圈,不然企鹅物流识别不出来
|
||||
//int offset = Configer::get_instance().m_options.print_window_crop_offset;
|
||||
//cv::Rect rect(offset, offset, image.cols - offset * 2, image.rows - offset * 2);
|
||||
|
||||
std::filesystem::create_directory(dir);
|
||||
const std::string time_str = StringReplaceAll(StringReplaceAll(GetFormatTimeString(), " ", "_"), ":", "-");
|
||||
const std::string filename = dir + time_str + ".png";
|
||||
|
||||
bool ret = cv::imwrite(filename, m_controller_ptr->get_image(raw));
|
||||
bool ret = cv::imwrite(filename, image);
|
||||
|
||||
json::value callback_json;
|
||||
callback_json["filename"] = filename;
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace asst {
|
||||
virtual void on_run_fails(int retry_times) { ; }
|
||||
protected:
|
||||
virtual bool sleep(unsigned millisecond);
|
||||
virtual bool print_window(const std::string& dir, bool raw = true);
|
||||
virtual bool save_image(const cv::Mat& iamge, const std::string& dir);
|
||||
virtual bool need_exit() const noexcept;
|
||||
virtual bool is_ptr_inited() const noexcept;
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ Assistance::Assistance(AsstCallback callback, void* callback_arg)
|
||||
}
|
||||
|
||||
/* 第三方库`penguin-stats-recognize`(企鹅物流掉落识别)所需资源*/
|
||||
m_identify_ptr->penguin_load_server("CN");
|
||||
m_identify_ptr->penguin_load_server(Configer::get_instance().m_options.penguin_server);
|
||||
m_identify_ptr->penguin_load_json(GetResourceDir() + "penguin-stats-recognize\\json\\stages.json", GetResourceDir() + "penguin-stats-recognize\\json\\hash_index.json");
|
||||
|
||||
for (const auto& file : std::filesystem::directory_iterator(GetResourceDir() + "penguin-stats-recognize\\items")) {
|
||||
|
||||
@@ -191,7 +191,9 @@ namespace asst {
|
||||
int control_delay_lower = 0; // 点击随机延时下限:每次点击操作会进行随机延时
|
||||
int control_delay_upper = 0; // 点击随机延时上限:每次点击操作会进行随机延时
|
||||
bool print_window = false; // 截图功能:开启后每次结算界面会截图到screenshot目录下
|
||||
int print_window_delay = 0; // 截图延时:每次到结算界面,掉落物品不是一次性出来的,有个动画,所以需要等一会再截图
|
||||
bool upload_to_penguin = false; // 上传企鹅物流:每次到结算界面,是否上传企鹅物流数据统计网站 https://penguin-stats.cn/
|
||||
std::string penguin_api; // 企鹅物流汇报接口
|
||||
std::string penguin_server; // 企鹅物流汇报接口"server"字段,"CN", "US", "JP" and "KR".
|
||||
int ocr_gpu_index = -1; // OcrLite使用GPU编号,-1(使用CPU)/0(使用GPU0)/1(使用GPU1)/...
|
||||
int ocr_thread_number = 0; // OcrLite线程数量
|
||||
};
|
||||
|
||||
@@ -23,7 +23,9 @@ bool asst::Configer::parse(const json::value& json)
|
||||
m_options.control_delay_lower = options_json.at("controlDelayRange")[0].as_integer();
|
||||
m_options.control_delay_upper = options_json.at("controlDelayRange")[1].as_integer();
|
||||
m_options.print_window = options_json.at("printWindow").as_boolean();
|
||||
m_options.print_window_delay = options_json.at("printWindowDelay").as_integer();
|
||||
m_options.upload_to_penguin = options_json.at("uploadToPenguin").as_boolean();
|
||||
m_options.penguin_api = options_json.at("penguinApi").as_string();
|
||||
m_options.penguin_server = options_json.get("penguinServer", "CN");
|
||||
m_options.ocr_thread_number = options_json.at("ocrThreadNumber").as_integer();
|
||||
}
|
||||
DebugTrace("Options", options_json.to_string());
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace penguin {
|
||||
|
||||
#include "Logger.hpp"
|
||||
#include "AsstAux.h"
|
||||
#include "Configer.h"
|
||||
|
||||
using namespace asst;
|
||||
using namespace cv;
|
||||
@@ -256,7 +257,6 @@ std::vector<TextArea> asst::Identify::find_text(const cv::Mat& image, const std:
|
||||
|
||||
bool asst::Identify::penguin_load_server(const std::string& server)
|
||||
{
|
||||
m_penguin_server = server;
|
||||
penguin::load_server(server.c_str());
|
||||
return true;
|
||||
}
|
||||
@@ -300,7 +300,7 @@ bool asst::Identify::penguin_load_json(const std::string& stage_path, const std:
|
||||
}
|
||||
}
|
||||
stage_dst["drops"] = json::array(std::move(drops_vector));
|
||||
std::string server = m_penguin_server.empty() ? "CN" : m_penguin_server;
|
||||
const std::string& server = Configer::get_instance().m_options.penguin_server;
|
||||
stage_dst["existence"] = stage_info.at("existence").at(server).at("exist");
|
||||
|
||||
cvt_stage_json.emplace(std::move(key), std::move(stage_dst));
|
||||
|
||||
@@ -67,8 +67,6 @@ namespace asst {
|
||||
std::unordered_map<std::string, cv::Mat> m_mat_map;
|
||||
std::unordered_map<std::string, std::pair<cv::Rect, cv::Mat>> m_cache_map; // 位置、直方图缓存
|
||||
|
||||
std::string m_penguin_server;
|
||||
|
||||
OcrLiteCaller m_ocr_lite;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
<ClInclude Include="Logger.hpp" />
|
||||
<ClInclude Include="OcrAbstractTask.h" />
|
||||
<ClInclude Include="OpenRecruitTask.h" />
|
||||
<ClInclude Include="PenguinUploader.h" />
|
||||
<ClInclude Include="ProcessTask.h" />
|
||||
<ClInclude Include="RecruitConfiger.h" />
|
||||
<ClInclude Include="ScreenCaptureTask.h" />
|
||||
@@ -58,6 +59,7 @@
|
||||
<ClCompile Include="InfrastProductionTask.cpp" />
|
||||
<ClCompile Include="OcrAbstractTask.cpp" />
|
||||
<ClCompile Include="OpenRecruitTask.cpp" />
|
||||
<ClCompile Include="PenguinUploader.cpp" />
|
||||
<ClCompile Include="ProcessTask.cpp" />
|
||||
<ClCompile Include="RecruitConfiger.cpp" />
|
||||
<ClCompile Include="ScreenCaptureTask.cpp" />
|
||||
|
||||
@@ -22,9 +22,6 @@
|
||||
<Filter Include="源文件\Configer">
|
||||
<UniqueIdentifier>{74bd94e1-4973-412a-a17a-d8457de387af}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="头文件\Aux">
|
||||
<UniqueIdentifier>{87c9dee5-847b-41e6-818e-387a6385ea8b}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="头文件\Task">
|
||||
<UniqueIdentifier>{3b93d9f2-728c-4a22-bc13-57ce7df5806c}</UniqueIdentifier>
|
||||
</Filter>
|
||||
@@ -34,6 +31,12 @@
|
||||
<Filter Include="源文件\Caller">
|
||||
<UniqueIdentifier>{557d6d96-11d9-46e1-b611-b2b8216abea6}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="源文件\utils">
|
||||
<UniqueIdentifier>{a5c43813-70af-4b0e-94ac-9ddecc2e4a3c}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="头文件\utils">
|
||||
<UniqueIdentifier>{87c9dee5-847b-41e6-818e-387a6385ea8b}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Identify.h">
|
||||
@@ -55,16 +58,16 @@
|
||||
<Filter>头文件\Configer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="AsstDef.h">
|
||||
<Filter>头文件\Aux</Filter>
|
||||
<Filter>头文件\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="AsstAux.h">
|
||||
<Filter>头文件\Aux</Filter>
|
||||
<Filter>头文件\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Version.h">
|
||||
<Filter>头文件\Aux</Filter>
|
||||
<Filter>头文件\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Logger.hpp">
|
||||
<Filter>头文件\Aux</Filter>
|
||||
<Filter>头文件\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\AsstCaller.h">
|
||||
<Filter>头文件\Caller</Filter>
|
||||
@@ -88,7 +91,7 @@
|
||||
<Filter>头文件\Task</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="AsstMsg.h">
|
||||
<Filter>头文件\Aux</Filter>
|
||||
<Filter>头文件\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Task.h">
|
||||
<Filter>头文件\Task</Filter>
|
||||
@@ -123,6 +126,9 @@
|
||||
<ClInclude Include="CreditShoppingTask.h">
|
||||
<Filter>头文件\Task</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="PenguinUploader.h">
|
||||
<Filter>头文件\utils</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="WinMacro.cpp">
|
||||
@@ -191,5 +197,8 @@
|
||||
<ClCompile Include="CreditShoppingTask.cpp">
|
||||
<Filter>源文件\Task</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="PenguinUploader.cpp">
|
||||
<Filter>源文件\utils</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
44
src/MeoAssistance/PenguinUploader.cpp
Normal file
44
src/MeoAssistance/PenguinUploader.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "PenguinUploader.h"
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#include <json.h>
|
||||
|
||||
#include "Configer.h"
|
||||
#include "Version.h"
|
||||
#include "Logger.hpp"
|
||||
|
||||
bool asst::PenguinUploader::upload(const std::string& rec_res)
|
||||
{
|
||||
std::string body = cvt_json(rec_res);
|
||||
return request_penguin(body);
|
||||
}
|
||||
|
||||
std::string asst::PenguinUploader::cvt_json(const std::string& rec_res)
|
||||
{
|
||||
auto parse_ret = json::parse(rec_res);
|
||||
if (!parse_ret) {
|
||||
return std::string();
|
||||
}
|
||||
json::value rec = std::move(parse_ret.value());
|
||||
|
||||
// Doc: https://developer.penguin-stats.io/public-api/api-v2-instruction/report-api
|
||||
json::value body;
|
||||
body["server"] = Configer::get_instance().m_options.penguin_server;
|
||||
body["stageId"] = rec["stage"]["stageId"];
|
||||
body["drops"] = rec["drops"];
|
||||
body["source"] = "MeoAssistance";
|
||||
body["version"] = Version;
|
||||
|
||||
return body.to_string();
|
||||
}
|
||||
|
||||
bool asst::PenguinUploader::request_penguin(const std::string& body)
|
||||
{
|
||||
std::string curl_cmd = R"(curl -H "Content-Type: application/json" -X POST -d )";
|
||||
curl_cmd += '\'' + body + "' \"" + Configer::get_instance().m_options.penguin_api + '"';
|
||||
|
||||
DebugTrace("request_penguin |", curl_cmd);
|
||||
|
||||
return !system(curl_cmd.c_str());
|
||||
}
|
||||
18
src/MeoAssistance/PenguinUploader.h
Normal file
18
src/MeoAssistance/PenguinUploader.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace json {
|
||||
class value;
|
||||
}
|
||||
|
||||
namespace asst {
|
||||
class PenguinUploader
|
||||
{
|
||||
public:
|
||||
static bool upload(const std::string& rec_res);
|
||||
private:
|
||||
static std::string cvt_json(const std::string& rec_res);
|
||||
static bool request_penguin(const std::string& body);
|
||||
};
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "TaskConfiger.h"
|
||||
#include "WinMacro.h"
|
||||
#include "Identify.h"
|
||||
#include "PenguinUploader.h"
|
||||
|
||||
using namespace asst;
|
||||
|
||||
@@ -91,10 +92,18 @@ bool ProcessTask::run()
|
||||
need_stop = true;
|
||||
break;
|
||||
case ProcessTaskAction::PrintWindow:
|
||||
if (Configer::get_instance().m_options.print_window) {
|
||||
sleep(Configer::get_instance().m_options.print_window_delay);
|
||||
static const std::string dirname = GetCurrentDir() + "screenshot\\";
|
||||
print_window(dirname);
|
||||
if (Configer::get_instance().m_options.print_window
|
||||
|| Configer::get_instance().m_options.upload_to_penguin)
|
||||
{
|
||||
cv::Mat image = m_controller_ptr->get_image(true);
|
||||
if (Configer::get_instance().m_options.print_window) {
|
||||
static const std::string dirname = GetCurrentDir() + "screenshot\\";
|
||||
save_image(image, dirname);
|
||||
}
|
||||
if (Configer::get_instance().m_options.upload_to_penguin) {
|
||||
std::string res = m_identify_ptr->penguin_recognize(image);
|
||||
PenguinUploader::upload(res);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -18,5 +18,5 @@ bool asst::ScreenCaptureTask::run()
|
||||
auto res = m_identify_ptr->penguin_recognize(image);
|
||||
|
||||
static const std::string dirname = GetCurrentDir() + "template\\";
|
||||
return print_window(dirname, false);
|
||||
return save_image(image, dirname);
|
||||
}
|
||||
Reference in New Issue
Block a user