From 213c1e9283ceb7ecb605c9ffe03301c956f77a07 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Tue, 28 Oct 2025 14:36:35 -0400 Subject: [PATCH] xa clean --- .../src/requests/index_page/signature/mod.rs | 3 +- .../index_page/signature/signature_xa.rs | 69 +++++++++++++++++++ .../index_page/signature/signature_xs.rs | 3 +- 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 crates/api_clients/grok_client/src/requests/index_page/signature/signature_xa.rs diff --git a/crates/api_clients/grok_client/src/requests/index_page/signature/mod.rs b/crates/api_clients/grok_client/src/requests/index_page/signature/mod.rs index 090061232a..3bf0f825c7 100644 --- a/crates/api_clients/grok_client/src/requests/index_page/signature/mod.rs +++ b/crates/api_clients/grok_client/src/requests/index_page/signature/mod.rs @@ -1,2 +1,3 @@ pub mod signature_xs; -pub mod generate_sign_for_new_conversation; \ No newline at end of file +pub mod generate_sign_for_new_conversation; +mod signature_xa; \ No newline at end of file diff --git a/crates/api_clients/grok_client/src/requests/index_page/signature/signature_xa.rs b/crates/api_clients/grok_client/src/requests/index_page/signature/signature_xa.rs new file mode 100644 index 0000000000..60f2a075f6 --- /dev/null +++ b/crates/api_clients/grok_client/src/requests/index_page/signature/signature_xa.rs @@ -0,0 +1,69 @@ +use once_cell::sync::Lazy; +use regex::Regex; +use crate::error::grok_client_error::GrokClientError; + +static CLEAN_NON_DIGIT_REGEX : Lazy = Lazy::new(|| { + Regex::new(r#"[^\d]+"#) + .expect("Regex should parse") +}); + +/* + @staticmethod + def xa(svg: str) -> List[List[int]]: + s = (svg) + substr = s[9:] + parts = substr.split("C") + out = [] + for part in parts: + cleaned = sub(r"[^\d]+", " ", part).strip() + if cleaned == "": + nums = [0] + else: + nums = [int(tok) for tok in cleaned.split() if tok != ""] + out.append(nums) + return out + */ + +/// Based on "Grok-Api/core/xctid.py" +/// `svg_data` is the svg path stroke data +pub fn signature_xa(svg_data: &str) -> Result>, GrokClientError> { + // s = (svg) -- not this is needed, looks like a NO-OP to me. + let s = svg_data; + println!("s.len() ={}", s.len()); + + // substr = s[9:] + let substr = &s[9..]; + println!("Substr ={}", substr); + println!("substr.len() ={}", substr.len()); + + // parts = substr.split("C") + let parts = substr.split("C").collect::>(); + println!("parts.len() = {}", parts.len()); + println!("parts = {:?}", parts); + + let mut out = Vec::new(); + + for part in parts { + // cleaned = sub(r"[^\d]+", " ", part).strip() + let cleaned = CLEAN_NON_DIGIT_REGEX.replace_all(part, " ").to_string().trim().to_string(); + println!("cleaned len = {} value = {}", cleaned.len(), cleaned); + + + } + + Ok(out) +} + +#[cfg(test)] +mod tests { + use crate::requests::index_page::signature::signature_xa::signature_xa; + + #[test] + fn test() { + let svg_data = "M 10,30 C 147,16 51,222 136,87 h 31 s 177,77 40,114 C 68,166 18,188 114,44 h 220 s 148,210 202,25 C 220,36 246,218 12,120 h 244 s 34,154 56,161 C 211,204 208,60 174,14 h 155 s 157,116 220,95 C 116,164 53,210 174,232 h 139 s 148,151 135,221 C 167,196 118,27 149,247 h 233 s 129,238 113,21 C 73,44 215,158 218,29 h 68 s 13,98 243,134 C 44,98 149,35 20,178 h 163 s 219,104 41,152 C 237,107 118,120 127,117 h 57 s 41,167 43,136 C 116,168 44,246 182,209 h 143 s 238,93 237,119 C 142,36 64,67 97,111 h 71 s 230,247 119,27 C 206,56 158,51 71,115 h 135 s 120,186 74,57 C 197,165 180,214 102,16 h 88 s 252,48 189,166 C 163,237 57,253 154,60 h 96 s 84,56 15,66 C 177,101 10,202 185,227 h 29 s 204,55 115,219 C 103,82 127,143 194,99 h 102 s 179,63 84,110"; + + signature_xa(&svg_data).unwrap(); + + assert_eq!(1,2); + } +} diff --git a/crates/api_clients/grok_client/src/requests/index_page/signature/signature_xs.rs b/crates/api_clients/grok_client/src/requests/index_page/signature/signature_xs.rs index 5a45dad3c2..b038520c29 100644 --- a/crates/api_clients/grok_client/src/requests/index_page/signature/signature_xs.rs +++ b/crates/api_clients/grok_client/src/requests/index_page/signature/signature_xs.rs @@ -22,6 +22,7 @@ use crate::error::grok_client_error::GrokClientError; return cleaned */ +/// Based on "Grok-Api/core/xctid.py" /// `bytes` is /// `svg_data` is the svg path stroke data /// `x_values` are the magic numbers from the script @@ -87,4 +88,4 @@ mod tests { assert_eq!(1,2); } -} \ No newline at end of file +}