mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-17 18:01:26 +08:00
fix: fix typo and undefined behavior of minmax
This commit is contained in:
@@ -458,7 +458,7 @@ bool asst::AdbController::screencap(cv::Mat& image_payload, bool allow_reconnect
|
||||
break;
|
||||
}
|
||||
// 记录截图耗时,每10次截图回传一次最值+平均值
|
||||
m_screencap_duration.emplace_back(screencap_ret ? m_last_command_duration : INT_MAX); // 记录截图耗时
|
||||
m_screencap_duration.emplace_back(screencap_ret ? m_last_command_duration : LLONG_MAX); // 记录截图耗时
|
||||
++m_screencap_time;
|
||||
|
||||
if (m_screencap_duration.size() > 30) {
|
||||
@@ -466,23 +466,25 @@ bool asst::AdbController::screencap(cv::Mat& image_payload, bool allow_reconnect
|
||||
}
|
||||
if (m_screencap_time > 9) { // 每 10 次截图计算一次平均耗时
|
||||
m_screencap_time = 0;
|
||||
auto filted_duration = m_screencap_duration | views::filter([](long long num) { return num < INT_MAX; });
|
||||
auto filtered_duration =
|
||||
m_screencap_duration | views::filter([](long long num) { return num < LLONG_MAX; });
|
||||
// 过滤后的有效截图用时次数
|
||||
auto filted_count = m_screencap_duration.size() - ranges::count(m_screencap_duration, INT_MAX);
|
||||
auto [screencap_cost_min, screencap_cost_max] = ranges::minmax(filted_duration);
|
||||
json::value info = json::object {
|
||||
{ "uuid", m_uuid },
|
||||
{ "what", "ScreencapCost" },
|
||||
{ "details",
|
||||
json::object {
|
||||
{ "min", screencap_cost_min },
|
||||
{ "max", screencap_cost_max },
|
||||
{ "avg", filted_count > 0
|
||||
? std::accumulate(filted_duration.begin(), filted_duration.end(), 0ll) / filted_count
|
||||
: -1 },
|
||||
} },
|
||||
};
|
||||
callback(AsstMsg::ConnectionInfo, info);
|
||||
auto filtered_count = m_screencap_duration.size() - ranges::count(m_screencap_duration, LLONG_MAX);
|
||||
if (filtered_count != 0) {
|
||||
auto [screencap_cost_min, screencap_cost_max] = ranges::minmax(filtered_duration);
|
||||
json::value info = json::object {
|
||||
{ "uuid", m_uuid },
|
||||
{ "what", "ScreencapCost" },
|
||||
{ "details",
|
||||
json::object {
|
||||
{ "min", screencap_cost_min },
|
||||
{ "max", screencap_cost_max },
|
||||
{ "avg",
|
||||
std::accumulate(filtered_duration.begin(), filtered_duration.end(), 0LL) / filtered_count },
|
||||
} },
|
||||
};
|
||||
callback(AsstMsg::ConnectionInfo, info);
|
||||
}
|
||||
}
|
||||
return screencap_ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user