From fe6b58c14072c2b1c6236c7a1ad2dbb72dfac311 Mon Sep 17 00:00:00 2001 From: eiiko6 Date: Sun, 12 Apr 2026 10:57:27 +0200 Subject: [PATCH] added report count per os chart --- Cargo.toml | 2 +- src/handlers.rs | 12 ++++++++++++ templates/analytics.html | 29 +++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4f852fc..63486c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "slimes-website" -version = "0.1.1" +version = "0.1.2" edition = "2024" [dependencies] diff --git a/src/handlers.rs b/src/handlers.rs index 1ad3981..ce6b8b8 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -275,6 +275,8 @@ pub struct AnalyticsData { pub os_max_scores: Vec, pub os_min_labels: Vec, pub os_min_scores: Vec, + pub os_count_labels: Vec, + pub os_count_values: Vec, pub dist_labels: Vec, pub dist_counts: Vec, pub avg_score_per_gb: f32, @@ -298,6 +300,7 @@ pub async fn analytics_handler( entry.1 += 1; } let mut os_stats: Vec<(String, u64)> = os_map + .clone() .into_iter() .map(|(os, (sum, count))| (os, sum / count as u64)) .collect(); @@ -330,6 +333,13 @@ pub async fn analytics_handler( let mut os_min_stats: Vec<(String, u64)> = os_min_map.into_iter().collect(); os_min_stats.sort_by(|a, b| b.1.cmp(&a.1)); + // Count of each OS + let mut os_counts: Vec<(String, u32)> = os_map + .iter() + .map(|(os, (_, count))| (os.clone(), *count)) + .collect(); + os_counts.sort_by(|a, b| b.1.cmp(&a.1)); + // Score distribution let min_score = reports.iter().map(|r| r.score).min().unwrap_or(0); let max_score = reports.iter().map(|r| r.score).max().unwrap_or(0); @@ -376,6 +386,8 @@ pub async fn analytics_handler( os_max_scores: os_max_stats.iter().map(|x| x.1).collect(), os_min_labels: os_min_stats.iter().map(|x| x.0.clone()).collect(), os_min_scores: os_min_stats.iter().map(|x| x.1).collect(), + os_count_labels: os_counts.iter().map(|x| x.0.clone()).collect(), + os_count_values: os_counts.iter().map(|x| x.1).collect(), dist_labels, dist_counts, avg_score_per_gb, diff --git a/templates/analytics.html b/templates/analytics.html index ea1a2d0..8f8b398 100644 --- a/templates/analytics.html +++ b/templates/analytics.html @@ -23,6 +23,11 @@ +
+

Reports by Operating System

+ +
+

Avg Score by Operating System

@@ -55,6 +60,30 @@ } }; + // OS Distribution (Count) + new Chart(document.getElementById('osCountChart'), { + type: 'bar', + data: { + labels: analyticsData.os_count_labels, + datasets: [{ + label: 'Number of Reports', + data: analyticsData.os_count_values, + backgroundColor: primaryColor, + borderRadius: 6 + }] + }, + options: { + ...chartOptions, + indexAxis: 'y', + scales: { + x: { + ticks: { stepSize: 1 }, + beginAtZero: true + } + } + } + }); + // Average per OS new Chart(document.getElementById('osChart'), { type: 'bar',