added report count per os chart

This commit is contained in:
2026-04-12 10:57:27 +02:00
parent 0ec29a70c3
commit fe6b58c140
3 changed files with 42 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "slimes-website" name = "slimes-website"
version = "0.1.1" version = "0.1.2"
edition = "2024" edition = "2024"
[dependencies] [dependencies]

View File

@@ -275,6 +275,8 @@ pub struct AnalyticsData {
pub os_max_scores: Vec<u64>, pub os_max_scores: Vec<u64>,
pub os_min_labels: Vec<String>, pub os_min_labels: Vec<String>,
pub os_min_scores: Vec<u64>, pub os_min_scores: Vec<u64>,
pub os_count_labels: Vec<String>,
pub os_count_values: Vec<u32>,
pub dist_labels: Vec<String>, pub dist_labels: Vec<String>,
pub dist_counts: Vec<u32>, pub dist_counts: Vec<u32>,
pub avg_score_per_gb: f32, pub avg_score_per_gb: f32,
@@ -298,6 +300,7 @@ pub async fn analytics_handler(
entry.1 += 1; entry.1 += 1;
} }
let mut os_stats: Vec<(String, u64)> = os_map let mut os_stats: Vec<(String, u64)> = os_map
.clone()
.into_iter() .into_iter()
.map(|(os, (sum, count))| (os, sum / count as u64)) .map(|(os, (sum, count))| (os, sum / count as u64))
.collect(); .collect();
@@ -330,6 +333,13 @@ pub async fn analytics_handler(
let mut os_min_stats: Vec<(String, u64)> = os_min_map.into_iter().collect(); 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)); 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 // Score distribution
let min_score = reports.iter().map(|r| r.score).min().unwrap_or(0); 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); 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_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_labels: os_min_stats.iter().map(|x| x.0.clone()).collect(),
os_min_scores: os_min_stats.iter().map(|x| x.1).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_labels,
dist_counts, dist_counts,
avg_score_per_gb, avg_score_per_gb,

View File

@@ -23,6 +23,11 @@
<canvas id="distChart"></canvas> <canvas id="distChart"></canvas>
</div> </div>
<div class="chart-card">
<h3>Reports by Operating System</h3>
<canvas id="osCountChart"></canvas>
</div>
<div class="chart-card"> <div class="chart-card">
<h3>Avg Score by Operating System</h3> <h3>Avg Score by Operating System</h3>
<canvas id="osChart"></canvas> <canvas id="osChart"></canvas>
@@ -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 // Average per OS
new Chart(document.getElementById('osChart'), { new Chart(document.getElementById('osChart'), {
type: 'bar', type: 'bar',