Skip to content

Commit

Permalink
fix: fixed bug in multiquery
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Jul 12, 2022
1 parent 6c8ce96 commit 53343b3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 42 deletions.
34 changes: 19 additions & 15 deletions src/queries.ts
Expand Up @@ -31,7 +31,7 @@ interface BaseQueryParams {
categories: Category[];
filter_categories: string[][];
bid_browsers?: string[];
return_variable?: string;
return_variable_suffix?: string;
}

interface DesktopQueryParams extends BaseQueryParams {
Expand Down Expand Up @@ -62,7 +62,7 @@ function get_params(
bid_window: 'aw-watcher-window_' + host,
bid_afk: 'aw-watcher-afk_' + host,
bid_browsers: [],
return_variable: 'events_' + safeHostname(host),
return_variable_suffix: safeHostname(host),
};

const host_params = params.host_params[host];
Expand Down Expand Up @@ -117,14 +117,13 @@ export function canonicalEvents(params: DesktopQueryParams | AndroidQueryParams)
not_afk = filter_keyvals(not_afk, "status", ["not-afk"]);`
: '',
// Fetch browser events
params.bid_browsers
? isDesktopParams(params) &&
browserEvents(params) +
// Include focused and audible browser events as indications of not-afk
(params.include_audible
? `audible_events = filter_keyvals(browser_events, "audible", [true]);
isDesktopParams(params) && params.bid_browsers
? browserEvents(params) +
// Include focused and audible browser events as indications of not-afk
(params.include_audible
? `audible_events = filter_keyvals(browser_events, "audible", [true]);
not_afk = period_union(not_afk, audible_events);`
: '')
: '')
: '',
// Filter out window events when the user was afk
isDesktopParams(params) && params.filter_afk
Expand All @@ -137,7 +136,10 @@ export function canonicalEvents(params: DesktopQueryParams | AndroidQueryParams)
? `events = filter_keyvals(events, "$category", ${cat_filter_str});`
: '',
// "Return" events by setting variable named with return_variable if set
params.return_variable ? `${params.return_variable} = events;` : '',
params.return_variable_suffix
? `events_${params.return_variable_suffix} = events;
not_afk_${params.return_variable_suffix} = not_afk;`
: '',
].join('\n');
}

Expand All @@ -151,11 +153,13 @@ export function canonicalMultideviceEvents(params: MultiQueryParams): string {
// To do this, we can use the union_no_overlap function, which merges events
// but avoids overlaps by giving priority according to the order of hosts.
let query = queries.join('\n');
if (queries.length > 1) {
query += 'events = [];';
for (let i = 0; i < queries.length; i++) {
query += `events = union_no_overlap(events, events_${safeHostname(params.hosts[i])});`;
}
query += 'events = [];';
query += 'not_afk = [];';
for (let i = 0; i < queries.length; i++) {
query += `
events = union_no_overlap(events, events_${safeHostname(params.hosts[i])});
not_afk = union_no_overlap(not_afk, not_afk_${safeHostname(params.hosts[i])});
`;
}

return query;
Expand Down
2 changes: 1 addition & 1 deletion src/stores/activity.ts
Expand Up @@ -206,7 +206,7 @@ export const useActivityStore = defineStore('activity', {

if (this.window.available) {
// Perform this last, as it takes the longest
await this.query_category_time_by_period({ ...query_options, dontQueryInactive: true });
await this.query_category_time_by_period({ ...query_options, dont_query_inactive: true });
}
} else {
console.warn(
Expand Down
14 changes: 7 additions & 7 deletions src/views/Trends.vue
Expand Up @@ -40,14 +40,14 @@ div

<style lang="scss" scoped></style>

<script>
<script lang="ts">
import moment from 'moment';
import { get_today_with_offset } from '~/util/time';
import { buildBarchartDataset } from '~/util/datasets';
import { useBucketsStore } from '~/stores/buckets';
import { useCategoryStore } from '~/stores/categories';
import { useActivityStore } from '~/stores/activity';
import { useActivityStore, QueryOptions } from '~/stores/activity';
export default {
name: 'Trends',
Expand Down Expand Up @@ -85,14 +85,14 @@ export default {
methods: {
refresh: async function (force) {
const queryParams = {
const queryParams: QueryOptions = {
timeperiod: this.timeperiod,
host: this.host,
force,
filterAFK: this.filterAFK,
includeAudible: this.includeAudible,
filterCategories: this.filterCategories,
dontQueryInactive: false,
filter_afk: this.filter_afk,
include_audible: this.include_audible,
filter_categories: this.filter_categories,
dont_query_inactive: false,
};
await this.activityStore.query_category_time_by_period(queryParams);
},
Expand Down
40 changes: 21 additions & 19 deletions src/views/activity/Activity.vue
Expand Up @@ -50,18 +50,18 @@ div
div.col-md-12
h5 Filters
div.col-md-6
b-form-checkbox(v-model="filterAFK" size="sm")
b-form-checkbox(v-model="filter_afk" size="sm")
| Exclude AFK time
icon#filterAFKHelp(name="question-circle" style="opacity: 0.4")
b-tooltip(target="filterAFKHelp" v-b-tooltip.hover title="Filter away time where the AFK watcher didn't detect any input.")
b-form-checkbox(v-model="includeAudible" :disabled="!filterAFK" size="sm")
b-form-checkbox(v-model="include_audible" :disabled="!filter_afk" size="sm")
| Count audible browser tab as active
icon#includeAudibleHelp(name="question-circle" style="opacity: 0.4")
b-tooltip(target="includeAudibleHelp" v-b-tooltip.hover title="If the active window is an audible browser tab, count as active. Requires a browser watcher.")

div.col-md-6.mt-2.mt-md-0
b-form-group(label="Show category" label-cols="5" label-cols-lg="4" style="font-size: 0.88em")
b-form-select(v-model="filterCategory", :options="categoryStore.category_select(true)" size="sm")
b-form-select(v-model="filter_category", :options="categoryStore.category_select(true)" size="sm")


aw-periodusage.mt-2(:periodusage_arr="periodusage", @update="setDate")
Expand Down Expand Up @@ -137,7 +137,7 @@ div
}
</style>

<script>
<script lang="ts">
import { mapState } from 'pinia';
import moment from 'moment';
import { get_day_start_with_offset, get_today_with_offset } from '~/util/time';
Expand All @@ -156,7 +156,7 @@ import 'vue-awesome/icons/filter';
import { useSettingsStore } from '~/stores/settings';
import { useCategoryStore } from '~/stores/categories';
import { useActivityStore } from '~/stores/activity';
import { useActivityStore, QueryOptions } from '~/stores/activity';
import { useViewsStore } from '~/stores/views';
export default {
Expand Down Expand Up @@ -185,9 +185,10 @@ export default {
today: null,
showOptions: false,
filterCategory: null,
includeAudible: true,
filterAFK: true,
filter_category: null,
include_audible: true,
filter_afk: true,
new_view: {},
};
},
Expand Down Expand Up @@ -216,11 +217,11 @@ export default {
return this.$route.meta.subview;
},
filterCategories: function () {
if (this.filterCategory) {
if (this.filter_category) {
const cats = this.categoryStore.all_categories;
const isChild = p => c => c.length > p.length && _.isEqual(p, c.slice(0, p.length));
const children = _.filter(cats, isChild(this.filterCategory));
return [this.filterCategory].concat(children);
const children = _.filter(cats, isChild(this.filter_category));
return [this.filter_category].concat(children);
} else {
return null;
}
Expand Down Expand Up @@ -272,13 +273,13 @@ export default {
timeperiod: function () {
this.refresh();
},
filterCategory: function () {
filter_category: function () {
this.refresh();
},
filterAFK: function () {
filter_afk: function () {
this.refresh();
},
includeAudible: function () {
include_audible: function () {
this.refresh();
},
},
Expand Down Expand Up @@ -322,14 +323,15 @@ export default {
},
refresh: async function (force) {
await this.activityStore.ensure_loaded({
const queryOptions: QueryOptions = {
timeperiod: this.timeperiod,
host: this.host,
force: force,
filterAFK: this.filterAFK,
includeAudible: this.includeAudible,
filterCategories: this.filterCategories,
});
filter_afk: this.filter_afk,
include_audible: this.include_audible,
filter_categories: this.filter_categories,
};
await this.activityStore.ensure_loaded(queryOptions);
},
load_demo: async function () {
Expand Down

0 comments on commit 53343b3

Please sign in to comment.