-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(metrics): Add normalization and update set metrics hashing
- Loading branch information
Elias Ram
committed
May 23, 2024
1 parent
8c701e8
commit 5f41028
Showing
9 changed files
with
1,335 additions
and
88 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod normalized_name; | ||
pub mod normalized_tags; | ||
pub mod normalized_unit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use regex::Regex; | ||
use std::borrow::Cow; | ||
|
||
pub struct NormalizedName<'a> { | ||
name: Cow<'a, str>, | ||
} | ||
|
||
impl<'a> From<&'a str> for NormalizedName<'a> { | ||
fn from(name: &'a str) -> Self { | ||
Self { | ||
name: Regex::new(r"[^a-zA-Z0-9_\-.]") | ||
.expect("Regex should compile") | ||
.replace_all(name, "_"), | ||
} | ||
} | ||
} | ||
|
||
impl std::fmt::Display for NormalizedName<'_> { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{}", self.name) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use crate::metrics::NormalizedName; | ||
|
||
#[test] | ||
fn test_from() { | ||
let expected = "aA1_-.____________"; | ||
|
||
let actual = NormalizedName::from("aA1_-./+ö{😀\n\t\r\\| ,").to_string(); | ||
|
||
assert_eq!(expected, actual); | ||
} | ||
} |
Oops, something went wrong.