Skip to content

Commit 01f2541

Browse files
committed
feat: add optional always-active-pattern to canonical queries
1 parent 78bbad7 commit 01f2541

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

aw-client-rust/src/queries.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
//! },
2626
//! bid_window: "aw-watcher-window_example".to_string(),
2727
//! bid_afk: "aw-watcher-afk_example".to_string(),
28+
//! always_active_pattern: None,
2829
//! };
2930
//!
3031
//! // Automatically fetches classes from localhost:5600
@@ -104,6 +105,8 @@ pub struct DesktopQueryParams {
104105
pub base: QueryParamsBase,
105106
pub bid_window: String,
106107
pub bid_afk: String,
108+
#[serde(default)]
109+
pub always_active_pattern: Option<String>,
107110
}
108111

109112
/// Query parameters specific to Android
@@ -180,11 +183,26 @@ pub fn build_desktop_canonical_events(params: &DesktopQueryParams) -> String {
180183

181184
// Fetch not-afk events
182185
if params.base.filter_afk {
183-
query.push(format!(
186+
let mut not_afk_query = format!(
184187
"not_afk = flood(query_bucket(find_bucket(\"{}\")));
185188
not_afk = filter_keyvals(not_afk, \"status\", [\"not-afk\"])",
186189
escape_doublequote(&params.bid_afk)
187-
));
190+
);
191+
192+
// Add treat_as_active functionality if pattern is provided
193+
if let Some(ref pattern) = params.always_active_pattern {
194+
not_afk_query.push_str(&format!(
195+
";
196+
not_treat_as_afk = filter_keyvals_regex(events, \"app\", \"{}\");
197+
not_afk = period_union(not_afk, not_treat_as_afk);
198+
not_treat_as_afk = filter_keyvals_regex(events, \"title\", \"{}\");
199+
not_afk = period_union(not_afk, not_treat_as_afk)",
200+
escape_doublequote(pattern),
201+
escape_doublequote(pattern)
202+
));
203+
}
204+
205+
query.push(not_afk_query);
188206
}
189207

190208
// Add browser events if any browser buckets specified
@@ -362,6 +380,7 @@ mod tests {
362380
},
363381
bid_window: "aw-watcher-window_".to_string(),
364382
bid_afk: "aw-watcher-afk_".to_string(),
383+
always_active_pattern: None,
365384
};
366385

367386
let query = full_desktop_query(&params);
@@ -414,6 +433,7 @@ mod tests {
414433
},
415434
bid_window: "test-window".to_string(),
416435
bid_afk: "test-afk".to_string(),
436+
always_active_pattern: None,
417437
};
418438

419439
let query_params = QueryParams::Desktop(params);
@@ -445,6 +465,7 @@ mod tests {
445465
},
446466
bid_window: "test-window".to_string(),
447467
bid_afk: "test-afk".to_string(),
468+
always_active_pattern: None,
448469
};
449470

450471
let query_params = QueryParams::Desktop(params);

0 commit comments

Comments
 (0)