Skip to content

Commit

Permalink
Merge pull request #226 from TurtIeSocks/worst-stats
Browse files Browse the repository at this point in the history
feat: log worst clusters in stats
  • Loading branch information
TurtIeSocks authored Jul 3, 2024
2 parents a072938 + 4e1ccc3 commit 679b8de
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 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,23 +206,36 @@ 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 {
let length = cluster.all.len();
if length > best {
best_clusters.clear();
best = cluster.all.len();
best = length;
best_clusters.push(cluster.point.center);
} else if cluster.all.len() == best {
} else if length == best {
best_clusters.push(cluster.point.center);
} else if length < worst {
worst = length;
worst_count = 1;
} else if length == 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 679b8de

Please sign in to comment.