Skip to content

Commit

Permalink
feat: log worst clusters in stats
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Jul 3, 2024
1 parent a072938 commit 31f58ab
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions server/algorithms/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub struct Stats {

pub best_clusters: SingleVec,
pub best_cluster_point_count: usize,
pub worst_cluster_point_count: usize,
pub worst_cluster_count: usize,
pub cluster_time: Precision,
pub route_time: Precision,
pub stats_time: Precision,
Expand All @@ -33,6 +35,8 @@ impl Stats {
Self {
best_clusters: vec![],
best_cluster_point_count: 0,
worst_cluster_point_count: 0,
worst_cluster_count: 0,
cluster_time: 0.,
route_time: 0.,
stats_time: 0.,
Expand Down Expand Up @@ -106,9 +110,11 @@ impl Stats {
),
get_row(
format!(
"|| [BEST_CLUSTER] Amount: {:?} | Point Count: {}",
self.best_clusters.len(),
"|| [COVERAGE] Best: {} ({}) | Worst: {} ({})",
self.best_cluster_point_count,
self.best_clusters.len(),
self.worst_cluster_point_count,
self.worst_cluster_count,
),
true
),
Expand Down Expand Up @@ -200,7 +206,9 @@ impl Stats {
let clusters: Vec<Cluster<'_>> = cluster_info(&tree, &clusters);
let mut points_covered: HashSet<&point::Point> = HashSet::new();
let mut best_clusters = SingleVec::new();
let mut best = 0;
let mut best = usize::MIN;
let mut worst = usize::MAX;
let mut worst_count = 0;

for cluster in clusters.iter() {
if cluster.all.len() > best {
Expand All @@ -210,13 +218,24 @@ impl Stats {
} else if cluster.all.len() == best {
best_clusters.push(cluster.point.center);
}
if cluster.all.len() < worst {
worst = cluster.all.len();
worst_count = 1;
} else if cluster.all.len() == worst {
worst_count += 1;
}
if let Some(point) = tree.locate_at_point(&cluster.point.center) {
points_covered.insert(point);
}
points_covered.extend(&cluster.all);
}
if worst == usize::MAX {
worst = 0;
}

self.best_cluster_point_count = best;
self.worst_cluster_point_count = worst;
self.worst_cluster_count = worst_count;
self.best_clusters = best_clusters;
self.points_covered = points_covered.len();

Expand Down Expand Up @@ -244,6 +263,7 @@ impl Serialize for Stats {
let mut state = serializer.serialize_struct("Stats", 11)?;
state.serialize_field("best_clusters", &self.best_clusters)?;
state.serialize_field("best_cluster_point_count", &self.best_cluster_point_count)?;
state.serialize_field("worst_cluster_point_count", &self.worst_cluster_point_count)?;
state.serialize_field("cluster_time", &self.cluster_time)?;
state.serialize_field("route_time", &self.route_time)?;
state.serialize_field("stats_time", &self.stats_time)?;
Expand Down

0 comments on commit 31f58ab

Please sign in to comment.