added report count per os chart
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "slimes-website"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -275,6 +275,8 @@ pub struct AnalyticsData {
|
||||
pub os_max_scores: Vec<u64>,
|
||||
pub os_min_labels: Vec<String>,
|
||||
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_counts: Vec<u32>,
|
||||
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,
|
||||
|
||||
@@ -23,6 +23,11 @@
|
||||
<canvas id="distChart"></canvas>
|
||||
</div>
|
||||
|
||||
<div class="chart-card">
|
||||
<h3>Reports by Operating System</h3>
|
||||
<canvas id="osCountChart"></canvas>
|
||||
</div>
|
||||
|
||||
<div class="chart-card">
|
||||
<h3>Avg Score by Operating System</h3>
|
||||
<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
|
||||
new Chart(document.getElementById('osChart'), {
|
||||
type: 'bar',
|
||||
|
||||
Reference in New Issue
Block a user