28
28
//! };
29
29
//!
30
30
//! // Automatically fetches classes from localhost:5600
31
- //! let query = QueryParams::Desktop(params.clone()).canonical_events_with_classes ();
31
+ //! let query = QueryParams::Desktop(params.clone()).canonical_events ();
32
32
//!
33
- //! // Or from a custom server
34
- //! let query = QueryParams::Desktop(params)
35
- //! .canonical_events_with_classes_from_server("localhost", 2345);
36
33
//! ```
37
34
38
35
use crate :: classes:: { CategoryId , CategorySpec } ;
@@ -78,8 +75,6 @@ pub static BROWSER_APPNAMES: phf::Map<&'static str, &'static [&'static str]> = p
78
75
"vivaldi" => & [ "Vivaldi-stable" , "Vivaldi-snapshot" , "vivaldi.exe" ] ,
79
76
} ;
80
77
81
- pub const DEFAULT_LIMIT : u32 = 100 ;
82
-
83
78
/// Type alias for categorization classes
84
79
pub type ClassRule = ( CategoryId , CategorySpec ) ;
85
80
@@ -135,33 +130,6 @@ impl QueryParams {
135
130
QueryParams :: Android ( params) => build_android_canonical_events ( params) ,
136
131
}
137
132
}
138
-
139
- /// Build canonical events query string with automatic class fetching if not provided
140
- pub fn canonical_events_with_classes ( & self ) -> String {
141
- self . canonical_events_with_classes_from_server ( "localhost" , 5600 )
142
- }
143
-
144
- /// Build canonical events query string with automatic class fetching from custom server
145
- pub fn canonical_events_with_classes_from_server ( & self , host : & str , port : u16 ) -> String {
146
- match self {
147
- QueryParams :: Desktop ( params) => {
148
- let mut params_with_classes = params. clone ( ) ;
149
- if params_with_classes. base . classes . is_empty ( ) {
150
- params_with_classes. base . classes =
151
- crate :: classes:: get_classes_from_server ( host, port) ;
152
- }
153
- build_desktop_canonical_events ( & params_with_classes)
154
- }
155
- QueryParams :: Android ( params) => {
156
- let mut params_with_classes = params. clone ( ) ;
157
- if params_with_classes. base . classes . is_empty ( ) {
158
- params_with_classes. base . classes =
159
- crate :: classes:: get_classes_from_server ( host, port) ;
160
- }
161
- build_android_canonical_events ( & params_with_classes)
162
- }
163
- }
164
- }
165
133
}
166
134
167
135
/// Helper function to serialize classes in the format expected by the categorize function
@@ -201,7 +169,7 @@ fn serialize_classes(classes: &[ClassRule]) -> String {
201
169
format ! ( "[{}]" , parts. join( ", " ) )
202
170
}
203
171
204
- fn build_desktop_canonical_events ( params : & DesktopQueryParams ) -> String {
172
+ pub fn build_desktop_canonical_events ( params : & DesktopQueryParams ) -> String {
205
173
let mut query = Vec :: new ( ) ;
206
174
207
175
// Fetch window events
@@ -256,7 +224,7 @@ not_afk = period_union(not_afk, audible_events)"
256
224
query. join ( ";\n " )
257
225
}
258
226
259
- fn build_android_canonical_events ( params : & AndroidQueryParams ) -> String {
227
+ pub fn build_android_canonical_events ( params : & AndroidQueryParams ) -> String {
260
228
let mut query = Vec :: new ( ) ;
261
229
262
230
// Fetch app events
@@ -287,7 +255,7 @@ fn build_android_canonical_events(params: &AndroidQueryParams) -> String {
287
255
query. join ( ";\n " )
288
256
}
289
257
290
- fn build_browser_events ( params : & DesktopQueryParams ) -> String {
258
+ pub fn build_browser_events ( params : & DesktopQueryParams ) -> String {
291
259
let mut query = String :: from ( "browser_events = [];" ) ;
292
260
293
261
for browser_bucket in & params. base . bid_browsers {
@@ -311,38 +279,34 @@ browser_events = sort_by_timestamp(browser_events)",
311
279
query
312
280
}
313
281
314
- /// Build a full desktop query
282
+ /// Build a full desktop query using default localhost:5600 configuration
315
283
pub fn full_desktop_query ( params : & DesktopQueryParams ) -> String {
316
- let mut query = QueryParams :: Desktop ( params. clone ( ) ) . canonical_events_with_classes ( ) ;
284
+ let mut query = QueryParams :: Desktop ( params. clone ( ) ) . canonical_events ( ) ;
317
285
318
286
// Add basic event aggregations
319
- query. push_str ( & format ! (
320
- "
287
+ query. push_str (
288
+ & "
321
289
title_events = sort_by_duration(merge_events_by_keys(events, [\" app\" , \" title\" ]));
322
290
app_events = sort_by_duration(merge_events_by_keys(title_events, [\" app\" ]));
323
291
cat_events = sort_by_duration(merge_events_by_keys(events, [\" $category\" ]));
324
- app_events = limit_events(app_events, {});
325
- title_events = limit_events(title_events, {});
326
292
duration = sum_durations(events);
327
- " ,
328
- DEFAULT_LIMIT , DEFAULT_LIMIT
329
- ) ) ;
293
+ "
294
+ . to_string ( ) ,
295
+ ) ;
330
296
331
297
// Add browser-specific query parts if browser buckets exist
332
298
if !params. base . bid_browsers . is_empty ( ) {
333
- query. push_str ( & format ! (
334
- "
299
+ query. push_str (
300
+ & "
335
301
browser_events = split_url_events(browser_events);
336
302
browser_urls = merge_events_by_keys(browser_events, [\" url\" ]);
337
303
browser_urls = sort_by_duration(browser_urls);
338
- browser_urls = limit_events(browser_urls, {});
339
304
browser_domains = merge_events_by_keys(browser_events, [\" $domain\" ]);
340
305
browser_domains = sort_by_duration(browser_domains);
341
- browser_domains = limit_events(browser_domains, {});
342
306
browser_duration = sum_durations(browser_events);
343
- " ,
344
- DEFAULT_LIMIT , DEFAULT_LIMIT
345
- ) ) ;
307
+ "
308
+ . to_string ( ) ,
309
+ ) ;
346
310
} else {
347
311
query. push_str (
348
312
"
@@ -443,7 +407,7 @@ mod tests {
443
407
let params = DesktopQueryParams {
444
408
base : QueryParamsBase {
445
409
bid_browsers : vec ! [ ] ,
446
- classes : vec ! [ ] , // Empty classes - should trigger server fetch
410
+ classes : vec ! [ ] ,
447
411
filter_classes : vec ! [ ] ,
448
412
filter_afk : true ,
449
413
include_audible : true ,
@@ -453,9 +417,9 @@ mod tests {
453
417
} ;
454
418
455
419
let query_params = QueryParams :: Desktop ( params) ;
456
- let query = query_params. canonical_events_with_classes ( ) ;
420
+ let query = query_params. canonical_events ( ) ;
457
421
458
- // Should contain basic query structure even if server fetch fails
422
+ // Should contain basic query structure
459
423
assert ! ( query. contains( "events = flood" ) ) ;
460
424
assert ! ( query. contains( "test-window" ) ) ;
461
425
}
@@ -484,7 +448,7 @@ mod tests {
484
448
} ;
485
449
486
450
let query_params = QueryParams :: Desktop ( params) ;
487
- let query = query_params. canonical_events_with_classes ( ) ;
451
+ let query = query_params. canonical_events ( ) ;
488
452
489
453
// Should contain categorization
490
454
assert ! ( query. contains( "events = categorize" ) ) ;
0 commit comments