From 8aeb290d0f5034d4eb3a7df380c03d95acdaa062 Mon Sep 17 00:00:00 2001 From: chn Date: Tue, 18 Jun 2024 01:23:00 +0800 Subject: [PATCH] localPackages.hpcstat: sort before export --- local/pkgs/hpcstat/src/sql.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/local/pkgs/hpcstat/src/sql.cpp b/local/pkgs/hpcstat/src/sql.cpp index 3b4d5c02..c8b50950 100644 --- a/local/pkgs/hpcstat/src/sql.cpp +++ b/local/pkgs/hpcstat/src/sql.cpp @@ -262,7 +262,16 @@ namespace hpcstat::sql // export to markdown std::cout << "| 账号 | 使用核时 | 登陆次数(交互式) | 登陆次数(非交互式) | 成功任务数 | 失败任务数 | SSH密钥编号::指纹 |\n"; std::cout << "| :--: | :--: | :--: | :--: | :--: | :--: | :--: |\n"; - for (auto& [key, stat] : stat_account) + std::vector, StatAccount>> stat_account_vector + (stat_account.begin(), stat_account.end()); + auto compare = [](auto& a, auto& b) + { + if (a.first) + { if (b.first) return Keys[*a.first].PubkeyFilename < Keys[*b.first].PubkeyFilename; else return true; } + else return false; + }; + std::sort(stat_account_vector.begin(), stat_account_vector.end(), compare); + for (auto& [key, stat] : stat_account_vector) std::cout << "| {} | {:.2f} | {} | {} | {} | {} | `{}::{}` |\n"_f ( key ? Keys[*key].Username : "(unknown)", stat.CpuTime, stat.LoginInteractive, stat.LoginNonInteractive,