Skip to content

Commit 10c50ba

Browse files
authored
feat: add optional always-active-pattern to canonical queries (#543)
Signed-off-by: Brayo <[email protected]>
1 parent 8289a0f commit 10c50ba

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
@@ -106,6 +107,8 @@ pub struct DesktopQueryParams {
106107
pub base: QueryParamsBase,
107108
pub bid_window: String,
108109
pub bid_afk: String,
110+
#[serde(default)]
111+
pub always_active_pattern: Option<String>,
109112
}
110113

111114
/// Query parameters specific to Android
@@ -182,11 +185,26 @@ pub fn build_desktop_canonical_events(params: &DesktopQueryParams) -> String {
182185

183186
// Fetch not-afk events
184187
if params.base.filter_afk {
185-
query.push(format!(
188+
let mut not_afk_query = format!(
186189
"not_afk = flood(query_bucket(find_bucket(\"{}\")));
187190
not_afk = filter_keyvals(not_afk, \"status\", [\"not-afk\"])",
188191
escape_doublequote(&params.bid_afk)
189-
));
192+
);
193+
194+
// Add treat_as_active functionality if pattern is provided
195+
if let Some(ref pattern) = params.always_active_pattern {
196+
not_afk_query.push_str(&format!(
197+
";
198+
not_treat_as_afk = filter_keyvals_regex(events, \"app\", \"{}\");
199+
not_afk = period_union(not_afk, not_treat_as_afk);
200+
not_treat_as_afk = filter_keyvals_regex(events, \"title\", \"{}\");
201+
not_afk = period_union(not_afk, not_treat_as_afk)",
202+
escape_doublequote(pattern),
203+
escape_doublequote(pattern)
204+
));
205+
}
206+
207+
query.push(not_afk_query);
190208
}
191209

192210
// Add browser events if any browser buckets specified
@@ -368,6 +386,7 @@ mod tests {
368386
},
369387
bid_window: "aw-watcher-window_".to_string(),
370388
bid_afk: "aw-watcher-afk_".to_string(),
389+
always_active_pattern: None,
371390
};
372391

373392
let query = full_desktop_query(&params);
@@ -420,6 +439,7 @@ mod tests {
420439
},
421440
bid_window: "test-window".to_string(),
422441
bid_afk: "test-afk".to_string(),
442+
always_active_pattern: None,
423443
};
424444

425445
let query_params = QueryParams::Desktop(params);
@@ -451,6 +471,7 @@ mod tests {
451471
},
452472
bid_window: "test-window".to_string(),
453473
bid_afk: "test-afk".to_string(),
474+
always_active_pattern: None,
454475
};
455476

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

0 commit comments

Comments
 (0)