Skip to content

Commit

Permalink
refactor: move fake info log to its own fn
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Oct 23, 2023
1 parent 7a693f9 commit 058f3e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
17 changes: 8 additions & 9 deletions server/algorithms/src/clustering/greedy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use colored::Colorize;
use hashbrown::HashSet;
use model::api::{cluster_mode::ClusterMode, single_vec::SingleVec, GetBbox, Precision};

Expand All @@ -13,6 +12,7 @@ use crate::{
clustering::rtree::{cluster::Cluster, point::Point},
rtree::{self, point::ToPoint},
s2,
utils::info_log,
};

pub struct Greedy {
Expand Down Expand Up @@ -304,14 +304,13 @@ impl<'a> Greedy {
if highest >= self.min_points {
stdout
.write(
format!(
"\r{}{}Z {} algorithms::clustering::greedy{} Progress: {:.2}% | Clusters: {}",
"[".black(),
chrono::Local::now().format("%Y-%m-%dT%H:%M:%S"),
"INFO".green(),
"]".black(),
(current_iteration as f32 / total_iterations as f32) * 100.
, new_clusters.len()
info_log(
"algorithms::clustering::greedy",
format!(
"Progress: {:.2}% | Clusters: {}",
(current_iteration as f32 / total_iterations as f32) * 100.,
new_clusters.len()
),
)
.as_bytes(),
)
Expand Down
13 changes: 13 additions & 0 deletions server/algorithms/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::fmt::Debug;
use std::fs::{create_dir_all, File};
use std::io::{Result, Write};

use colored::Colorize;
use model::api::{point_array::PointArray, single_vec::SingleVec};

pub fn debug_hashmap<T, U>(file_name: &str, input: &T) -> Result<()>
Expand Down Expand Up @@ -67,3 +68,15 @@ pub fn centroid(coords: &SingleVec) -> PointArray {

[lat.to_degrees(), lon.to_degrees()]
}

pub fn info_log(file_name: &str, message: String) -> String {
format!(
"\r{}{}Z {} {}{} {}",
"[".black(),
chrono::Local::now().format("%Y-%m-%dT%H:%M:%S"),
"INFO".green(),
file_name,
"]".black(),
message
)
}

0 comments on commit 058f3e2

Please sign in to comment.