fix latency sort

This commit is contained in:
arm64v8a
2023-03-01 21:44:23 +09:00
parent dd18441b8a
commit 1f4263acd1
3 changed files with 19 additions and 9 deletions

View File

@@ -55,6 +55,7 @@ namespace NekoRay::fmt {
QJsonObject outbound; QJsonObject outbound;
outbound["type"] = socks_http_type == type_HTTP ? "http" : "socks"; outbound["type"] = socks_http_type == type_HTTP ? "http" : "socks";
if (socks_http_type == type_Socks4) outbound["version"] = "4";
outbound["server"] = serverAddress; outbound["server"] = serverAddress;
outbound["server_port"] = serverPort; outbound["server_port"] = serverPort;

View File

@@ -850,12 +850,16 @@ void MainWindow::refresh_proxy_list_impl(const int &id, NekoRay::GroupSortAction
ms_a = NekoRay::profileManager->GetProfile(a)->full_test_report; ms_a = NekoRay::profileManager->GetProfile(a)->full_test_report;
ms_b = NekoRay::profileManager->GetProfile(b)->full_test_report; ms_b = NekoRay::profileManager->GetProfile(b)->full_test_report;
} }
auto get_latency_for_sort = [](int id) {
auto i = NekoRay::profileManager->GetProfile(id)->latency;
if (i < 0) i = 99999;
return i;
};
if (groupSortAction.descending) { if (groupSortAction.descending) {
if (groupSortAction.method == NekoRay::GroupSortMethod::ByLatency) { if (groupSortAction.method == NekoRay::GroupSortMethod::ByLatency) {
auto int_a = NekoRay::profileManager->GetProfile(a)->latency; if (ms_a.isEmpty() && ms_b.isEmpty()) {
auto int_b = NekoRay::profileManager->GetProfile(b)->latency; // compare latency if full_test_report is empty
if (int_a > 0 && int_b > 0) { return get_latency_for_sort(a) > get_latency_for_sort(b);
return int_a > int_b;
} }
} }
return ms_a > ms_b; return ms_a > ms_b;
@@ -863,8 +867,9 @@ void MainWindow::refresh_proxy_list_impl(const int &id, NekoRay::GroupSortAction
if (groupSortAction.method == NekoRay::GroupSortMethod::ByLatency) { if (groupSortAction.method == NekoRay::GroupSortMethod::ByLatency) {
auto int_a = NekoRay::profileManager->GetProfile(a)->latency; auto int_a = NekoRay::profileManager->GetProfile(a)->latency;
auto int_b = NekoRay::profileManager->GetProfile(b)->latency; auto int_b = NekoRay::profileManager->GetProfile(b)->latency;
if (int_a > 0 && int_b > 0) { if (ms_a.isEmpty() && ms_b.isEmpty()) {
return int_a < int_b; // compare latency if full_test_report is empty
return get_latency_for_sort(a) < get_latency_for_sort(b);
} }
} }
return ms_a < ms_b; return ms_a < ms_b;

View File

@@ -126,9 +126,13 @@ void MainWindow::speedtest_current_group(int mode) {
} }
if (!rpcOK) return; if (!rpcOK) return;
profile->latency = result.ms(); if (result.error().empty()) {
if (profile->latency == 0) profile->latency = -1; // sn profile->latency = result.ms();
profile->full_test_report = result.full_report().c_str(); if (profile->latency == 0) profile->latency = 1; // nekoray use 0 to represents not tested
} else {
profile->latency = -1;
}
profile->full_test_report = result.full_report().c_str(); // higher priority
profile->Save(); profile->Save();
if (!result.error().empty()) { if (!result.error().empty()) {