From 0282eec70c89850d4874b7d98cceaea454380e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Bj=C3=A4reholt?= Date: Wed, 22 Nov 2023 11:00:10 +0100 Subject: [PATCH] feat: added categoryQuery support on Android, fixing 'Timeline (barchart)' visualization --- src/queries.ts | 4 +++- src/stores/activity.ts | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/queries.ts b/src/queries.ts index f3a54abb..ab733323 100644 --- a/src/queries.ts +++ b/src/queries.ts @@ -441,7 +441,9 @@ export function activityQueryAndroid(androidbucket: string): string[] { // Returns a query that yields a dict with a key "cat_events" which is an // array of one event per category, with the duration of each event set to the sum of the category durations. -export function categoryQuery(params: MultiQueryParams | DesktopQueryParams): string[] { +export function categoryQuery( + params: MultiQueryParams | DesktopQueryParams | AndroidQueryParams +): string[] { const q = ` ${isMultiParams(params) ? canonicalMultideviceEvents(params) : canonicalEvents(params)} cat_events = sort_by_duration(merge_events_by_keys(events, ["$category"])); diff --git a/src/stores/activity.ts b/src/stores/activity.ts index e6b91505..3ba81c33 100644 --- a/src/stores/activity.ts +++ b/src/stores/activity.ts @@ -293,9 +293,9 @@ export const useActivityStore = defineStore('activity', { await this.query_editor_completed(); } - if (this.window.available) { - // Perform this last, as it takes the longest - await this.query_category_time_by_period({ ...query_options }); + // Perform this last, as it takes the longest + if (this.window.available || this.android.available) { + await this.query_category_time_by_period(query_options); } } else { console.warn( @@ -502,22 +502,28 @@ export const useActivityStore = defineStore('activity', { } } + const isAndroid = this.buckets.android[0] !== undefined; const categories = useCategoryStore().classes_for_query; // TODO: Clean up call, pass QueryParams in fullDesktopQuery as well // TODO: Unify QueryOptions and QueryParams const query = queries.categoryQuery({ - bid_afk: this.buckets.afk[0], - bid_window: this.buckets.window[0], bid_browsers: this.buckets.browser, bid_stopwatch: include_stopwatch && this.buckets.stopwatch.length > 0 ? this.buckets.stopwatch[0] : undefined, - // bid_android: this.buckets.android, categories, filter_categories, filter_afk, always_active_pattern, + ...(isAndroid + ? { + bid_android: this.buckets.android[0], + } + : { + bid_afk: this.buckets.afk[0], + bid_window: this.buckets.window[0], + }), }); const result = await getClient().query([period], query, { verbose: true,