Skip to content

Commit 9259df7

Browse files
authored
feat: add Top Stopwatch Events view (#659)
In order for the stopwatch events to appear, one has to enable "Force devmode" in the settings and have some stopwatch events. The stopwatch events are merged with window events. If they overlap, then the stopwatch events have precedence, so that no more than 24 h of all events are logged per day.
1 parent 4ae606a commit 9259df7

5 files changed

Lines changed: 35 additions & 3 deletions

File tree

src/components/SelectableVisualization.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ div
8585
vis-timeline(:buckets="timeline_buckets", :showRowLabels='true', :queriedInterval="timeline_daterange")
8686
div(v-if="type == 'score'")
8787
aw-score()
88+
div(v-if="type == 'top_stopwatches'")
89+
aw-summary(:fields="activityStore.stopwatch.top_stopwatches",
90+
:namefunc="e => e.data.label",
91+
:colorfunc="e => e.data.label",
92+
with_limit)
8893
</template>
8994

9095
<style lang="scss">
@@ -152,6 +157,7 @@ export default {
152157
'custom_vis',
153158
'vis_timeline',
154159
'score',
160+
'top_stopwatches',
155161
],
156162
// TODO: Move this function somewhere else
157163
top_editor_files_namefunc: e => {
@@ -241,6 +247,10 @@ export default {
241247
title: 'Score',
242248
available: this.activityStore.category.available,
243249
},
250+
top_stopwatches: {
251+
title: 'Top Stopwatch Events',
252+
available: this.activityStore.stopwatch.available,
253+
},
244254
};
245255
},
246256
has_prerequisites() {

src/queries.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ export function canonicalEvents(params: DesktopQueryParams | AndroidQueryParams)
145145
: '',
146146
params.bid_stopwatch
147147
? `stopwatch_events = query_bucket("${params.bid_stopwatch}");
148-
events = period_union(events, stopwatch_events);`
149-
: '',
148+
events = union_no_overlap(stopwatch_events, events);`
149+
: 'stopwatch_events = [];',
150150
// Categorize
151151
params.categories ? `events = categorize(events, ${categories_str});` : '',
152152
// Filter out selected categories
@@ -357,6 +357,9 @@ export function fullDesktopQuery(params: DesktopQueryParams): string[] {
357357
browser_titles = sort_by_duration(browser_titles);
358358
browser_titles = limit_events(browser_titles, ${default_limit});
359359
browser_duration = sum_durations(browser_events);
360+
stopwatch_events = merge_events_by_keys(stopwatch_events, ["label"]);
361+
stopwatch_events = sort_by_duration(stopwatch_events);
362+
stopwatch_events = limit_events(stopwatch_events, ${default_limit});
360363
361364
RETURN = {
362365
"window": {
@@ -371,6 +374,9 @@ export function fullDesktopQuery(params: DesktopQueryParams): string[] {
371374
"urls": browser_urls,
372375
"titles": browser_titles,
373376
"duration": browser_duration
377+
},
378+
"stopwatch": {
379+
"stopwatch_events": stopwatch_events
374380
}
375381
};`
376382
);

src/stores/activity.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ interface State {
116116

117117
stopwatch: {
118118
available: boolean;
119+
top_stopwatches: IEvent[];
119120
};
120121

121122
query_options?: QueryOptions;
@@ -181,6 +182,7 @@ export const useActivityStore = defineStore('activity', {
181182

182183
stopwatch: {
183184
available: false,
185+
top_stopwatches: [],
184186
},
185187

186188
query_options: null,
@@ -376,6 +378,9 @@ export const useActivityStore = defineStore('activity', {
376378
});
377379
this.query_window_completed(data[0].window);
378380
this.query_browser_completed(data[0].browser);
381+
if (include_stopwatch) {
382+
this.query_stopwatch_completed(data[0].stopwatch);
383+
}
379384
},
380385

381386
async query_editor({ timeperiod }) {
@@ -720,6 +725,10 @@ export const useActivityStore = defineStore('activity', {
720725
this.browser.duration = data.duration;
721726
},
722727

728+
query_stopwatch_completed(this: State, data = { stopwatch_events: [] }) {
729+
this.stopwatch.top_stopwatches = data.stopwatch_events;
730+
},
731+
723732
query_editor_completed(
724733
this: State,
725734
data = { duration: 0, files: [], languages: [], projects: [] }

src/views/activity/Activity.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ div
6565
// WIP: https://github.com/ActivityWatch/aw-webui/pull/368
6666
| Include manually logged events (stopwatch)
6767
br
68-
| #[b Note:] WIP, breaks aw-server-rust badly. Only shown in devmode.
68+
| #[b Note:] WIP. Stopwatch events shadow other events, when overlapping with them. Only shown in devmode.
6969

7070
div.col-md-6.mt-2.mt-md-0
7171
b-form-group(label="Show category" label-cols="5" label-cols-lg="4" style="font-size: 0.88em")

test/unit/__snapshots__/queries.test.node.js.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ browser_events = [];
1212
audible_events = filter_keyvals(browser_events, "audible", [true]);
1313
not_afk = period_union(not_afk, audible_events);
1414
events = filter_period_intersect(events, not_afk);
15+
stopwatch_events = [];
1516
events = categorize(events, []);
1617
events = filter_keyvals(events, "$category", true);
1718
title_events = sort_by_duration(merge_events_by_keys(events, ["app", "title"]));
@@ -31,6 +32,9 @@ browser_titles = merge_events_by_keys(browser_events, ["title"]);
3132
browser_titles = sort_by_duration(browser_titles);
3233
browser_titles = limit_events(browser_titles, 100);
3334
browser_duration = sum_durations(browser_events);
35+
stopwatch_events = merge_events_by_keys(stopwatch_events, ["label"]);
36+
stopwatch_events = sort_by_duration(stopwatch_events);
37+
stopwatch_events = limit_events(stopwatch_events, 100);
3438
RETURN = {
3539
"window": {
3640
"app_events": app_events,
@@ -44,6 +48,9 @@ RETURN = {
4448
"urls": browser_urls,
4549
"titles": browser_titles,
4650
"duration": browser_duration
51+
},
52+
"stopwatch": {
53+
"stopwatch_events": stopwatch_events
4754
}
4855
};"
4956
`;

0 commit comments

Comments
 (0)