diff options
author | gennyble <gen@nyble.dev> | 2025-03-29 05:47:11 -0500 |
---|---|---|
committer | gennyble <gen@nyble.dev> | 2025-03-29 05:47:11 -0500 |
commit | 23f494f065be5eaec37aab6ca6e72348c6a025e0 (patch) | |
tree | 3ff9f0e54260f945005e33d4203647f34fa2fa4a | |
parent | b8d65256e1e9ed48ea6032905fef06b3ff5cc899 (diff) | |
download | corgi-23f494f065be5eaec37aab6ca6e72348c6a025e0.tar.gz corgi-23f494f065be5eaec37aab6ca6e72348c6a025e0.zip |
highest ten, add percent of highest
-rw-r--r-- | stats_module/src/lib.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/stats_module/src/lib.rs b/stats_module/src/lib.rs index 5f026fb..2c1bce0 100644 --- a/stats_module/src/lib.rs +++ b/stats_module/src/lib.rs @@ -34,13 +34,14 @@ extern "C" fn cgi_handle(req: *const ModuleRequest) -> *const ModuleResponse { let highest_five_query = "SELECT count(requests.id) AS request_count, agents.agent FROM requests \ INNER JOIN agents ON requests.agent_id = agents.id \ GROUP BY requests.agent_id \ - ORDER BY request_count DESC LIMIT 5;"; + ORDER BY request_count DESC LIMIT 10;"; let mut prepared = db.prepare(highest_five_query).unwrap(); let highest_five: Vec<(usize, String)> = prepared .query_map(params![], |row| Ok((row.get(0)?, row.get(1)?))) .unwrap() .map(|r| r.unwrap()) .collect(); + let sum_highest_five = highest_five.iter().fold(0, |acc, (count, _)| acc + count); body.push_str("<p>In the last fifteen minutes:<br/><code><pre>"); body.push_str("total | req/m | agent\n"); @@ -52,10 +53,13 @@ extern "C" fn cgi_handle(req: *const ModuleRequest) -> *const ModuleResponse { } body.push_str("</pre></code></p>"); - body.push_str("<p>Highest five all time requests:<br/><code><pre>"); - body.push_str(" total | agent\n"); + body.push_str("<p>Highest ten all time requesters:<br/><code><pre>"); + body.push_str(" total | %of10 | agent\n"); for (count, agent) in highest_five { - body.push_str(&format!(" {count:<7} | {agent}\n")); + body.push_str(&format!( + " {count:<7} | {:<5.1} | {agent}\n", + (count as f32 / sum_highest_five as f32) * 100.0 + )); } body.push_str("</pre></code></p>"); |